Registry Mirror
Skip to content

Conversation

@zachlewis

Copy link
Copy Markdown
Collaborator

OpenImageIO currently drops PNG Third Edition mastering-display metadata during
a read and rewrite. This preserves the ten wire values as integer ImageSpec
attributes and writes mDCV only when the record is complete, valid, and
accompanied by cICP.

Breaking and changed behavior

  • PNG and PNG-encoded ICO input report ten mdcv_* attributes when supported
    by the linked libpng.
  • PNG and PNG-encoded ICO output write a valid complete record with cICP.
  • Invalid, incomplete, unsupported, or cICP-less records are omitted with a
    debug warning; the image write otherwise continues.
  • libpng older than 1.6.46 keeps its previous file output, except that supplied
    mDCV attributes now produce the debug warning. A build without libpng's
    fixed-point API requires 1.6.48.

Motivation

A read and rewrite currently loses the mastering-display record, and callers
cannot author one through ImageSpec metadata.

What this PR does

  • Reads and writes the ten wire-unit integer fields.
  • Validates completeness, chromaticity and luminance bounds, and luminance
    ordering.
  • Adds input/output capability queries with the same version gates.
  • Covers PNG and the PNG-encoded ICO path.

What this PR deliberately does not do

  • Convert the integers to a new public structure.
  • Write mDCV without cICP.
  • Turn an omitted metadata record into a write failure.

Testing

The PNG test checks exact bytes, copy-through, all omission reasons, inclusive
bounds, unsigned attributes, capability reporting, and ICO read/write paths.

Validation

  • macOS arm64, AppleClang, Release, warnings as errors, libpng 1.6.58: focused
    5/5 normal and debug; full CTest 220/220 normal and 220/220 debug.
  • Two mutation checks covering input capability reporting and luminance
    ordering were killed.
  • Documentation warnings match the base.
  • No libpng at the 1.6.46/1.6.48 boundary was available. The
    floating-point-only branch was not linked or run.
  • CI passed on my fork, including the Linux gcc, Windows, sanitizer and ABI
    jobs: https://github.com/zachlewis/OpenImageIO/actions/runs/36108523146

Documentation

stdmetadata.md defines the ten attributes. builtinplugins.md documents the
read/write conditions, capability query, and libpng floors.

Assisted-by: OpenAI Codex (GPT-6 Astra, GPT-5.6 Sol)
Assisted-by: Claude Code / Claude Opus 5

Changed behavior: PNG input, and ICO input of PNG-encoded icons, with an
mDCV chunk now report ten mdcv_* integer attributes; before, the chunk
was ignored. PNG output and PNG-encoded ICO output, which used to ignore
mdcv_* attributes, now write an mDCV chunk when they form a complete,
valid record and a cICP chunk is written too. Otherwise (an incomplete,
invalid or unsupported record, or no cICP) the attributes are still left
out of the file, now with an "OpenImageIO WARNING:" debug message
explaining why. Input does not apply the output limits, so copying a
file whose record is out of range still drops the chunk, now with that
message. No write that used to succeed fails because of them, unless
libpng itself rejects a record that passed these checks. PNG input now
answers supports("mdcv") from the linked libpng, and PNG output does
when that libpng also supports cICP; ICO does not report it. All of
this needs libPNG 1.6.46 or newer, which added the mDCV chunk, or 1.6.48
or newer if libpng was built without its fixed-point API. Builds against
an older libpng write the same files as before; the only difference is
that debug message when the output is given mdcv_* attributes.

PNG Third Edition carries the mastering display's primaries, white point
and luminance range in an mDCV chunk. OIIO drops it, so a PNG read and
rewrite loses the record and callers cannot author one.

Read mDCV into ten integer ImageSpec attributes, mdcv_red_x through
mdcv_min_luminance, in PNG wire units, and write them back when a
complete, valid record accompanies a cICP chunk. The omission reason is
shown when OPENIMAGEIO_DEBUG is set or in debug builds. Pixels and color
space identification are unchanged.

libpng added the mDCV chunk in 1.6.46 and fixed its floating-point mDCV
setter in 1.6.48, so a libpng built without the fixed-point API needs
that later release. A single OIIO_PNG_MDCV_SUPPORTED gate, defined
beside the existing OIIO_LIBPNG_VERSION macro, enforces both floors for
the reader, the writer and both supports() answers, so the code accepts
exactly the libpng versions the documentation names.

Document the attributes and those versions beside the existing libPNG
1.6.45 note for CICP, and the new "mdcv" query beside "cicp" in the
supports() lists.

The test covers exact read and write bytes, copy-through, each omission
reason including negative and oversized chromaticities and the luminance
range and ordering checks, the inclusive range limits, unsigned integer
attributes, the copy of an out-of-range input record, a record that
libpng itself rejects, supports("mdcv") on input and output, and the
PNG-encoded ICO read and write path. It reads the record back through
--info rather than --echo, which errors on an absent attribute, so the
test also runs against a libpng without mDCV support.

Assisted-by: OpenAI Codex (GPT-6 Astra, GPT-5.6 Sol)
Assisted-by: Claude Code / Claude Opus 5
Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>

@lgritz lgritz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beyond my expertise, but I take your word that this is needed, and it probably can't break anything because it passes all the test.

@zachlewis

Copy link
Copy Markdown
Collaborator Author

Well, more of a "nice to have" than a "need", but it's data that would be nice to view and edit and, in an upcoming PR, approximately compute.

Just to explain real quick: Mastering Display Color Volume is kind of like a "region of interest" within the full pq_rec2020_display space representing the display capabilities and characteristics of the display a colorist ostensibly used when mastering -- the primaries, whitepoint, and minimum and maximum luminance (in absolute nits emitted by the display). And if the MDCV is one region of interest, the volume representing the chromaticities and min/max luminance reachable by the actual output display is another region of interest -- thus, there exists an overlap between code values the colorist saw, and code values the output display is able to emit; and from that point, there are many different ways how that information is used -- out of our hands, in any case.

