Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README-JXR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# JPEG XR metadata

`ImageFactory::open()` recognizes the version-1 JPEG XR still-image signature,
independently of the filename extension. It reports `ImageType::jxr` and
`image/jxr`, using a private adapter built on the TIFF reader and serializer.
Earlier versions reported TIFF identity. Native width and height describe the
stored primary image before its spatial transformation.

The adapter reads and writes Exif, IPTC, XMP and ICC metadata without decoding or
recompressing image data. It preserves the ordered image/preview chain and both
interleaved and separate alpha streams. The exposed metadata belongs to the first
non-preview image; other images retain their metadata during ordinary edits.
TIFF's existing metadata precedence applies independently within each image.

Explicit category-clearing APIs and empty category setters remove that category
from every image and preview. `clearMetadata()` removes all supported metadata
categories throughout the file. Clearing a mutable metadata container affects
only the exposed primary image. Native decoding, layout and image-association
fields survive category clears. Supplied changes to those protected fields
(`0xbc00`–`0xbcff` and PageNumber) are rejected, including partial removal and
duplicates. A metadata-only replacement may omit the native view; it is retained.
`setMetadata()` copies writable metadata, excluding source-native fields.

Raw XMP packets remain writable without the XMP toolkit. Structured XMP edits
require the toolkit. An image-byte count of zero is read through EOF and rewritten
as an explicit length. BYTE/USHORT stream offsets and lengths are promoted to
ULONG when rewritten. Output directories and external values are word-aligned;
bounded unaligned input values are accepted for compatibility with existing files.

Writing requires complete, nonoverlapping ownership of directory/value ranges and
compressed streams, valid image/alpha pairs, and a result within the 32-bit
container limit. Unsupported TIFF strip/tile/SubIFD-array/embedded-JPEG pointer
layouts and opaque maker notes are rejected. Resource limits are 1,024 images,
4,096 total directories, 65,536 entries and 64 MiB of typed values per file.
The replacement is serialized to temporary I/O, reparsed, and checked against
the intended per-image metadata and every original compressed stream before
source transfer. Original compressed streams are borrowed rather than stored in
Exif values.

JPEG XR creation, pixel encoding and Motion JPEG XR are unsupported. Direct
`TiffImage`/`TiffParser` writing rejects JPEG XR; use `ImageFactory` for editing.

The container follows Annex A of
[ITU-T T.832 (01/2012)](https://www.itu.int/rec/dologin_pub.asp?id=T-REC-T.832-201201-S%21%21PDF-E&lang=e&type=items).
No JPEG XR codec library is required. Focused unit tests run with
`unit_tests --gtest_filter='Jxr*'`; the CLI regression is
`tests/bugfixes/github/test_issue_3162.py`.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ write, delete and modify Exif, IPTC, XMP and ICC image metadata.
| Releases and Documentation<br>Prereleases:<br>Project Resources<br>License (GPLv2)<br>CMake Downloads | [https://exiv2.org](https://exiv2.org)<br>[https://pre-release.exiv2.org](https://pre-release.exiv2.org)<br>[https://github.com/Exiv2/exiv2](https://github.com/Exiv2/exiv2)<br>[COPYING](COPYING)<br>[https://cmake.org/download/](https://cmake.org/download/) |
| README.md<br>README-CONAN.md<br>README-SAMPLES.md | User Manual. _This document_<br>Conan User Manual _[click here](README-CONAN.md)_<br>Sample Code Manual. _[click here](README-SAMPLES.md)_ |

See [README-JXR](README-JXR.md) for JPEG XR metadata policy and write limits.

The file ReadMe.txt in a build bundle describes how to install the library on the platform. ReadMe.txt also documents how to compile and link code on the platform.

<div id="TOC">
Expand Down
7 changes: 7 additions & 0 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ using IsThisTypeFct = bool (*)(BasicIo& iIo, bool advance);
@brief Returns an Image instance of the specified type.

The factory is implemented as a static class.

@note Version-1 JPEG XR still images report ImageType::jxr and receive a private
TIFF-based adapter. Earlier versions reported TIFF identity. Ordinary edits
affect the first non-preview image; explicit category clears and empty category
setters apply throughout the image/preview chain. Native decoding/layout fields
and compressed streams are retained. Individual layouts and requested edits
are validated by Image::writeMetadata(); creation is unsupported.
*/
class EXIV2API ImageFactory {
friend bool Image::good() const;
Expand Down
1 change: 1 addition & 0 deletions include/exiv2/image_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class ImageType {
qtime,
riff,
mkv,
jxr, //!< JPEG XR (version-1 still-image container)
};
} // namespace Exiv2

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ add_library(
image_int.hpp
jp2image_int.cpp
jp2image_int.hpp
jxrimage_int.cpp
jxrimage_int.hpp
makernote_int.cpp
makernote_int.hpp
minoltamn_int.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "bmpimage.hpp"
#include "gifimage.hpp"
#include "jp2image.hpp"
#include "jxrimage_int.hpp"
#include "nikonmn_int.hpp"
#include "orfimage.hpp"
#include "pgfimage.hpp"
Expand Down Expand Up @@ -86,6 +87,7 @@ constexpr Registry registry[] = {
{ImageType::cr2, newCr2Instance, isCr2Type, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amNone, amReadWrite},
{ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amRead, amNone},
{ImageType::jxr, Internal::newJxrInstance, Internal::isJxrType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::tiff, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::webp, newWebPInstance, isWebPType, amReadWrite, amNone, amReadWrite, amNone},
{ImageType::dng, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Expand Down Expand Up @@ -774,6 +776,8 @@ const std::string& Image::tagName(uint16_t tag) {
}

AccessMode ImageFactory::checkMode(ImageType type, MetadataId metadataId) {
if (type == ImageType::jxr && metadataId == mdIccProfile)
return amReadWrite;
auto r = Exiv2::find(registry, type);
if (!r)
throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type));
Expand Down Expand Up @@ -895,6 +899,9 @@ Image::UniquePtr ImageFactory::open(BasicIo::UniquePtr io) {

#ifdef EXV_ENABLE_FILESYSTEM
Image::UniquePtr ImageFactory::create(ImageType type, const std::string& path) {
// Unsupported JPEG XR creation must not truncate an existing destination.
if (type == ImageType::jxr)
throw Error(ErrorCode::kerWritingImageFormatUnsupported, "JPEG XR creation");
auto fileIo = std::make_unique<FileIo>(path);
// Create or overwrite the file, then close it
if (fileIo->open("w+b") != 0) {
Expand Down
Loading
Loading