diff --git a/CHANGELOG.md b/CHANGELOG.md index 677d0fda1c..d784b6d5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ The changes are relative to the previous release, unless the baseline is specifi AVIF_PIXEL_FORMAT_YUV400 to be AV1 spec compatible. * Ignore tmap items not present in `grpl` box * Update libyuv.cmd: dc47c71b3 (1907) +* Fix wrong Exif orientation set in JPEG or PNG output by avifdec when the input + AVIF file has an ImageRotation property with angle set to 1 or 3, has no + ImageMirror property, and carries an Exif chunk. Note that Exif orientation is + usually ignored in PNG files, so this mainly impacts JPEG files. ## [1.2.1] - 2025-03-17 diff --git a/apps/shared/avifexif.c b/apps/shared/avifexif.c index 13fe8bfc73..3976276a94 100644 --- a/apps/shared/avifexif.c +++ b/apps/shared/avifexif.c @@ -13,7 +13,7 @@ uint8_t avifImageGetExifOrientationFromIrotImir(const avifImage * image) } return 5; // 90 degrees anti-clockwise then swap top and bottom. } - return 6; // 90 degrees anti-clockwise. + return 8; // 90 degrees anti-clockwise. } if ((image->transformFlags & AVIF_TRANSFORM_IROT) && (image->irot.angle == 2)) { if (image->transformFlags & AVIF_TRANSFORM_IMIR) { @@ -31,7 +31,7 @@ uint8_t avifImageGetExifOrientationFromIrotImir(const avifImage * image) } return 7; // 270 degrees anti-clockwise then swap top and bottom. } - return 8; // 270 degrees anti-clockwise. + return 6; // 270 degrees anti-clockwise. } if (image->transformFlags & AVIF_TRANSFORM_IMIR) { if (image->imir.axis) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3c9892c9c4..1a5945a377 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -126,7 +126,7 @@ if(AVIF_GTEST) add_avif_gtest_with_data(avifiostatstest) add_avif_gtest_with_data(avifkeyframetest) add_avif_gtest_with_data(aviflosslesstest) - add_avif_gtest_with_data(avifmetadatatest) + add_avif_internal_gtest_with_data(avifmetadatatest) if(AVIF_ENABLE_EXPERIMENTAL_MINI) add_avif_gtest(avifminitest) diff --git a/tests/gtest/avifmetadatatest.cc b/tests/gtest/avifmetadatatest.cc index e7914bf917..302c446436 100644 --- a/tests/gtest/avifmetadatatest.cc +++ b/tests/gtest/avifmetadatatest.cc @@ -9,6 +9,8 @@ #include "avif/avif.h" #include "avif/avif_cxx.h" +#include "avif/internal.h" +#include "avifexif.h" #include "avifjpeg.h" #include "avifpng.h" #include "aviftest_helpers.h" @@ -284,6 +286,22 @@ TEST(MetadataTest, ExifOrientation) { EXPECT_EQ(image->width, temp_image->width /* should be height here */); } +TEST(MetadataTest, AllExifOrientations) { + const ImagePtr image = + testutil::ReadImage(data_path, "paris_exif_orientation_5.jpg"); + ASSERT_NE(image, nullptr); + image->transformFlags = AVIF_TRANSFORM_NONE; + for (uint8_t orientation = 1; orientation <= 8; ++orientation) { + // Check roundtrip. + ASSERT_EQ(avifSetExifOrientation(&image->exif, orientation), + AVIF_RESULT_OK); + ASSERT_EQ(avifImageExtractExifOrientationToIrotImir(image.get()), + AVIF_RESULT_OK); + ASSERT_EQ(avifImageGetExifOrientationFromIrotImir(image.get()), + orientation); + } +} + TEST(MetadataTest, ExifOrientationAndForcedImir) { const ImagePtr image = testutil::ReadImage(data_path, "paris_exif_orientation_5.jpg");