diff --git a/include/avif/internal.h b/include/avif/internal.h index 236633f866..1d1e5c31d3 100644 --- a/include/avif/internal.h +++ b/include/avif/internal.h @@ -783,7 +783,7 @@ typedef struct avifSequenceHeader avifTransferCharacteristics transferCharacteristics; avifMatrixCoefficients matrixCoefficients; avifRange range; - avifCodecConfigurationBox av1C; // TODO(yguyon): Rename or add av2C + avifCodecConfigurationBox codecConfig; // "av1C" for AV1 ("av2C" for AV2 if AVIF_CODEC_AVM) } avifSequenceHeader; AVIF_NODISCARD avifBool avifSequenceHeaderParse(avifSequenceHeader * header, const avifROData * sample, avifCodecType codecType); @@ -802,7 +802,7 @@ typedef enum avifPixiSubsamplingType // Mapping from subsampling_x, subsampling_y as defined in AV1 specification Section 6.4.2 // to PixelInformationBox subsampling_type as defined in ISO/IEC 23008-12:2024/CDAM 2:2025 section 6.5.6.3. -uint8_t avifCodecConfigurationBoxGetSubsamplingType(const avifCodecConfigurationBox * av1C, uint8_t channelIndex); +uint8_t avifCodecConfigurationBoxGetSubsamplingType(const avifCodecConfigurationBox * codecConfig, uint8_t channelIndex); #endif // --------------------------------------------------------------------------- diff --git a/src/obu.c b/src/obu.c index e4b4ce3790..a1662362be 100644 --- a/src/obu.c +++ b/src/obu.c @@ -158,7 +158,7 @@ static avifBool parseSequenceHeaderProfile(avifBits * bits, uint32_t numBits, av if (seq_profile > 2) { return AVIF_FALSE; } - header->av1C.seqProfile = (uint8_t)seq_profile; + header->codecConfig.seqProfile = (uint8_t)seq_profile; return !bits->error; } @@ -171,8 +171,8 @@ static avifBool parseSequenceHeaderLevelIdxAndTier(avifBits * bits, avifSequence } if (header->reduced_still_picture_header) { - header->av1C.seqLevelIdx0 = (uint8_t)avifBitsRead(bits, 5); - header->av1C.seqTier0 = 0; + header->codecConfig.seqLevelIdx0 = (uint8_t)avifBitsRead(bits, 5); + header->codecConfig.seqTier0 = 0; } else { uint32_t timing_info_present_flag = avifBitsRead(bits, 1); uint32_t decoder_model_info_present_flag = 0; @@ -201,13 +201,13 @@ static avifBool parseSequenceHeaderLevelIdxAndTier(avifBits * bits, avifSequence avifBitsRead(bits, 12); // operating_point_idc uint32_t seq_level_idx = avifBitsRead(bits, 5); if (i == 0) { - header->av1C.seqLevelIdx0 = (uint8_t)seq_level_idx; - header->av1C.seqTier0 = 0; + header->codecConfig.seqLevelIdx0 = (uint8_t)seq_level_idx; + header->codecConfig.seqTier0 = 0; } if (seq_level_idx > 7) { uint32_t seq_tier = avifBitsRead(bits, 1); if (i == 0) { - header->av1C.seqTier0 = (uint8_t)seq_tier; + header->codecConfig.seqTier0 = (uint8_t)seq_tier; } } if (decoder_model_info_present_flag) { @@ -282,22 +282,22 @@ static avifBool parseAV1SequenceHeaderColorConfig(avifBits * bits, avifSequenceH { header->bitDepth = 8; header->chromaSamplePosition = AVIF_CHROMA_SAMPLE_POSITION_UNKNOWN; - header->av1C.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; + header->codecConfig.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; uint32_t high_bitdepth = avifBitsRead(bits, 1); - header->av1C.highBitdepth = (uint8_t)high_bitdepth; - if ((header->av1C.seqProfile == 2) && high_bitdepth) { + header->codecConfig.highBitdepth = (uint8_t)high_bitdepth; + if ((header->codecConfig.seqProfile == 2) && high_bitdepth) { uint32_t twelve_bit = avifBitsRead(bits, 1); header->bitDepth = twelve_bit ? 12 : 10; - header->av1C.twelveBit = (uint8_t)twelve_bit; + header->codecConfig.twelveBit = (uint8_t)twelve_bit; } else /* if (seq_profile <= 2) */ { header->bitDepth = high_bitdepth ? 10 : 8; - header->av1C.twelveBit = 0; + header->codecConfig.twelveBit = 0; } uint32_t mono_chrome = 0; - if (header->av1C.seqProfile != 1) { + if (header->codecConfig.seqProfile != 1) { mono_chrome = avifBitsRead(bits, 1); } - header->av1C.monochrome = (uint8_t)mono_chrome; + header->codecConfig.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 @@ -310,21 +310,21 @@ static avifBool parseAV1SequenceHeaderColorConfig(avifBits * bits, avifSequenceH } if (mono_chrome) { header->range = avifBitsRead(bits, 1) ? AVIF_RANGE_FULL : AVIF_RANGE_LIMITED; // color_range - header->av1C.chromaSubsamplingX = 1; - header->av1C.chromaSubsamplingY = 1; + header->codecConfig.chromaSubsamplingX = 1; + header->codecConfig.chromaSubsamplingY = 1; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV400; } else if (header->colorPrimaries == AVIF_COLOR_PRIMARIES_BT709 && header->transferCharacteristics == AVIF_TRANSFER_CHARACTERISTICS_SRGB && header->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY) { header->range = AVIF_RANGE_FULL; - header->av1C.chromaSubsamplingX = 0; - header->av1C.chromaSubsamplingY = 0; + header->codecConfig.chromaSubsamplingX = 0; + header->codecConfig.chromaSubsamplingY = 0; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV444; } else { uint32_t subsampling_x = 0; uint32_t subsampling_y = 0; header->range = avifBitsRead(bits, 1) ? AVIF_RANGE_FULL : AVIF_RANGE_LIMITED; // color_range - switch (header->av1C.seqProfile) { + switch (header->codecConfig.seqProfile) { case 0: subsampling_x = 1; subsampling_y = 1; @@ -357,10 +357,10 @@ static avifBool parseAV1SequenceHeaderColorConfig(avifBits * bits, avifSequenceH if (subsampling_x && subsampling_y) { header->chromaSamplePosition = (avifChromaSamplePosition)avifBitsRead(bits, 2); // chroma_sample_position - header->av1C.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; + header->codecConfig.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; } - header->av1C.chromaSubsamplingX = (uint8_t)subsampling_x; - header->av1C.chromaSubsamplingY = (uint8_t)subsampling_y; + header->codecConfig.chromaSubsamplingX = (uint8_t)subsampling_x; + header->codecConfig.chromaSubsamplingY = (uint8_t)subsampling_y; } return !bits->error; @@ -405,25 +405,25 @@ static avifBool parseAV2ChromaFormatBitdepth(avifBits * bits, avifSequenceHeader } else { return AVIF_FALSE; } - header->av1C.highBitdepth = header->bitDepth > 8; - header->av1C.twelveBit = header->bitDepth == 12; - header->av1C.monochrome = chromaFormatIdc == AV2_CHROMA_FORMAT_400; + header->codecConfig.highBitdepth = header->bitDepth > 8; + header->codecConfig.twelveBit = header->bitDepth == 12; + header->codecConfig.monochrome = chromaFormatIdc == AV2_CHROMA_FORMAT_400; - if (header->av1C.monochrome) { - header->av1C.chromaSubsamplingX = 1; - header->av1C.chromaSubsamplingY = 1; + if (header->codecConfig.monochrome) { + header->codecConfig.chromaSubsamplingX = 1; + header->codecConfig.chromaSubsamplingY = 1; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV400; } else if (chromaFormatIdc == AV2_CHROMA_FORMAT_420) { - header->av1C.chromaSubsamplingX = 1; - header->av1C.chromaSubsamplingY = 1; + header->codecConfig.chromaSubsamplingX = 1; + header->codecConfig.chromaSubsamplingY = 1; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV420; } else if (chromaFormatIdc == AV2_CHROMA_FORMAT_444) { - header->av1C.chromaSubsamplingX = 0; - header->av1C.chromaSubsamplingY = 0; + header->codecConfig.chromaSubsamplingX = 0; + header->codecConfig.chromaSubsamplingY = 0; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV444; } else if (chromaFormatIdc == AV2_CHROMA_FORMAT_422) { - header->av1C.chromaSubsamplingX = 1; - header->av1C.chromaSubsamplingY = 0; + header->codecConfig.chromaSubsamplingX = 1; + header->codecConfig.chromaSubsamplingY = 0; header->yuvFormat = AVIF_PIXEL_FORMAT_YUV422; } else { return AVIF_FALSE; @@ -445,7 +445,7 @@ static avifBool parseAV1SequenceHeader(avifBits * bits, avifSequenceHeader * hea avifBitsRead(bits, 3); // enable_superres, enable_cdef, enable_restoration AVIF_CHECK(parseAV1SequenceHeaderColorConfig(bits, header)); - if (!header->av1C.monochrome) { + if (!header->codecConfig.monochrome) { avifBitsRead(bits, 1); // separate_uv_delta_q } @@ -469,11 +469,11 @@ static avifBool parseAV2SequenceHeader(avifBits * bits, avifSequenceHeader * hea avifBitsRead(bits, 1); // still_picture return AVIF_FALSE; } - header->av1C.seqLevelIdx0 = (uint8_t)avifBitsRead(bits, 5); - if (header->av1C.seqLevelIdx0 > 7 && !header->reduced_still_picture_header) { + header->codecConfig.seqLevelIdx0 = (uint8_t)avifBitsRead(bits, 5); + if (header->codecConfig.seqLevelIdx0 > 7 && !header->reduced_still_picture_header) { avifBitsRead(bits, 1); // single_tier_0 } - header->av1C.seqTier0 = 0; + header->codecConfig.seqTier0 = 0; uint32_t frame_width_bits = avifBitsRead(bits, 4) + 1; uint32_t frame_height_bits = avifBitsRead(bits, 4) + 1; @@ -495,7 +495,7 @@ static avifBool parseAV2SequenceHeader(avifBits * bits, avifSequenceHeader * hea header->range = AVIF_RANGE_LIMITED; header->chromaSamplePosition = AVIF_CHROMA_SAMPLE_POSITION_UNKNOWN; - header->av1C.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; + header->codecConfig.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; // Other ignored fields. return !bits->error; @@ -562,7 +562,7 @@ static avifBool parseAV2ContentInterpretation(avifBits * bits, avifSequenceHeade if (chromaSamplePositionPresent) { const uint32_t chromaSamplePosition = avifBitsReadVLC(bits); // ci_chroma_sample_position_0 header->chromaSamplePosition = av2ChromaSamplePositionToAv1ChromaSamplePosition(chromaSamplePosition); - header->av1C.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; + header->codecConfig.chromaSamplePosition = (uint8_t)header->chromaSamplePosition; } // Other ignored fields. diff --git a/src/read.c b/src/read.c index f343ed9875..9b326dc83e 100644 --- a/src/read.c +++ b/src/read.c @@ -179,7 +179,7 @@ typedef struct avifProperty avifImageSpatialExtents ispe; avifAuxiliaryType auxC; // Contents of 'auxC' for items, or 'auxi' for tracks avifColourInformationBox colr; - avifCodecConfigurationBox av1C; // TODO(yguyon): Rename or add av2C + avifCodecConfigurationBox codecConfig; avifPixelAspectRatioBox pasp; avifCleanApertureBox clap; avifImageRotation irot; @@ -376,29 +376,29 @@ static avifCodecType avifSampleTableGetCodecType(const avifSampleTable * sampleT return AVIF_CODEC_TYPE_UNKNOWN; } -static uint32_t avifCodecConfigurationBoxGetDepth(const avifCodecConfigurationBox * av1C) +static uint32_t avifCodecConfigurationBoxGetDepth(const avifCodecConfigurationBox * codecConfig) { - if (av1C->twelveBit) { + if (codecConfig->twelveBit) { return 12; - } else if (av1C->highBitdepth) { + } else if (codecConfig->highBitdepth) { return 10; } return 8; } #if defined(AVIF_ENABLE_EXPERIMENTAL_EXTENDED_PIXI) -uint8_t avifCodecConfigurationBoxGetSubsamplingType(const avifCodecConfigurationBox * av1C, uint8_t channelIndex) +uint8_t avifCodecConfigurationBoxGetSubsamplingType(const avifCodecConfigurationBox * codecConfig, uint8_t channelIndex) { if (channelIndex == 0) { return AVIF_PIXI_444; } - if (av1C->chromaSubsamplingX == 0) { - if (av1C->chromaSubsamplingY == 0) { + if (codecConfig->chromaSubsamplingX == 0) { + if (codecConfig->chromaSubsamplingY == 0) { return AVIF_PIXI_444; } return AVIF_PIXI_440; } - if (av1C->chromaSubsamplingY == 0) { + if (codecConfig->chromaSubsamplingY == 0) { return AVIF_PIXI_422; } return AVIF_PIXI_420; @@ -1270,15 +1270,15 @@ static avifResult avifDecoderItemValidateProperties(const avifDecoderItem * item } // configProp was copied from a tile item to the grid item. Comparing tileConfigProp with it // is equivalent to comparing tileConfigProp with the configPropName from the first tile. - if ((tileConfigProp->u.av1C.seqProfile != configProp->u.av1C.seqProfile) || - (tileConfigProp->u.av1C.seqLevelIdx0 != configProp->u.av1C.seqLevelIdx0) || - (tileConfigProp->u.av1C.seqTier0 != configProp->u.av1C.seqTier0) || - (tileConfigProp->u.av1C.highBitdepth != configProp->u.av1C.highBitdepth) || - (tileConfigProp->u.av1C.twelveBit != configProp->u.av1C.twelveBit) || - (tileConfigProp->u.av1C.monochrome != configProp->u.av1C.monochrome) || - (tileConfigProp->u.av1C.chromaSubsamplingX != configProp->u.av1C.chromaSubsamplingX) || - (tileConfigProp->u.av1C.chromaSubsamplingY != configProp->u.av1C.chromaSubsamplingY) || - (tileConfigProp->u.av1C.chromaSamplePosition != configProp->u.av1C.chromaSamplePosition)) { + if ((tileConfigProp->u.codecConfig.seqProfile != configProp->u.codecConfig.seqProfile) || + (tileConfigProp->u.codecConfig.seqLevelIdx0 != configProp->u.codecConfig.seqLevelIdx0) || + (tileConfigProp->u.codecConfig.seqTier0 != configProp->u.codecConfig.seqTier0) || + (tileConfigProp->u.codecConfig.highBitdepth != configProp->u.codecConfig.highBitdepth) || + (tileConfigProp->u.codecConfig.twelveBit != configProp->u.codecConfig.twelveBit) || + (tileConfigProp->u.codecConfig.monochrome != configProp->u.codecConfig.monochrome) || + (tileConfigProp->u.codecConfig.chromaSubsamplingX != configProp->u.codecConfig.chromaSubsamplingX) || + (tileConfigProp->u.codecConfig.chromaSubsamplingY != configProp->u.codecConfig.chromaSubsamplingY) || + (tileConfigProp->u.codecConfig.chromaSamplePosition != configProp->u.codecConfig.chromaSamplePosition)) { avifDiagnosticsPrintf(diag, "The fields of the %s property of tile item ID %u of type '%.4s' differs from other tiles", configPropName, @@ -1300,7 +1300,7 @@ static avifResult avifDecoderItemValidateProperties(const avifDecoderItem * item } if (pixiProp) { - const uint32_t configDepth = avifCodecConfigurationBoxGetDepth(&configProp->u.av1C); + const uint32_t configDepth = avifCodecConfigurationBoxGetDepth(&configProp->u.codecConfig); for (uint8_t i = 0; i < pixiProp->u.pixi.planeCount; ++i) { if (pixiProp->u.pixi.planeDepths[i] != configDepth) { // pixi depth must match configuration property depth @@ -1314,20 +1314,20 @@ static avifResult avifDecoderItemValidateProperties(const avifDecoderItem * item } #if defined(AVIF_ENABLE_EXPERIMENTAL_EXTENDED_PIXI) if (pixiProp->u.pixi.subsamplingFlag[i]) { - if (pixiProp->u.pixi.subsamplingType[i] != avifCodecConfigurationBoxGetSubsamplingType(&configProp->u.av1C, i)) { + if (pixiProp->u.pixi.subsamplingType[i] != avifCodecConfigurationBoxGetSubsamplingType(&configProp->u.codecConfig, i)) { avifDiagnosticsPrintf(diag, "Item ID %u subsampling type specified by pixi property [%u] for channel %u does not match %s property [%u,%u]", item->id, pixiProp->u.pixi.subsamplingType[i], i, configPropName, - configProp->u.av1C.chromaSubsamplingX, - configProp->u.av1C.chromaSubsamplingY); + configProp->u.codecConfig.chromaSubsamplingX, + configProp->u.codecConfig.chromaSubsamplingY); return AVIF_RESULT_BMFF_PARSE_FAILED; } - if (configProp->u.av1C.chromaSamplePosition != AVIF_CHROMA_SAMPLE_POSITION_UNKNOWN) { + if (configProp->u.codecConfig.chromaSamplePosition != AVIF_CHROMA_SAMPLE_POSITION_UNKNOWN) { const avifChromaSamplePosition expectedChromaSamplePosition = - i == AVIF_CHAN_Y ? AVIF_CHROMA_SAMPLE_POSITION_COLOCATED : configProp->u.av1C.chromaSamplePosition; + i == AVIF_CHAN_Y ? AVIF_CHROMA_SAMPLE_POSITION_COLOCATED : configProp->u.codecConfig.chromaSamplePosition; if (avifSubsamplingLocationToChromaSamplePosition(pixiProp->u.pixi.subsamplingType[i], pixiProp->u.pixi.subsamplingLocation[i]) != expectedChromaSamplePosition) { @@ -1338,7 +1338,7 @@ static avifResult avifDecoderItemValidateProperties(const avifDecoderItem * item pixiProp->u.pixi.subsamplingLocation[i], i, configPropName, - configProp->u.av1C.chromaSamplePosition); + configProp->u.codecConfig.chromaSamplePosition); return AVIF_RESULT_BMFF_PARSE_FAILED; } } @@ -1351,39 +1351,39 @@ static avifResult avifDecoderItemValidateProperties(const avifDecoderItem * item if (item->miniBoxPixelFormat != AVIF_PIXEL_FORMAT_NONE) { // This is a MinimizedImageBox ('mini'). - avifPixelFormat av1CPixelFormat; - if (configProp->u.av1C.monochrome) { - av1CPixelFormat = AVIF_PIXEL_FORMAT_YUV400; - } else if (configProp->u.av1C.chromaSubsamplingY == 1) { - av1CPixelFormat = AVIF_PIXEL_FORMAT_YUV420; - } else if (configProp->u.av1C.chromaSubsamplingX == 1) { - av1CPixelFormat = AVIF_PIXEL_FORMAT_YUV422; + avifPixelFormat codecConfigFormat; + if (configProp->u.codecConfig.monochrome) { + codecConfigFormat = AVIF_PIXEL_FORMAT_YUV400; + } else if (configProp->u.codecConfig.chromaSubsamplingY == 1) { + codecConfigFormat = AVIF_PIXEL_FORMAT_YUV420; + } else if (configProp->u.codecConfig.chromaSubsamplingX == 1) { + codecConfigFormat = AVIF_PIXEL_FORMAT_YUV422; } else { - av1CPixelFormat = AVIF_PIXEL_FORMAT_YUV444; + codecConfigFormat = AVIF_PIXEL_FORMAT_YUV444; } - if (item->miniBoxPixelFormat != av1CPixelFormat) { + if (item->miniBoxPixelFormat != codecConfigFormat) { avifDiagnosticsPrintf(diag, "Item ID %u format [%s] specified by MinimizedImageBox does not match %s property format [%s]", item->id, avifPixelFormatToString(item->miniBoxPixelFormat), configPropName, - avifPixelFormatToString(av1CPixelFormat)); + avifPixelFormatToString(codecConfigFormat)); return AVIF_RESULT_BMFF_PARSE_FAILED; } - if (configProp->u.av1C.chromaSamplePosition == /*CSP_UNKNOWN=*/0) { + if (configProp->u.codecConfig.chromaSamplePosition == /*CSP_UNKNOWN=*/0) { // Section 6.4.2. Color config semantics of AV1 specification says: // CSP_UNKNOWN - the source video transfer function must be signaled outside the AV1 bitstream // See https://aomediacodec.github.io/av1-spec/#color-config-semantics // So item->miniBoxChromaSamplePosition can differ and will override the AV1 value. - } else if ((uint8_t)item->miniBoxChromaSamplePosition != configProp->u.av1C.chromaSamplePosition) { + } else if ((uint8_t)item->miniBoxChromaSamplePosition != configProp->u.codecConfig.chromaSamplePosition) { avifDiagnosticsPrintf(diag, "Item ID %u chroma sample position [%u] specified by MinimizedImageBox does not match %s property chroma sample position [%u]", item->id, (uint32_t)item->miniBoxChromaSamplePosition, configPropName, - configProp->u.av1C.chromaSamplePosition); + configProp->u.codecConfig.chromaSamplePosition); return AVIF_RESULT_BMFF_PARSE_FAILED; } } @@ -2582,7 +2582,7 @@ static avifResult avifParseMiniHDRProperties(avifROStream * s, uint32_t * hasCll // See https://aomediacodec.github.io/av1-isobmff/v1.2.0.html#av1codecconfigurationbox-syntax. static avifBool avifParseCodecConfiguration(avifROStream * s, avifCodecConfigurationBox * config, const char * configPropName, avifDiagnostics * diag) { - const size_t av1COffset = s->offset; + const size_t codecConfigOffset = s->offset; uint32_t marker, version; AVIF_CHECK(avifROStreamReadBitsU32(s, &marker, /*bitCount=*/1)); // unsigned int (1) marker = 1; @@ -2626,7 +2626,7 @@ static avifBool avifParseCodecConfiguration(avifROStream * s, avifCodecConfigura // The following is skipped by avifParseItemPropertyContainerBox(). // unsigned int (8) configOBUs[]; - AVIF_CHECK(s->offset - av1COffset == 4); // Make sure avifParseCodecConfiguration() reads exactly 4 bytes. + AVIF_CHECK(s->offset - codecConfigOffset == 4); // Make sure avifParseCodecConfiguration() reads exactly 4 bytes. return AVIF_TRUE; } @@ -2639,7 +2639,7 @@ static avifBool avifParseCodecConfigurationBoxProperty(avifProperty * prop, char diagContext[10]; snprintf(diagContext, sizeof(diagContext), "Box[%.4s]", configPropName); // "Box[av1C]" or "Box[av2C]" BEGIN_STREAM(s, raw, rawLen, diag, diagContext); - return avifParseCodecConfiguration(&s, &prop->u.av1C, configPropName, diag); + return avifParseCodecConfiguration(&s, &prop->u.codecConfig, configPropName, diag); } static avifBool avifParsePixelAspectRatioBoxProperty(avifProperty * prop, const uint8_t * raw, size_t rawLen, avifDiagnostics * diag) @@ -4407,7 +4407,7 @@ static avifResult avifParseMinimizedImageBox(avifDecoderData * data, // Property with fixed index 1. avifProperty * colorCodecConfigProp = avifMetaCreateProperty(meta, (const char *)codecConfigType); AVIF_CHECKERR(colorCodecConfigProp, AVIF_RESULT_OUT_OF_MEMORY); - colorCodecConfigProp->u.av1C = mainItemCodecConfig; + colorCodecConfigProp->u.codecConfig = mainItemCodecConfig; AVIF_CHECKERR(avifDecoderItemAddProperty(colorItem, colorCodecConfigProp), AVIF_RESULT_OUT_OF_MEMORY); // Property with fixed index 2. @@ -4453,7 +4453,7 @@ static avifResult avifParseMinimizedImageBox(avifDecoderData * data, // Property with fixed index 6. avifProperty * alphaCodecConfigProp = avifMetaCreateProperty(meta, (const char *)codecConfigType); AVIF_CHECKERR(alphaCodecConfigProp, AVIF_RESULT_OUT_OF_MEMORY); - alphaCodecConfigProp->u.av1C = alphaItemCodecConfig; + alphaCodecConfigProp->u.codecConfig = alphaItemCodecConfig; AVIF_CHECKERR(avifDecoderItemAddProperty(alphaItem, alphaCodecConfigProp), AVIF_RESULT_OUT_OF_MEMORY); } else { AVIF_CHECKERR(avifMetaCreateProperty(meta, "skip"), AVIF_RESULT_OUT_OF_MEMORY); // Placeholder. @@ -4526,7 +4526,7 @@ static avifResult avifParseMinimizedImageBox(avifDecoderData * data, // Property with fixed index 17. avifProperty * gainmapCodecConfigProp = avifMetaCreateProperty(meta, (const char *)codecConfigType); AVIF_CHECKERR(gainmapCodecConfigProp, AVIF_RESULT_OUT_OF_MEMORY); - gainmapCodecConfigProp->u.av1C = gainmapItemCodecConfig; + gainmapCodecConfigProp->u.codecConfig = gainmapItemCodecConfig; AVIF_CHECKERR(avifDecoderItemAddProperty(gainmapItem, gainmapCodecConfigProp), AVIF_RESULT_OUT_OF_MEMORY); } else { AVIF_CHECKERR(avifMetaCreateProperty(meta, "skip"), AVIF_RESULT_OUT_OF_MEMORY); // Placeholder. @@ -5974,19 +5974,19 @@ static avifResult avifReadCodecConfigProperty(avifImage * image, const avifPrope { const avifProperty * configProp = avifPropertyArrayFind(properties, avifGetConfigurationPropertyName(codecType)); if (configProp) { - image->depth = avifCodecConfigurationBoxGetDepth(&configProp->u.av1C); - if (configProp->u.av1C.monochrome) { + image->depth = avifCodecConfigurationBoxGetDepth(&configProp->u.codecConfig); + if (configProp->u.codecConfig.monochrome) { image->yuvFormat = AVIF_PIXEL_FORMAT_YUV400; } else { - if (configProp->u.av1C.chromaSubsamplingX && configProp->u.av1C.chromaSubsamplingY) { + if (configProp->u.codecConfig.chromaSubsamplingX && configProp->u.codecConfig.chromaSubsamplingY) { image->yuvFormat = AVIF_PIXEL_FORMAT_YUV420; - } else if (configProp->u.av1C.chromaSubsamplingX) { + } else if (configProp->u.codecConfig.chromaSubsamplingX) { image->yuvFormat = AVIF_PIXEL_FORMAT_YUV422; } else { image->yuvFormat = AVIF_PIXEL_FORMAT_YUV444; } } - image->yuvChromaSamplePosition = (avifChromaSamplePosition)configProp->u.av1C.chromaSamplePosition; + image->yuvChromaSamplePosition = (avifChromaSamplePosition)configProp->u.codecConfig.chromaSamplePosition; } else { // A configuration property box is mandatory in all valid AVIF configurations. Bail out. return AVIF_RESULT_BMFF_PARSE_FAILED; diff --git a/src/write.c b/src/write.c index b8a87dc846..e4ac7cb1ad 100644 --- a/src/write.c +++ b/src/write.c @@ -162,15 +162,15 @@ void avifCodecEncodeOutputDestroy(avifCodecEncodeOutput * encodeOutput) typedef struct avifEncoderItem { uint16_t id; - uint8_t type[4]; // 4-character 'item_type' field in the 'infe' (item info entry) box - avifCodec * codec; // only present on image items - avifCodecEncodeOutput * encodeOutput; // AV1 sample data - avifRWData metadataPayload; // Exif/XMP data - avifCodecConfigurationBox av1C; // Harvested in avifEncoderFinish(), if encodeOutput has samples - // TODO(yguyon): Rename or add av2C - uint32_t cellIndex; // Which row-major cell index corresponds to this item. only present on image items - avifItemCategory itemCategory; // Category of item being encoded - avifBool hiddenImage; // A hidden image item has (flags & 1) equal to 1 in its ItemInfoEntry. + uint8_t type[4]; // 4-character 'item_type' field in the 'infe' (item info entry) box + avifCodec * codec; // only present on image items + avifCodecEncodeOutput * encodeOutput; // AV1 sample data + avifRWData metadataPayload; // Exif/XMP data + avifCodecConfigurationBox codecConfig; // "av1C" for AV1 ("av2C" for AV2 if AVIF_CODEC_AVM) + // Harvested in avifEncoderFinish(), if encodeOutput has samples + uint32_t cellIndex; // Which row-major cell index corresponds to this item. only present on image items + avifItemCategory itemCategory; // Category of item being encoded + avifBool hiddenImage; // A hidden image item has (flags & 1) equal to 1 in its ItemInfoEntry. const char * infeName; size_t infeNameSize; @@ -2761,7 +2761,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream * AVIF_CHECKRES(avifRWStreamWriteBits(s, (uint32_t)gainmapData->size, largeItemDataFlag ? 28 : 15)); // unsigned int(large_item_data_flag ? 28 : 15) gainmap_item_data_size; } if (hasHdr && hasGainmap && gainmapData->size != 0) { - if (!memcmp(&colorItem->av1C, &gainmapItem->av1C, sizeof(colorItem->av1C))) { + if (!memcmp(&colorItem->codecConfig, &gainmapItem->codecConfig, sizeof(colorItem->codecConfig))) { // The gainmap codec config is copied from the main codec config. // This is signaled by a size of 0. gainmapCodecConfigSize = 0; @@ -2778,7 +2778,7 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream * AVIF_CHECKRES(avifRWStreamWriteBits(s, (uint32_t)alphaData->size, largeItemDataFlag ? 28 : 15)); // unsigned int(large_item_data_flag ? 28 : 15) alpha_item_data_size; } if (hasAlpha && alphaData->size != 0) { - if (!memcmp(&colorItem->av1C, &alphaItem->av1C, sizeof(colorItem->av1C))) { + if (!memcmp(&colorItem->codecConfig, &alphaItem->codecConfig, sizeof(colorItem->codecConfig))) { // The alpha codec config is copied from the main codec config. // This is signaled by a size of 0. alphaCodecConfigSize = 0; @@ -2806,13 +2806,13 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream * // Chunks if (codecConfigSize > 0) { - AVIF_CHECKRES(writeCodecConfig(s, &colorItem->av1C)); // unsigned int(8) main_item_codec_config[main_item_codec_config_size]; + AVIF_CHECKRES(writeCodecConfig(s, &colorItem->codecConfig)); // unsigned int(8) main_item_codec_config[main_item_codec_config_size]; } if (hasAlpha && alphaData->size != 0 && alphaCodecConfigSize != 0) { - AVIF_CHECKRES(writeCodecConfig(s, &alphaItem->av1C)); // unsigned int(8) alpha_item_codec_config[alpha_item_codec_config_size]; + AVIF_CHECKRES(writeCodecConfig(s, &alphaItem->codecConfig)); // unsigned int(8) alpha_item_codec_config[alpha_item_codec_config_size]; } if (hasHdr && hasGainmap && gainmapCodecConfigSize != 0) { - AVIF_CHECKRES(writeCodecConfig(s, &gainmapItem->av1C)); // unsigned int(8) gainmap_item_codec_config[gainmap_item_codec_config_size]; + AVIF_CHECKRES(writeCodecConfig(s, &gainmapItem->codecConfig)); // unsigned int(8) gainmap_item_codec_config[gainmap_item_codec_config_size]; } if (hasIcc) { @@ -2981,11 +2981,11 @@ static avifResult avifRWStreamWriteProperties(avifItemPropertyDedup * const dedu } #if defined(AVIF_ENABLE_EXPERIMENTAL_EXTENDED_PIXI) if (flags & 1) { - AVIF_ASSERT_OR_RETURN(item->av1C.chromaSamplePosition != AVIF_CHROMA_SAMPLE_POSITION_RESERVED); + AVIF_ASSERT_OR_RETURN(item->codecConfig.chromaSamplePosition != AVIF_CHROMA_SAMPLE_POSITION_RESERVED); // Do not signal any subsampling information if the sample position is unknown because the 'pixi' box // does not have an enum entry for "unknown subsampling location". - const uint8_t subsampling_flag = item->av1C.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_VERTICAL || - item->av1C.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_COLOCATED; + const uint8_t subsampling_flag = item->codecConfig.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_VERTICAL || + item->codecConfig.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_COLOCATED; for (uint8_t chan = 0; chan < channelCount; ++chan) { AVIF_CHECKRES(avifRWStreamWriteBits(&dedup->s, 0, /*bitCount=*/3)); // unsigned int(3) channel_idc; AVIF_CHECKRES(avifRWStreamWriteBits(&dedup->s, 0, /*bitCount=*/1)); // unsigned int(1) reserved; @@ -2993,9 +2993,9 @@ static avifResult avifRWStreamWriteProperties(avifItemPropertyDedup * const dedu AVIF_CHECKRES(avifRWStreamWriteBits(&dedup->s, subsampling_flag, /*bitCount=*/1)); // unsigned int(1) subsampling_flag; AVIF_CHECKRES(avifRWStreamWriteBits(&dedup->s, 0, /*bitCount=*/1)); // unsigned int(1) channel_label_flag; if (subsampling_flag) { - const uint8_t subsamplingType = avifCodecConfigurationBoxGetSubsamplingType(&item->av1C, chan); + const uint8_t subsamplingType = avifCodecConfigurationBoxGetSubsamplingType(&item->codecConfig, chan); const uint8_t subsamplingLocation = subsamplingType == AVIF_PIXI_444 ? 0 - : item->av1C.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_VERTICAL + : item->codecConfig.chromaSamplePosition == AVIF_CHROMA_SAMPLE_POSITION_VERTICAL ? 0 : 2; AVIF_CHECKRES(avifRWStreamWriteBits(&dedup->s, subsamplingType, /*bitCount=*/4)); // unsigned int(4) subsampling_type; @@ -3011,7 +3011,7 @@ static avifResult avifRWStreamWriteProperties(avifItemPropertyDedup * const dedu // Codec configuration box ('av1C' or 'av2C') if (item->codec) { avifItemPropertyDedupStart(dedup); - AVIF_CHECKRES(writeConfigBox(&dedup->s, &item->av1C, encoder->data->configPropName)); + AVIF_CHECKRES(writeConfigBox(&dedup->s, &item->codecConfig, encoder->data->configPropName)); AVIF_CHECKRES(avifItemPropertyDedupFinish(dedup, s, &item->associations, /*essential=*/AVIF_TRUE)); } @@ -3187,7 +3187,7 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) avifSequenceHeader sequenceHeader; AVIF_CHECKERR(avifSequenceHeaderParse(&sequenceHeader, (const avifROData *)&firstSample->data, codecType), avifGetErrorForItemCategory(item->itemCategory)); - item->av1C = sequenceHeader.av1C; + item->codecConfig = sequenceHeader.codecConfig; } } @@ -3712,7 +3712,7 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) AVIF_CHECKRES(avifRWStreamWriteZeros(&s, 32 - 11)); // AVIF_CHECKRES(avifRWStreamWriteU16(&s, 0x0018)); // template unsigned int(16) depth = 0x0018; AVIF_CHECKRES(avifRWStreamWriteU16(&s, (uint16_t)0xffff)); // int(16) pre_defined = -1; - AVIF_CHECKRES(writeConfigBox(&s, &item->av1C, encoder->data->configPropName)); + AVIF_CHECKRES(writeConfigBox(&s, &item->codecConfig, encoder->data->configPropName)); if (item->itemCategory == AVIF_ITEM_COLOR) { AVIF_CHECKRES(avifEncoderWriteColorProperties(&s, imageMetadata, NULL, NULL)); AVIF_CHECKRES(avifEncoderWriteHDRProperties(NULL, &s, imageMetadata, NULL, NULL)); @@ -3865,7 +3865,7 @@ avifResult avifEncoderWrite(avifEncoder * encoder, const avifImage * image, avif // See https://aomediacodec.github.io/av1-isobmff/v1.2.0.html#av1codecconfigurationbox-syntax. static avifResult writeCodecConfig(avifRWStream * s, const avifCodecConfigurationBox * cfg) { - const size_t av1COffset = s->offset; + const size_t codecConfigOffset = s->offset; AVIF_CHECKRES(avifRWStreamWriteBits(s, 1, /*bitCount=*/1)); // unsigned int (1) marker = 1; AVIF_CHECKRES(avifRWStreamWriteBits(s, 1, /*bitCount=*/7)); // unsigned int (7) version = 1; @@ -3890,7 +3890,7 @@ static avifResult writeCodecConfig(avifRWStream * s, const avifCodecConfiguratio // See https://aomediacodec.github.io/av1-avif/v1.1.0.html#av1-configuration-item-property. // unsigned int (8) configOBUs[]; - AVIF_ASSERT_OR_RETURN(s->offset - av1COffset == 4); // Make sure writeCodecConfig() writes exactly 4 bytes. + AVIF_ASSERT_OR_RETURN(s->offset - codecConfigOffset == 4); // Make sure writeCodecConfig() writes exactly 4 bytes. return AVIF_RESULT_OK; }