diff --git a/autotests/read/heif/rotated090.heif b/autotests/read/heif/rotated090.heif new file mode 100644 index 0000000..428c956 Binary files /dev/null and b/autotests/read/heif/rotated090.heif differ diff --git a/autotests/read/heif/rotated090.png b/autotests/read/heif/rotated090.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated090.png differ diff --git a/autotests/read/heif/rotated090_left-to-right.heif b/autotests/read/heif/rotated090_left-to-right.heif new file mode 100644 index 0000000..9730c66 Binary files /dev/null and b/autotests/read/heif/rotated090_left-to-right.heif differ diff --git a/autotests/read/heif/rotated090_left-to-right.png b/autotests/read/heif/rotated090_left-to-right.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated090_left-to-right.png differ diff --git a/autotests/read/heif/rotated090_top-to-bottom.heif b/autotests/read/heif/rotated090_top-to-bottom.heif new file mode 100644 index 0000000..f935db4 Binary files /dev/null and b/autotests/read/heif/rotated090_top-to-bottom.heif differ diff --git a/autotests/read/heif/rotated090_top-to-bottom.png b/autotests/read/heif/rotated090_top-to-bottom.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated090_top-to-bottom.png differ diff --git a/autotests/read/heif/rotated180.heif b/autotests/read/heif/rotated180.heif new file mode 100644 index 0000000..9d89960 Binary files /dev/null and b/autotests/read/heif/rotated180.heif differ diff --git a/autotests/read/heif/rotated180.png b/autotests/read/heif/rotated180.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated180.png differ diff --git a/autotests/read/heif/rotated180_left-to-right.heif b/autotests/read/heif/rotated180_left-to-right.heif new file mode 100644 index 0000000..08a495f Binary files /dev/null and b/autotests/read/heif/rotated180_left-to-right.heif differ diff --git a/autotests/read/heif/rotated180_left-to-right.png b/autotests/read/heif/rotated180_left-to-right.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated180_left-to-right.png differ diff --git a/autotests/read/heif/rotated180_top-to-bottom.heif b/autotests/read/heif/rotated180_top-to-bottom.heif new file mode 100644 index 0000000..70c4fdb Binary files /dev/null and b/autotests/read/heif/rotated180_top-to-bottom.heif differ diff --git a/autotests/read/heif/rotated180_top-to-bottom.png b/autotests/read/heif/rotated180_top-to-bottom.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated180_top-to-bottom.png differ diff --git a/autotests/read/heif/rotated270.heif b/autotests/read/heif/rotated270.heif new file mode 100644 index 0000000..c93e65e Binary files /dev/null and b/autotests/read/heif/rotated270.heif differ diff --git a/autotests/read/heif/rotated270.png b/autotests/read/heif/rotated270.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated270.png differ diff --git a/autotests/read/heif/rotated270_left-to-right.heif b/autotests/read/heif/rotated270_left-to-right.heif new file mode 100644 index 0000000..192b3b5 Binary files /dev/null and b/autotests/read/heif/rotated270_left-to-right.heif differ diff --git a/autotests/read/heif/rotated270_left-to-right.png b/autotests/read/heif/rotated270_left-to-right.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated270_left-to-right.png differ diff --git a/autotests/read/heif/rotated270_top-to-bottom.heif b/autotests/read/heif/rotated270_top-to-bottom.heif new file mode 100644 index 0000000..46df770 Binary files /dev/null and b/autotests/read/heif/rotated270_top-to-bottom.heif differ diff --git a/autotests/read/heif/rotated270_top-to-bottom.png b/autotests/read/heif/rotated270_top-to-bottom.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/rotated270_top-to-bottom.png differ diff --git a/autotests/read/heif/unrotated.heif b/autotests/read/heif/unrotated.heif new file mode 100644 index 0000000..2fdfe17 Binary files /dev/null and b/autotests/read/heif/unrotated.heif differ diff --git a/autotests/read/heif/unrotated.png b/autotests/read/heif/unrotated.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/unrotated.png differ diff --git a/autotests/read/heif/unrotated_left-to-right.heif b/autotests/read/heif/unrotated_left-to-right.heif new file mode 100644 index 0000000..b936974 Binary files /dev/null and b/autotests/read/heif/unrotated_left-to-right.heif differ diff --git a/autotests/read/heif/unrotated_left-to-right.png b/autotests/read/heif/unrotated_left-to-right.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/unrotated_left-to-right.png differ diff --git a/autotests/read/heif/unrotated_top-to-bottom.heif b/autotests/read/heif/unrotated_top-to-bottom.heif new file mode 100644 index 0000000..d01ce97 Binary files /dev/null and b/autotests/read/heif/unrotated_top-to-bottom.heif differ diff --git a/autotests/read/heif/unrotated_top-to-bottom.png b/autotests/read/heif/unrotated_top-to-bottom.png new file mode 100644 index 0000000..be62095 Binary files /dev/null and b/autotests/read/heif/unrotated_top-to-bottom.png differ diff --git a/src/imageformats/heif.cpp b/src/imageformats/heif.cpp index 41e7559..191fa95 100644 --- a/src/imageformats/heif.cpp +++ b/src/imageformats/heif.cpp @@ -608,22 +608,67 @@ bool HEIFHandler::read_orientation_helper(void *heif_handle, const void *heif_ct if (rotation_ccw == -1 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_invalid) { m_orientation = 0; - } else if (rotation_ccw == 0 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_invalid) { - m_orientation = 1; - } else if (rotation_ccw <= 0 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal) { - m_orientation = 2; - } else if (rotation_ccw == 180 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_invalid) { - m_orientation = 3; - } else if (rotation_ccw <= 0 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_vertical) { - m_orientation = 4; - } else if (rotation_ccw == 270 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal) { - m_orientation = 5; - } else if (rotation_ccw == 270 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_invalid) { - m_orientation = 6; - } else if (rotation_ccw == 270 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_vertical) { - m_orientation = 7; - } else if (rotation_ccw == 90 && mirror == heif_transform_mirror_direction::heif_transform_mirror_direction_invalid) { - m_orientation = 8; + return true; + } + + // The rotation is applied first, then the mirroring (the order required by MIAF) + switch (rotation_ccw) { + case -1: + case 0: + switch (mirror) { + case heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal: + m_orientation = 2; + break; + case heif_transform_mirror_direction::heif_transform_mirror_direction_vertical: + m_orientation = 4; + break; + default: + m_orientation = 1; + break; + } + break; + case 90: + switch (mirror) { + case heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal: + m_orientation = 7; + break; + case heif_transform_mirror_direction::heif_transform_mirror_direction_vertical: + m_orientation = 5; + break; + default: + m_orientation = 8; + break; + } + break; + case 180: + switch (mirror) { + case heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal: + m_orientation = 4; + break; + case heif_transform_mirror_direction::heif_transform_mirror_direction_vertical: + m_orientation = 2; + break; + default: + m_orientation = 3; + break; + } + break; + case 270: + switch (mirror) { + case heif_transform_mirror_direction::heif_transform_mirror_direction_horizontal: + m_orientation = 5; + break; + case heif_transform_mirror_direction::heif_transform_mirror_direction_vertical: + m_orientation = 7; + break; + default: + m_orientation = 6; + break; + } + break; + default: + // let libheif apply the transformations + return false; } return true;