Skip to content

Commit

Permalink
Fix group id conflicting with item id. #2391 (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryla-uc authored Aug 19, 2024
1 parent 4d0f851 commit a0f3ed1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -2272,15 +2272,15 @@ static avifResult avifEncoderWriteMediaDataBox(avifEncoder * encoder,
return AVIF_RESULT_OK;
}

static avifResult avifWriteAltrGroup(avifRWStream * s, const avifEncoderItemIdArray * itemIDs)
static avifResult avifWriteAltrGroup(avifRWStream * s, uint32_t groupID, const avifEncoderItemIdArray * itemIDs)
{
avifBoxMarker grpl;
AVIF_CHECKRES(avifRWStreamWriteBox(s, "grpl", AVIF_BOX_SIZE_TBD, &grpl));

avifBoxMarker altr;
AVIF_CHECKRES(avifRWStreamWriteFullBox(s, "altr", AVIF_BOX_SIZE_TBD, 0, 0, &altr));

AVIF_CHECKRES(avifRWStreamWriteU32(s, 1)); // unsigned int(32) group_id;
AVIF_CHECKRES(avifRWStreamWriteU32(s, groupID)); // unsigned int(32) group_id;
AVIF_CHECKRES(avifRWStreamWriteU32(s, (uint32_t)itemIDs->count)); // unsigned int(32) num_entities_in_group;
for (uint32_t i = 0; i < itemIDs->count; ++i) {
AVIF_CHECKRES(avifRWStreamWriteU32(s, (uint32_t)itemIDs->item_id[i])); // unsigned int(32) entity_id;
Expand Down Expand Up @@ -3294,7 +3294,15 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output)
// Write grpl/altr box

if (encoder->data->alternativeItemIDs.count) {
AVIF_CHECKRES(avifWriteAltrGroup(&s, &encoder->data->alternativeItemIDs));
// Section 8.18.3.3 of ISO 14496-12 (ISOBMFF) says:
// group_id is a non-negative integer assigned to the particular grouping that shall not be equal to any
// group_id value of any other EntityToGroupBox, any item_ID value of the hierarchy level
// (file, movie. or track) that contains the GroupsListBox, or any track_ID value (when the
// GroupsListBox is contained in the file level).
AVIF_ASSERT_OR_RETURN(encoder->data->lastItemID < UINT16_MAX);
++encoder->data->lastItemID;
const uint32_t groupID = encoder->data->lastItemID;
AVIF_CHECKRES(avifWriteAltrGroup(&s, groupID, &encoder->data->alternativeItemIDs));
}

// -----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</ItemPropertyAssociationBox>
</ItemPropertiesBox>
<GroupListBox Size="36" Type="grpl" Specification="iff" Container="meta" >
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="1">
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="6">
<EntityToGroupTypeBoxEntry EntityID="2"/>
<EntityToGroupTypeBoxEntry EntityID="1"/>
</EntityToGroupTypeBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</ItemPropertyAssociationBox>
</ItemPropertiesBox>
<GroupListBox Size="36" Type="grpl" Specification="iff" Container="meta" >
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="1">
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="6">
<EntityToGroupTypeBoxEntry EntityID="2"/>
<EntityToGroupTypeBoxEntry EntityID="1"/>
</EntityToGroupTypeBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</ItemPropertyAssociationBox>
</ItemPropertiesBox>
<GroupListBox Size="36" Type="grpl" Specification="iff" Container="meta" >
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="1">
<EntityToGroupTypeBox Size="28" Type="altr" Version="0" Flags="0" Specification="iff" Container="grpl" group_id="6">
<EntityToGroupTypeBoxEntry EntityID="2"/>
<EntityToGroupTypeBoxEntry EntityID="1"/>
</EntityToGroupTypeBox>
Expand Down
Binary file modified tests/data/seine_hdr_gainmap_small_srgb.avif
Binary file not shown.
Binary file modified tests/data/seine_hdr_gainmap_srgb.avif
Binary file not shown.
Binary file modified tests/data/seine_sdr_gainmap_big_srgb.avif
Binary file not shown.
Binary file modified tests/data/seine_sdr_gainmap_srgb.avif
Binary file not shown.

0 comments on commit a0f3ed1

Please sign in to comment.