Skip to content

Commit

Permalink
Minor comment fixes for the mini box code
Browse files Browse the repository at this point in the history
Change
   bit(2) version;
to
   bit(2) version = 0;
to match the spec exactly.
  • Loading branch information
wantehchang committed Aug 15, 2024
1 parent 0d3e5e2 commit 4f1acb6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ AVIF_NODISCARD avifBool avifROStreamReadBoxHeader(avifROStream * stream, avifBox
AVIF_NODISCARD avifBool avifROStreamReadBoxHeaderPartial(avifROStream * stream, avifBoxHeader * header, avifBool topLevel); // This doesn't require that the full box can fit in the stream
AVIF_NODISCARD avifBool avifROStreamReadVersionAndFlags(avifROStream * stream, uint8_t * version, uint32_t * flags); // version and flags ptrs are both optional
AVIF_NODISCARD avifBool avifROStreamReadAndEnforceVersion(avifROStream * stream, uint8_t enforcedVersion); // currently discards flags
// The following functions can write non-aligned bits.
// The following functions can read non-aligned bits.
AVIF_NODISCARD avifBool avifROStreamReadBits8(avifROStream * stream, uint8_t * v, size_t bitCount);
AVIF_NODISCARD avifBool avifROStreamReadBits(avifROStream * stream, uint32_t * v, size_t bitCount);

Expand Down
4 changes: 3 additions & 1 deletion src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -3572,7 +3572,7 @@ static avifResult avifParseMinimizedImageBox(avifMeta * meta, uint64_t rawOffset
meta->fromMiniBox = AVIF_TRUE;

uint32_t version;
AVIF_CHECKERR(avifROStreamReadBits(&s, &version, 2), AVIF_RESULT_BMFF_PARSE_FAILED); // bit(2) version;
AVIF_CHECKERR(avifROStreamReadBits(&s, &version, 2), AVIF_RESULT_BMFF_PARSE_FAILED); // bit(2) version = 0;
AVIF_CHECKERR(version == 0, AVIF_RESULT_BMFF_PARSE_FAILED);

// flags
Expand Down Expand Up @@ -3818,13 +3818,15 @@ static avifResult avifParseMinimizedImageBox(avifMeta * meta, uint64_t rawOffset
// Chunks
avifCodecConfigurationBox alphaItemCodecConfig = { 0 };
if (hasAlpha && alphaItemDataSize != 0 && alphaItemCodecConfigSize != 0) {
// 'av1C' always uses 4 bytes.
AVIF_CHECKERR(alphaItemCodecConfigSize == 4, AVIF_RESULT_BMFF_PARSE_FAILED);
AVIF_CHECKERR(avifParseCodecConfiguration(&s, &alphaItemCodecConfig, (const char *)codecConfigType, diag),
AVIF_RESULT_BMFF_PARSE_FAILED); // unsigned int(8) alpha_item_codec_config[alpha_item_codec_config_size];
}
// if (hdr_flag && gainmap_flag && gainmap_item_codec_config_size > 0)
// unsigned int(8) gainmap_item_codec_config[gainmap_item_codec_config_size];
avifCodecConfigurationBox mainItemCodecConfig = { 0 };
// 'av1C' always uses 4 bytes.
AVIF_CHECKERR(mainItemCodecConfigSize == 4, AVIF_RESULT_BMFF_PARSE_FAILED);
AVIF_CHECKERR(avifParseCodecConfiguration(&s, &mainItemCodecConfig, (const char *)codecConfigType, diag),
AVIF_RESULT_BMFF_PARSE_FAILED); // unsigned int(8) main_item_codec_config[main_item_codec_config_size];
Expand Down
6 changes: 3 additions & 3 deletions src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2462,14 +2462,14 @@ static avifResult avifEncoderWriteMiniBox(avifEncoder * encoder, avifRWStream *
const avifBool hasExplicitCodecTypes = AVIF_FALSE; // 'av01' and 'av1C' known from 'avif' minor_version field of FileTypeBox.

const uint32_t smallDimensionsFlag = image->width <= (1 << 7) && image->height <= (1 << 7);
const uint32_t codecConfigSize = 4; // 'av1C' always uses 4 bytes.
const uint32_t fewCodecConfigBytesFlag = codecConfigSize < (1 << 3); // 'av1C' always uses 4 bytes.
const uint32_t codecConfigSize = 4; // 'av1C' always uses 4 bytes.
const uint32_t fewCodecConfigBytesFlag = codecConfigSize < (1 << 3);
const uint32_t fewItemDataBytesFlag = colorData->size <= (1 << 15) && (!alphaData || alphaData->size < (1 << 15));
const uint32_t fewMetadataBytesFlag = image->icc.size <= (1 << 10) && image->exif.size <= (1 << 10) && image->xmp.size <= (1 << 10);

avifBoxMarker mini;
AVIF_CHECKRES(avifRWStreamWriteBox(s, "mini", AVIF_BOX_SIZE_TBD, &mini));
AVIF_CHECKRES(avifRWStreamWriteBits(s, 0, 2)); // bit(2) version;
AVIF_CHECKRES(avifRWStreamWriteBits(s, 0, 2)); // bit(2) version = 0;

// flags
AVIF_CHECKRES(avifRWStreamWriteBits(s, hasExplicitCodecTypes, 1)); // bit(1) explicit_codec_types_flag;
Expand Down

0 comments on commit 4f1acb6

Please sign in to comment.