Switch avifImage's CICP storage from enums to uint16_t, for future compatibility with amendments to H.273 Fixes: #461
diff --git a/include/avif/avif.h b/include/avif/avif.h index 31c758a..b99d719 100644 --- a/include/avif/avif.h +++ b/include/avif/avif.h
@@ -377,9 +377,14 @@ // ICC profile is not specified, these will be stored in the AVIF container's `colr` box with // a type of `nclx`. If your system supports ICC profiles, be sure to check for the existence // of one (avifImage.icc) before relying on the values listed here! - avifColorPrimaries colorPrimaries; - avifTransferCharacteristics transferCharacteristics; - avifMatrixCoefficients matrixCoefficients; + // + // Note: These are type uint16_t instead of their associated enums as additional CICP values + // are likely to be added to H.273 in the future, and there might exist a legal CICP value + // in one of these members that is not labeled by the above enums in this version of libavif. + // See the discussion here: https://github.com/AOMediaCodec/libavif/issues/461 + uint16_t colorPrimaries; // corresponds to enum avifColorPrimaries + uint16_t transferCharacteristics; // corresponds to enum avifTransferCharacteristics + uint16_t matrixCoefficients; // corresponds to enum avifMatrixCoefficients // Transformations - These metadata values are encoded/decoded when transformFlags are set // appropriately, but do not impact/adjust the actual pixel buffers used (images won't be
diff --git a/include/avif/internal.h b/include/avif/internal.h index aaa4cf6..502c4a2 100644 --- a/include/avif/internal.h +++ b/include/avif/internal.h
@@ -280,9 +280,9 @@ uint32_t bitDepth; avifPixelFormat yuvFormat; avifChromaSamplePosition chromaSamplePosition; - avifColorPrimaries colorPrimaries; - avifTransferCharacteristics transferCharacteristics; - avifMatrixCoefficients matrixCoefficients; + uint16_t colorPrimaries; + uint16_t transferCharacteristics; + uint16_t matrixCoefficients; avifRange range; avifCodecConfigurationBox av1C; } avifSequenceHeader;
diff --git a/src/obu.c b/src/obu.c index c039a89..0d84d87 100644 --- a/src/obu.c +++ b/src/obu.c
@@ -261,9 +261,9 @@ header->av1C.monochrome = (uint8_t)mono_chrome; uint32_t color_description_present_flag = avifBitsRead(bits, 1); if (color_description_present_flag) { - header->colorPrimaries = (avifColorPrimaries)avifBitsRead(bits, 8); // color_primaries - header->transferCharacteristics = (avifTransferCharacteristics)avifBitsRead(bits, 8); // transfer_characteristics - header->matrixCoefficients = (avifMatrixCoefficients)avifBitsRead(bits, 8); // matrix_coefficients + header->colorPrimaries = (uint16_t)avifBitsRead(bits, 8); // color_primaries + header->transferCharacteristics = (uint16_t)avifBitsRead(bits, 8); // transfer_characteristics + header->matrixCoefficients = (uint16_t)avifBitsRead(bits, 8); // matrix_coefficients } else { header->colorPrimaries = AVIF_COLOR_PRIMARIES_UNSPECIFIED; header->transferCharacteristics = AVIF_TRANSFER_CHARACTERISTICS_UNSPECIFIED;
diff --git a/src/read.c b/src/read.c index db18c9a..214f7bc 100644 --- a/src/read.c +++ b/src/read.c
@@ -72,9 +72,9 @@ size_t iccSize; avifBool hasNCLX; - avifColorPrimaries colorPrimaries; - avifTransferCharacteristics transferCharacteristics; - avifMatrixCoefficients matrixCoefficients; + uint16_t colorPrimaries; + uint16_t transferCharacteristics; + uint16_t matrixCoefficients; avifRange range; } avifColourInformationBox; @@ -1254,16 +1254,10 @@ colr->icc = avifROStreamCurrent(&s); colr->iccSize = avifROStreamRemainingBytes(&s); } else if (!memcmp(colorType, "nclx", 4)) { - uint16_t tmp16; - // unsigned int(16) colour_primaries; - CHECK(avifROStreamReadU16(&s, &tmp16)); - colr->colorPrimaries = (avifColorPrimaries)tmp16; - // unsigned int(16) transfer_characteristics; - CHECK(avifROStreamReadU16(&s, &tmp16)); - colr->transferCharacteristics = (avifTransferCharacteristics)tmp16; - // unsigned int(16) matrix_coefficients; - CHECK(avifROStreamReadU16(&s, &tmp16)); - colr->matrixCoefficients = (avifMatrixCoefficients)tmp16; + CHECK(avifROStreamReadU16(&s, &colr->colorPrimaries)); // unsigned int(16) colour_primaries; + CHECK(avifROStreamReadU16(&s, &colr->transferCharacteristics)); // unsigned int(16) transfer_characteristics; + CHECK(avifROStreamReadU16(&s, &colr->matrixCoefficients)); // unsigned int(16) matrix_coefficients; + // unsigned int(1) full_range_flag; // unsigned int(7) reserved = 0; uint8_t tmp8;
diff --git a/src/write.c b/src/write.c index b65f993..9362f52 100644 --- a/src/write.c +++ b/src/write.c
@@ -229,9 +229,9 @@ // Therefore, *always* writing an nclx box, even if an a prof box was already written above. avifBoxMarker colr = avifRWStreamWriteBox(s, "colr", AVIF_BOX_SIZE_TBD); avifRWStreamWriteChars(s, "nclx", 4); // unsigned int(32) colour_type; - avifRWStreamWriteU16(s, (uint16_t)imageMetadata->colorPrimaries); // unsigned int(16) colour_primaries; - avifRWStreamWriteU16(s, (uint16_t)imageMetadata->transferCharacteristics); // unsigned int(16) transfer_characteristics; - avifRWStreamWriteU16(s, (uint16_t)imageMetadata->matrixCoefficients); // unsigned int(16) matrix_coefficients; + avifRWStreamWriteU16(s, imageMetadata->colorPrimaries); // unsigned int(16) colour_primaries; + avifRWStreamWriteU16(s, imageMetadata->transferCharacteristics); // unsigned int(16) transfer_characteristics; + avifRWStreamWriteU16(s, imageMetadata->matrixCoefficients); // unsigned int(16) matrix_coefficients; avifRWStreamWriteU8(s, (imageMetadata->yuvRange == AVIF_RANGE_FULL) ? 0x80 : 0); // unsigned int(1) full_range_flag; // unsigned int(7) reserved = 0; avifRWStreamFinishBox(s, colr);