Skip to content
Merged
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions apps/shared/avifexif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I verified the bug fix by comparing this function with the corresponding code in Chrome. You can skip the following details.

Details:

In Chrome (third_party/blink/renderer/platform/image-decoders/avif/crabbyavif_image_decoder.cc), this operation is implemented as a table lookup (I replaced the symbolic constants with numeric values in the lookup table):

  // |angle| * 90 specifies the angle of anti-clockwise rotation in degrees.
  // Legal values: [0-3].
  int angle = 0;
  if (container->transformFlags & crabbyavif::AVIF_TRANSFORM_IROT) {
    angle = container->irot.angle;
    CHECK_LT(angle, 4);
  }
  // |axis| specifies how the mirroring is performed.
  //   -1: No mirroring.
  //    0: The top and bottom parts of the image are exchanged.
  //    1: The left and right parts of the image are exchanged.
  int axis = -1;
  if (container->transformFlags & crabbyavif::AVIF_TRANSFORM_IMIR) {
    axis = container->imir.axis;
    CHECK_LT(axis, 2);
  }
  // MIAF Section 7.3.6.7 (Clean aperture, rotation and mirror) says:
  //   These properties, if used, shall be indicated to be applied in the
  //   following order: clean aperture first, then rotation, then mirror.
  //
  // In the kAxisAngleToOrientation array, the first dimension is axis (with an
  // offset of 1). The second dimension is angle.
  constexpr std::array<std::array<ImageOrientationEnum, 4>, 3>
      kAxisAngleToOrientation = {{
          // No mirroring.
          {1, 8, 3, 6},
          // Top-to-bottom mirroring. Change Top<->Bottom in the first row.
          {4, 5, 2, 7},
          // Left-to-right mirroring. Change Left<->Right in the first row.
          {2, 7, 4, 5},
      }};
  orientation_ = kAxisAngleToOrientation[axis + 1][angle];

To match the code here, we need to read each column in Chrome's lookup table from the bottom up. For example, the second column read from the bottom up is 7, 5, 8. This should match the first outermost if block in this function. This confirms the last entry should be 8, not 6.

Similarly, the third column read from the bottom up is 4, 2, 3. This matches the second outermost if block in this function.

The fourth column read from the bottom up is 5, 7, 6. This matches the new code in the third outermost if block in this function.

Finally, the first column read from the bottom up is 2, 4, 1. This matches the last outermost if block and the final return statement in this function.

}
if (image->transformFlags & AVIF_TRANSFORM_IMIR) {
if (image->imir.axis) {
Expand Down
Loading