w3c / png

Maintenance of the PNG specification
https://w3c.github.io/png/
Other
44 stars 11 forks source link

Testing `mDCv` #359

Open svgeesus opened 10 months ago

svgeesus commented 10 months ago

For browsers and image viewers, there is no normative requirement that can be tested:

The mDCv chunk provides informative static metadata which allows a target (consumer) display to potentially optimize it's tone mapping decisions on a comparison of its inherent capabilities versus the original mastering displays capabilities.

If we are aware of implementations that do something with this, then we could check that they do different things with, say, one image reporting sRGB and then BT.2100 as mastering volume But what they actually do is completely unconstrained.

For a PNG validator or checker, it could report the presence of the chunk, check that the sizes of the data are correct and present the values, but that is about all.

For content creation tools, a list of tools that writes the chunk is helpful to demonstrate implementation.

svgeesus commented 8 months ago

I hacked mDCv support into my fork of the JavaScript PNG chunk inspector:

image

 ["mDCv", "Mastering Display Color Volume", false, (chunk, earlier) => {
            addErrorIfHasType(earlier, "PLTE", chunk, "Chunk must be before PLTE chunk");
            addErrorIfHasType(earlier, "IDAT", chunk, "Chunk must be before IDAT chunk");
            if (chunk.data.length != 24) {
                chunk.errorNotes.push("Invalid data length");
                return;
            }
            let red_chromaticity_x = chunk.data[0]*256 + chunk.data[1];
            let red_chromaticity_y = chunk.data[2]*256 + chunk.data[3];
            let rx = (red_chromaticity_x * 0.00002).toPrecision(6);
            let ry = (red_chromaticity_y * 0.00002).toPrecision(6);
            chunk.innerNotes.push(`red: x = ${rx}, y = ${ry}`);
            let green_chromaticity_x = chunk.data[4]*256 + chunk.data[5];
            let green_chromaticity_y = chunk.data[6]*256 + chunk.data[7];
            let gx = (green_chromaticity_x * 0.00002).toPrecision(6);
            let gy = (green_chromaticity_y * 0.00002).toPrecision(6);
            chunk.innerNotes.push(`green: x = ${gx}, y = ${gy}`);
            let blue_chromaticity_x = chunk.data[8]*256 + chunk.data[9];
            let blue_chromaticity_y = chunk.data[10]*256 + chunk.data[11];
            let bx = (blue_chromaticity_x * 0.00002).toPrecision(6);
            let by = (blue_chromaticity_y * 0.00002).toPrecision(6);
            chunk.innerNotes.push(`blue: x = ${bx}, y = ${by}`);
            let white_chromaticity_x = chunk.data[12]*256 + chunk.data[13];
            let white_chromaticity_y = chunk.data[14]*256 + chunk.data[15];
            let wx = (white_chromaticity_x * 0.00002).toPrecision(6);
            let wy = (white_chromaticity_y * 0.00002).toPrecision(6);
            chunk.innerNotes.push(`white: x = ${wx}, y = ${wy}`);
            let max_lum = chunk.data[16]*256 + chunk.data[17];
            let min_lum = chunk.data[18]*256 + chunk.data[19];
            let max = (max_lum * 0.0001).toPrecision(4);
            let min = (min_lum * 0.0001).toPrecision(4);
            chunk.innerNotes.push(`Max luminance: ${max} cd/m²`);
            chunk.innerNotes.push(`Min luminance: ${min} cd/m²`);
            }],
svgeesus commented 2 months ago

Implementation Report, section on mDCv