Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When converting a jpeg-r file with ICC, copy it to altICC as well. #1878

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,13 @@ static avifBool avifJPEGReadInternal(FILE * f,
gainMap->altDepth = 8;
gainMap->altPlaneCount =
(avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV400 && gainMap->image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) ? 1 : 3;
if (avif->icc.size > 0) {
// The base image's ICC should also apply to the alternage image.
if (avifRWDataSet(&gainMap->altICC, avif->icc.data, avif->icc.size) != AVIF_RESULT_OK) {
fprintf(stderr, "Setting gain map ICC profile failed: out of memory\n");
goto cleanup;
}
}
avif->gainMap = gainMap;
} else {
avifGainMapDestroy(gainMap);
Expand Down
5 changes: 5 additions & 0 deletions apps/shared/avifutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ static void avifImageDumpInternal(const avifImage * avif,
printf(" * Color Primaries: %u\n", avif->gainMap->altColorPrimaries);
printf(" * Transfer Char. : %u\n", avif->gainMap->altTransferCharacteristics);
printf(" * Matrix Coeffs. : %u\n", avif->gainMap->altMatrixCoefficients);
if (avif->gainMap->altICC.size != 0) {
printf(" * ICC Profile : Present (%" AVIF_FMT_ZU " bytes)\n", avif->gainMap->altICC.size);
} else {
printf(" * ICC Profile : Absent\n");
}
if (avif->gainMap->altDepth) {
printf(" * Bit Depth : %u\n", avif->gainMap->altDepth);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,20 @@ a hex editor to make the MPF metadata big endian, as signaled by the four bytes
| 33507 | 0xffe1 APP1 | 571 | `http://ns.adobe.com/xap/1.0/.<?x` |
| | | | ... |

### File [paris_exif_xmp_icc_gainmap_bigendian.jpg](paris_exif_xmp_icc_gainmap_bigendian.jpg)

![](paris_exif_xmp_icc_gainmap_bigendian.jpg)

License: [same as libavif](https://github.com/AOMediaCodec/libavif/blob/main/LICENSE)

Source: same as paris_exif_xmp_gainmap_bigendian.jpg but with a DCI-P3 ICC profile added
using exiftool:

```
cp paris_exif_xmp_gainmap_bigendian.jpg paris_exif_xmp_icc_gainmap_bigendian.jpg
exiftool -icc_profile -b path/to/some_image_with_a_p3_profile.jpg > p3.icc
exiftool "-icc_profile<=p3.icc" paris_exif_xmp_icc_gainmap_bigendian.jpg
```

### File [color_grid_gainmap_different_grid.avif](color_grid_gainmap_different_grid.avif)

Expand Down
120 changes: 120 additions & 0 deletions tests/data/goldens/paris_exif_xmp_icc_gainmap_bigendian.jpg.avif.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ISOBaseMediaFileTrace>
<!--MP4Box dump trace-->
<IsoMediaFile xmlns="urn:mpeg:isobmff:schema:file:2016" Name="paris_exif_xmp_icc_gainmap_bigendian.jpg.avif">
<FileTypeBox Size="32" Type="ftyp" Specification="p12" Container="file otyp" MajorBrand="avif" MinorVersion="0">
<BrandEntry AlternateBrand="avif"/>
<BrandEntry AlternateBrand="mif1"/>
<BrandEntry AlternateBrand="miaf"/>
<BrandEntry AlternateBrand="MA1B"/>
</FileTypeBox>
<MetaBox Size="1121" Type="meta" Version="0" Flags="0" Specification="p12" Container="file moov trak moof traf udta" >
<HandlerBox Size="40" Type="hdlr" Version="0" Flags="0" Specification="p12" Container="mdia meta minf" hdlrType="pict" Name="libavif" reserved1="0" reserved2="data:application/octet-string,000000000000000000000000">
</HandlerBox>
<PrimaryItemBox Size="14" Type="pitm" Version="0" Flags="0" Specification="p12" Container="meta" item_ID="1">
</PrimaryItemBox>
<ItemLocationBox Size="86" Type="iloc" Version="0" Flags="0" Specification="p12" Container="meta" offset_size="4" length_size="4" base_offset_size="0" index_size="0">
<ItemLocationEntry item_ID="1" data_reference_index="0" base_offset="0" construction_method="0">
<ItemExtentEntry extent_offset="REDACTED" extent_length="REDACTED" extent_index="0" />
</ItemLocationEntry>
<ItemLocationEntry item_ID="2" data_reference_index="0" base_offset="0" construction_method="0">
<ItemExtentEntry extent_offset="REDACTED" extent_length="REDACTED" extent_index="0" />
</ItemLocationEntry>
<ItemLocationEntry item_ID="3" data_reference_index="0" base_offset="0" construction_method="0">
<ItemExtentEntry extent_offset="REDACTED" extent_length="REDACTED" extent_index="0" />
</ItemLocationEntry>
<ItemLocationEntry item_ID="4" data_reference_index="0" base_offset="0" construction_method="0">
<ItemExtentEntry extent_offset="REDACTED" extent_length="REDACTED" extent_index="0" />
</ItemLocationEntry>
<ItemLocationEntry item_ID="5" data_reference_index="0" base_offset="0" construction_method="0">
<ItemExtentEntry extent_offset="REDACTED" extent_length="REDACTED" extent_index="0" />
</ItemLocationEntry>
</ItemLocationBox>
<ItemInfoBox Size="159" Type="iinf" Version="0" Flags="0" Specification="p12" Container="meta" >
<ItemInfoEntryBox Size="26" Type="infe" Version="2" Flags="0" Specification="p12" Container="iinf" item_ID="1" item_protection_index="0" item_name="Color" content_type="(null)" content_encoding="(null)" item_type="av01">
</ItemInfoEntryBox>
<ItemInfoEntryBox Size="25" Type="infe" Version="2" Flags="0" Specification="p12" Container="iinf" item_ID="2" item_protection_index="0" item_name="GMap" content_type="(null)" content_encoding="(null)" item_type="tmap">
</ItemInfoEntryBox>
<ItemInfoEntryBox Size="25" Type="infe" Version="2" Flags="1" Specification="p12" Container="iinf" item_ID="3" item_protection_index="0" item_name="GMap" content_type="(null)" content_encoding="(null)" item_type="av01">
</ItemInfoEntryBox>
<ItemInfoEntryBox Size="25" Type="infe" Version="2" Flags="0" Specification="p12" Container="iinf" item_ID="4" item_protection_index="0" item_name="Exif" content_type="(null)" content_encoding="(null)" item_type="Exif">
</ItemInfoEntryBox>
<ItemInfoEntryBox Size="44" Type="infe" Version="2" Flags="0" Specification="p12" Container="iinf" item_ID="5" item_protection_index="0" item_name="XMP" content_type="application/rdf+xml" content_encoding="(null)" item_type="mime">
</ItemInfoEntryBox>
</ItemInfoBox>
<ItemReferenceBox Size="56" Type="iref" Version="0" Flags="0" Specification="p12" Container="meta" >
<ItemReferenceBox Size="16" Type="dimg" Specification="p12" Container="iref" from_item_id="2">
<ItemReferenceBoxEntry ItemID="1"/>
<ItemReferenceBoxEntry ItemID="3"/>
</ItemReferenceBox>
<ItemReferenceBox Size="14" Type="cdsc" Specification="p12" Container="iref" from_item_id="4">
<ItemReferenceBoxEntry ItemID="1"/>
</ItemReferenceBox>
<ItemReferenceBox Size="14" Type="cdsc" Specification="p12" Container="iref" from_item_id="5">
<ItemReferenceBoxEntry ItemID="1"/>
</ItemReferenceBox>
</ItemReferenceBox>
<ItemPropertiesBox Size="718" Type="iprp" Specification="iff" Container="meta" >
<ItemPropertyContainerBox Size="672" Type="ipco" Specification="iff" Container="iprp" >
<ImageSpatialExtentsPropertyBox Size="20" Type="ispe" Version="0" Flags="0" Specification="iff" Container="ipco" image_width="403" image_height="302">
</ImageSpatialExtentsPropertyBox>
<PixelInformationPropertyBox Size="16" Type="pixi" Version="0" Flags="0" Specification="iff" Container="ipco" >
<BitPerChannel bits_per_channel="8"/>
<BitPerChannel bits_per_channel="8"/>
<BitPerChannel bits_per_channel="8"/>
</PixelInformationPropertyBox>
<AV1ConfigurationBox>
<AV1Config version="1" profile="0" level_idx0="0" tier="0" high_bitdepth="0" twelve_bit="0" monochrome="0" chroma_subsampling_x="1" chroma_subsampling_y="1" chroma_sample_position="0" initial_presentation_delay="1" OBUs_count="0">
</AV1Config>
</AV1ConfigurationBox>
<ColourInformationBox Size="532" Type="colr" Specification="iff" Container="video_sample_entry ipco encv resv" colour_type="prof">
<profile><![CDATA[AAACCAAAAAAEMAAAbW50clJHQiBYWVogB+AAAQABAAAAAAAAYWNzcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAPbWAAEAAAAA0y0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJZGVzYwAAAPAAAABkclhZWgAAAVQAAAAUZ1hZWgAAAWgAAAAUYlhZWgAAAXwAAAAUd3RwdAAAAZAAAAAUclRSQwAAAaQAAAAoZ1RSQwAAAaQAAAAoYlRSQwAAAaQAAAAoY3BydAAAAcwAAAA8bWx1YwAAAAAAAAABAAAADGVuVVMAAABGAAAAHABEAGkAcwBwAGwAYQB5ACAAUAAzACAARwBhAG0AdQB0ACAAdwBpAHQAaAAgAHMAUgBHAEIAIABUAHIAYQBuAHMAZgBlAHIAAFhZWiAAAAAAAACD3wAAPb////+7WFlaIAAAAAAAAEq/AACxNwAACrlYWVogAAAAAAAAKDgAABELAADIuVhZWiAAAAAAAAD21gABAAAAANMtcGFyYQAAAAAABAAAAAJmZgAA8qcAAA1ZAAAT0AAAClsAAAAAAAAAAG1sdWMAAAAAAAAAAQAAAAxlblVTAAAAIAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAwADEANg==]]></profile></ColourInformationBox>
<ColourInformationBox Size="19" Type="colr" Specification="iff" Container="video_sample_entry ipco encv resv" colour_type="nclx" colour_primaries="2" transfer_characteristics="2" matrix_coefficients="6" full_range_flag="1">
</ColourInformationBox>
<ColourInformationBox Size="19" Type="colr" Specification="iff" Container="video_sample_entry ipco encv resv" colour_type="nclx" colour_primaries="2" transfer_characteristics="16" matrix_coefficients="6" full_range_flag="1">
</ColourInformationBox>
<ImageSpatialExtentsPropertyBox Size="20" Type="ispe" Version="0" Flags="0" Specification="iff" Container="ipco" image_width="512" image_height="384">
</ImageSpatialExtentsPropertyBox>
<PixelInformationPropertyBox Size="14" Type="pixi" Version="0" Flags="0" Specification="iff" Container="ipco" >
<BitPerChannel bits_per_channel="8"/>
</PixelInformationPropertyBox>
<AV1ConfigurationBox>
<AV1Config version="1" profile="0" level_idx0="1" tier="0" high_bitdepth="0" twelve_bit="0" monochrome="1" chroma_subsampling_x="1" chroma_subsampling_y="1" chroma_sample_position="0" initial_presentation_delay="1" OBUs_count="0">
</AV1Config>
</AV1ConfigurationBox>
</ItemPropertyContainerBox>
<ItemPropertyAssociationBox Size="38" Type="ipma" Version="0" Flags="0" Specification="iff" Container="iprp" entry_count="3">
<AssociationEntry item_ID="1" association_count="5">
<Property index="1" essential="0"/>
<Property index="2" essential="0"/>
<Property index="3" essential="1"/>
<Property index="4" essential="0"/>
<Property index="5" essential="0"/>
</AssociationEntry>
<AssociationEntry item_ID="2" association_count="4">
<Property index="1" essential="0"/>
<Property index="2" essential="0"/>
<Property index="4" essential="0"/>
<Property index="6" essential="0"/>
</AssociationEntry>
<AssociationEntry item_ID="3" association_count="4">
<Property index="7" essential="0"/>
<Property index="8" essential="0"/>
<Property index="9" essential="1"/>
<Property index="5" essential="0"/>
</AssociationEntry>
</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">
<EntityToGroupTypeBoxEntry EntityID="2"/>
<EntityToGroupTypeBoxEntry EntityID="1"/>
</EntityToGroupTypeBox>
</GroupListBox>
</MetaBox>
<MediaDataBox Size="REDACTED" Type="mdat" Specification="p12" Container="file" dataSize="REDACTED">
</MediaDataBox>
</IsoMediaFile>
<Tracks>
</Tracks>
</ISOBaseMediaFileTrace>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to README.md?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/test_cmd_enc_gainmap_boxes_golden.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# All .avif files created here will become test cases.
encode_test_files() {
# Image with a gain map.
for f in "paris_exif_xmp_gainmap_bigendian.jpg" "paris_exif_xmp_gainmap_littleendian.jpg"; do
for f in "paris_exif_xmp_gainmap_bigendian.jpg" \
"paris_exif_xmp_icc_gainmap_bigendian.jpg" \
"paris_exif_xmp_gainmap_littleendian.jpg"; do
"${AVIFENC}" -s 9 "${TESTDATA_DIR}/$f" -o "$f.avif"
done

Expand Down
Loading