std/png: parse cICP chunk

Updates #180
This commit is contained in:
Nigel Tao committed 2026-10-18 18:13:59 +11:00
1 parent ab24b06450
commit c677bef7fd
7 files changed
+294 -24

No files matched your search

+3
View File
@@ -414,6 +414,9 @@ redirect:
if (flags & DecodeImageArgFlags::REPORT_METADATA_CHRM) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CHRM, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_CICP) {
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__CICP, true);
}
if (flags & DecodeImageArgFlags::REPORT_METADATA_EXIF) {
interested_in_metadata_after_the_frame = true;
image_decoder->set_report_metadata(WUFFS_BASE__FOURCC__EXIF, true);
+11 -9
View File
@@ -236,27 +236,29 @@ struct DecodeImageArgFlags {
static constexpr uint64_t REPORT_METADATA_BGCL = 0x0001;
// Primary Chromaticities and White Point.
static constexpr uint64_t REPORT_METADATA_CHRM = 0x0002;
// Coding-Independent Code Points for video signal type identification.
static constexpr uint64_t REPORT_METADATA_CICP = 0x0004;
// Exchangeable Image File Format.
static constexpr uint64_t REPORT_METADATA_EXIF = 0x0004;
static constexpr uint64_t REPORT_METADATA_EXIF = 0x0008;
// Gamma Correction.
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0008;
static constexpr uint64_t REPORT_METADATA_GAMA = 0x0010;
// International Color Consortium Profile.
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0010;
static constexpr uint64_t REPORT_METADATA_ICCP = 0x0020;
// Key-Value Pair.
//
// For PNG files, this includes iTXt, tEXt and zTXt chunks. In the
// HandleMetadata callback, the raw argument contains UTF-8 strings.
static constexpr uint64_t REPORT_METADATA_KVP = 0x0020;
static constexpr uint64_t REPORT_METADATA_KVP = 0x0040;
// Modification Time.
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0040;
static constexpr uint64_t REPORT_METADATA_MTIM = 0x0080;
// Offset (2-Dimensional).
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0080;
static constexpr uint64_t REPORT_METADATA_OFS2 = 0x0100;
// Physical Dimensions.
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0100;
static constexpr uint64_t REPORT_METADATA_PHYD = 0x0200;
// Standard Red Green Blue (Rendering Intent).
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0200;
static constexpr uint64_t REPORT_METADATA_SRGB = 0x0400;
// Extensible Metadata Platform.
static constexpr uint64_t REPORT_METADATA_XMP = 0x0400;
static constexpr uint64_t REPORT_METADATA_XMP = 0x0800;
uint64_t repr;
};
+55
View File
@@ -1122,6 +1122,7 @@ typedef struct wuffs_base__more_information__struct {
inline uint32_t metadata__fourcc() const;
inline wuffs_base__range_ie_u64 metadata_raw_passthrough__range() const;
inline int32_t metadata_parsed__chrm(uint32_t component) const;
inline uint8_t metadata_parsed__cicp(uint32_t component) const;
inline uint32_t metadata_parsed__gama() const;
inline uint32_t metadata_parsed__srgb() const;
#endif // __cplusplus
@@ -1264,6 +1265,55 @@ wuffs_base__more_information__metadata_parsed__chrm(
return ((int32_t)(u << 8)) >> 8;
}
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CICP__COLOR_PRIMARIES 0
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CICP__TRANSFER_FUNCTION 1
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CICP__MATRIX_COEFFICIENTS \
2
#define WUFFS_BASE__MORE_INFORMATION__METADATA_PARSED__CICP__VIDEO_FULL_RANGE_FLAG \
3
// wuffs_base__more_information__metadata_parsed__cicp returns
// Coding-Independent Code Points values.
//
// - Component 0 is the Color Primaries.
// - Component 1 is the Transfer Function.
// - Component 2 is the Matrix Coefficients.
// - Component 3 is the Video Full Range Flag.
//
// The (CP, TF) pair is the most interesting of these four. Some examples:
//
// - (CP: 1, TF: 1) is "bt.709".
// - (CP: 1, TF: 8) is "linear-light-srgb".
// - (CP: 1, TF: 13) is "srgb".
// - (CP: 5, TF: 6) is "bt.601-pal".
// - (CP: 6, TF: 6) is "bt.601-ntsc".
// - (CP: 9, TF: 14) is "bt.2020-10-bit".
// - (CP: 9, TF: 15) is "bt.2020-12-bit".
// - (CP: 9, TF: 16) is "bt.2100-pq".
// - (CP: 9, TF: 18) is "bt.2100-hlg".
// - (CP: 11, TF: 17) is "dci-p3".
// - (CP: 12, TF: 13) is "display-p3".
// - (CP: 12, TF: 16) is "p3-d65-pq".
//
// For PNG, the MC value is always zero, as PNG uses the RGB color model. For
// H.273, valid values include 0, 1, 5, 6 and 9. See the AOMediaCodec page.
//
// For PNG, the VFRF value is 0 (for narrow range) or 1 (for full range).
//
// See:
//
// - https://github.com/AOMediaCodec/libavif/wiki/CICP
// - https://svgees.us/blog/cICP.html
// - https://www.itu.int/rec/T-REC-H.273-202407-I
// - https://www.w3.org/TR/png-3/#cICP-chunk
static inline uint8_t //
wuffs_base__more_information__metadata_parsed__cicp(
const wuffs_base__more_information* m,
uint32_t component) {
int shift = 8 * (component & 3);
return ((uint8_t)(m->x >> shift));
}
// wuffs_base__more_information__metadata_parsed__gama returns inverse gamma
// correction values (scaled by 100000) like the PNG "gAMA" chunk. For example,
// for gamma = 2.2, this returns 45455 (approximating 100000 / 2.2).
@@ -1328,6 +1378,11 @@ wuffs_base__more_information::metadata_parsed__chrm(uint32_t component) const {
return wuffs_base__more_information__metadata_parsed__chrm(this, component);
}
inline uint8_t //
wuffs_base__more_information::metadata_parsed__cicp(uint32_t component) const {
return wuffs_base__more_information__metadata_parsed__cicp(this, component);
}
inline uint32_t //
wuffs_base__more_information::metadata_parsed__gama() const {
return wuffs_base__more_information__metadata_parsed__gama(this);