Skip to content

Commit 47b1ed6

Browse files
committed
Update imir implementation to conform with HEIF Draft Amendment 2
1 parent fca4964 commit 47b1ed6

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

mp4parse/src/lib.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,29 +2594,45 @@ fn read_irot<T: Read>(src: &mut BMFFBox<T>) -> Result<ImageRotation> {
25942594
Ok(image_rotation)
25952595
}
25962596

2597-
#[repr(C)]
2598-
#[derive(Debug)]
25992597
/// The axis about which the image is mirrored (opposite of flip)
26002598
/// Visualized in terms of starting with (⥠) UPWARDS HARPOON WITH BARB LEFT FROM BAR
26012599
/// similar to a DIGIT ONE (1)
2600+
#[repr(C)]
2601+
#[derive(Debug)]
26022602
pub enum ImageMirror {
2603-
/// left and right sides swapped
2604-
/// ⥜ UPWARDS HARPOON WITH BARB RIGHT FROM BAR
2605-
V,
2606-
/// top and bottom halves swapped
2603+
/// top and bottom parts exchanged
26072604
/// ⥡ DOWNWARDS HARPOON WITH BARB LEFT FROM BAR
2608-
H,
2605+
TopBottom,
2606+
/// left and right parts exchanged
2607+
/// ⥜ UPWARDS HARPOON WITH BARB RIGHT FROM BAR
2608+
LeftRight,
26092609
}
26102610

26112611
/// Parse image mirroring box
2612-
/// See HEIF (ISO 23008-12:2017) § 6.5.12
2612+
/// See HEIF (ISO 23008-12:2017) § 6.5.12<br />
2613+
/// Note: [ISO/IEC 23008-12:2017/DAmd 2](https://www.iso.org/standard/81688.html)
2614+
/// reverses the interpretation of the 'imir' box in § 6.5.12.3:
2615+
/// > `axis` specifies a vertical (`axis` = 0) or horizontal (`axis` = 1) axis
2616+
/// > for the mirroring operation.
2617+
///
2618+
/// is replaced with:
2619+
/// > `mode` specifies how the mirroring is performed: 0 indicates that the top
2620+
/// > and bottom parts of the image are exchanged; 1 specifies that the left and
2621+
/// > right parts are exchanged.
2622+
/// >
2623+
/// > NOTE: In Exif, orientation tag can be used to signal mirroring operations.
2624+
/// > Exif orientation tag 4 corresponds to `mode` = 0 of `ImageMirror`, and
2625+
/// > Exif orientation tag 2 corresponds to `mode` = 1 accordingly.
2626+
///
2627+
/// This implementation conforms to the text in Draft Amendment 2, which is the
2628+
/// opposite of the published standard as of 4 June 2021.
26132629
fn read_imir<T: Read>(src: &mut BMFFBox<T>) -> Result<ImageMirror> {
26142630
let imir = src.read_into_try_vec()?;
26152631
let mut imir = BitReader::new(&imir);
26162632
let _reserved = imir.read_u8(7)?;
26172633
let image_mirror = match imir.read_u8(1)? {
2618-
0 => ImageMirror::V,
2619-
1 => ImageMirror::H,
2634+
0 => ImageMirror::TopBottom,
2635+
1 => ImageMirror::LeftRight,
26202636
_ => unreachable!(),
26212637
};
26222638

0 commit comments

Comments
 (0)