Anyway, the relationship between an OCIO View Transforms / Views and OCIO Displays is similar to the relationship between MDCV and an output device's capabilities, insofar as it's reasonable to let MDCV data survive color space transformations, since it represents historical provenance that we intend to carry forward...

@lgritz

lgritz commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Now I'm not quite sure why my fingers typed "needed"... I think I meant more like "correct"?
Anyway, it's fine, I just hadn't merged yet. But now it's saying that there's a conflict? Something else must have gone in that touches png/run.py.
Let me see if I can trivially fix it while doing the merge.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
lgritz merged commit d865ca0 into AcademySoftwareFoundation:main Sep 29, 2026
32 checks passed
@zachlewis
zachlewis deleted the codex/sept-final14-g-png-mdcv branch October 1, 2026 02:40
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Oct 3, 2026
…eFoundation#5512)

OpenImageIO currently drops PNG Third Edition mastering-display metadata
during
a read and rewrite. This preserves the ten wire values as integer
ImageSpec
attributes and writes mDCV only when the record is complete, valid, and
accompanied by cICP.

## Breaking and changed behavior

- PNG and PNG-encoded ICO input report ten `mdcv_*` attributes when
supported
  by the linked libpng.
- PNG and PNG-encoded ICO output write a valid complete record with
cICP.
- Invalid, incomplete, unsupported, or cICP-less records are omitted
with a
  debug warning; the image write otherwise continues.
- libpng older than 1.6.46 keeps its previous file output, except that
supplied
mDCV attributes now produce the debug warning. A build without libpng's
  fixed-point API requires 1.6.48.

## Motivation

A read and rewrite currently loses the mastering-display record, and
callers
cannot author one through ImageSpec metadata.

## What this PR does

- Reads and writes the ten wire-unit integer fields.
- Validates completeness, chromaticity and luminance bounds, and
luminance
  ordering.
- Adds input/output capability queries with the same version gates.
- Covers PNG and the PNG-encoded ICO path.

## What this PR deliberately does not do

- Convert the integers to a new public structure.
- Write mDCV without cICP.
- Turn an omitted metadata record into a write failure.

## Testing

The PNG test checks exact bytes, copy-through, all omission reasons,
inclusive
bounds, unsigned attributes, capability reporting, and ICO read/write
paths.

## Validation

- macOS arm64, AppleClang, Release, warnings as errors, libpng 1.6.58:
focused
  5/5 normal and debug; full CTest 220/220 normal and 220/220 debug.
- Two mutation checks covering input capability reporting and luminance
  ordering were killed.
- Documentation warnings match the base.
- No libpng at the 1.6.46/1.6.48 boundary was available. The
  floating-point-only branch was not linked or run.
- CI passed on my fork, including the Linux gcc, Windows, sanitizer and
ABI
jobs: https://github.com/zachlewis/OpenImageIO/actions/runs/36108523146

## Documentation

`stdmetadata.md` defines the ten attributes. `builtinplugins.md`
documents the
read/write conditions, capability query, and libpng floors.


Assisted-by: OpenAI Codex (GPT-6 Astra, GPT-5.6 Sol)
Assisted-by: Claude Code / Claude Opus 5

Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Oct 10, 2026
…eFoundation#5512)

OpenImageIO currently drops PNG Third Edition mastering-display metadata
during
a read and rewrite. This preserves the ten wire values as integer
ImageSpec
attributes and writes mDCV only when the record is complete, valid, and
accompanied by cICP.

## Breaking and changed behavior

- PNG and PNG-encoded ICO input report ten `mdcv_*` attributes when
supported
  by the linked libpng.
- PNG and PNG-encoded ICO output write a valid complete record with
cICP.
- Invalid, incomplete, unsupported, or cICP-less records are omitted
with a
  debug warning; the image write otherwise continues.
- libpng older than 1.6.46 keeps its previous file output, except that
supplied
mDCV attributes now produce the debug warning. A build without libpng's
  fixed-point API requires 1.6.48.

## Motivation

A read and rewrite currently loses the mastering-display record, and
callers
cannot author one through ImageSpec metadata.

## What this PR does

- Reads and writes the ten wire-unit integer fields.
- Validates completeness, chromaticity and luminance bounds, and
luminance
  ordering.
- Adds input/output capability queries with the same version gates.
- Covers PNG and the PNG-encoded ICO path.

## What this PR deliberately does not do

- Convert the integers to a new public structure.
- Write mDCV without cICP.
- Turn an omitted metadata record into a write failure.

## Testing

The PNG test checks exact bytes, copy-through, all omission reasons,
inclusive
bounds, unsigned attributes, capability reporting, and ICO read/write
paths.

## Validation

- macOS arm64, AppleClang, Release, warnings as errors, libpng 1.6.58:
focused
  5/5 normal and debug; full CTest 220/220 normal and 220/220 debug.
- Two mutation checks covering input capability reporting and luminance
  ordering were killed.
- Documentation warnings match the base.
- No libpng at the 1.6.46/1.6.48 boundary was available. The
  floating-point-only branch was not linked or run.
- CI passed on my fork, including the Linux gcc, Windows, sanitizer and
ABI
jobs: https://github.com/zachlewis/OpenImageIO/actions/runs/36108523146

## Documentation

`stdmetadata.md` defines the ten attributes. `builtinplugins.md`
documents the
read/write conditions, capability query, and libpng floors.


Assisted-by: OpenAI Codex (GPT-6 Astra, GPT-5.6 Sol)
Assisted-by: Claude Code / Claude Opus 5

Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants