Skip to content
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
42 changes: 25 additions & 17 deletions src/parsers/tiff/makernotes/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,24 @@ const BPLIST_MAGIC: &[u8] = b"bplist";
// Decoders for Apple MakerNote tag values. These convert numeric values to
// human-readable strings based on ExifTool's Apple.pm definitions.

// Decodes Apple HDR image type
// Values observed from various iPhone models
// Decodes Apple HDR image type (Apple.pm 0x000a HDRImageType).
//
// ExifTool 13.59 declares exactly two values here:
// 3 => 'HDR Image'
// 4 => 'Original Image'
// (its `2` is commented out as unidentified, seen on iPad mini 2).
//
// This table previously carried nine invented entries -- 0 "Off", 1 "HDR",
// 2 "HDR (Original)", 3 "Auto HDR", 4 "Smart HDR", 5-8 "Smart HDR 2".."5" --
// so a real iPhone file printed "Auto HDR" where ExifTool prints "HDR Image",
// and "Smart HDR" where ExifTool prints "Original Image". Wrong values under a
// real tag name do not crash and nothing downstream can tell, which is why
// AGENTS.md requires omitting rather than approximating. Unmapped values fall
// through to "Unknown (N)", matching ExifTool.
const_decoder! {
pub DECODE_HDR_TYPE, i16, [
(0, "Off"),
(1, "HDR"),
(2, "HDR (Original)"),
(3, "Auto HDR"),
(4, "Smart HDR"),
(5, "Smart HDR 2"),
(6, "Smart HDR 3"),
(7, "Smart HDR 4"),
(8, "Smart HDR 5"),
(3, "HDR Image"),
(4, "Original Image"),
]
}

Expand Down Expand Up @@ -811,10 +816,12 @@ mod tests {

#[test]
fn test_decode_hdr_type() {
assert_eq!(DECODE_HDR_TYPE.decode(0), "Off");
assert_eq!(DECODE_HDR_TYPE.decode(1), "HDR");
assert_eq!(DECODE_HDR_TYPE.decode(4), "Smart HDR");
assert_eq!(DECODE_HDR_TYPE.decode(8), "Smart HDR 5");
// ExifTool 13.59 Apple.pm 0x000a: the PrintConv has exactly these two.
assert_eq!(DECODE_HDR_TYPE.decode(3), "HDR Image");
assert_eq!(DECODE_HDR_TYPE.decode(4), "Original Image");
// Everything else is unmapped in ExifTool and must not be invented.
assert_eq!(DECODE_HDR_TYPE.decode(0), "Unknown (0)");
assert_eq!(DECODE_HDR_TYPE.decode(8), "Unknown (8)");
}

#[test]
Expand Down Expand Up @@ -910,7 +917,7 @@ mod tests {
// Create minimal IFD with one entry
data.extend_from_slice(&[0x01, 0x00]); // 1 entry

// HDR tag entry (tag=0x000A, type=3 (SHORT), count=1, value=4 (Smart HDR))
// HDR tag entry (tag=0x000A, type=3 (SHORT), count=1, value=4)
data.extend_from_slice(&[0x0A, 0x00]); // Tag
data.extend_from_slice(&[0x03, 0x00]); // Type: SHORT
data.extend_from_slice(&[0x01, 0x00, 0x00, 0x00]); // Count: 1
Expand All @@ -920,9 +927,10 @@ mod tests {
let result = parser.parse(&data, ByteOrder::LittleEndian, &mut tags);

assert!(result.is_ok());
// ExifTool 13.59 Apple.pm 0x000a: 4 => 'Original Image'.
assert_eq!(
tags.get("Apple:HDRImageType"),
Some(&"Smart HDR".to_string())
Some(&"Original Image".to_string())
);
}

Expand Down
12 changes: 8 additions & 4 deletions src/parsers/tiff/makernotes/registries/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const APPLE_SEMANTIC_STYLE_PRESET: u16 = 0x0042;
/// # Example
/// ```ignore
/// let registry = apple_registry();
/// let hdr_type = registry.decode_i16(0x000A, 4); // "Smart HDR"
/// let hdr_type = registry.decode_i16(0x000A, 4); // "Original Image"
/// ```
pub fn apple_registry() -> TagRegistry {
TagRegistry::new()
Expand Down Expand Up @@ -260,10 +260,14 @@ mod tests {

#[test]
fn test_hdr_type_decoding() {
// ExifTool 13.59 Apple.pm 0x000a HDRImageType PrintConv: 3 and 4 only.
let registry = apple_registry();
assert_eq!(registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 0), "Off");
assert_eq!(registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 4), "Smart HDR");
assert_eq!(registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 8), "Smart HDR 5");
assert_eq!(registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 3), "HDR Image");
assert_eq!(
registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 4),
"Original Image"
);
assert_eq!(registry.decode_i16(APPLE_HDR_IMAGE_TYPE, 0), "Unknown (0)");
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,11 @@ mod ape_integration_tests;
// data as expected behaviour. See the commit that removed them for the
// name-by-name evidence.

#[path = "integration/apple_makernotes_tests.rs"]
mod apple_makernotes_tests;

#[path = "integration/samsung_makernotes_tests.rs"]
mod samsung_makernotes_tests;

#[path = "forensic/mod.rs"]
mod forensic;
Loading
Loading