From 97287eb688e9479568a862111bf2d36f68c855a1 Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 3 Jan 2025 10:35:56 -0500 Subject: [PATCH 1/2] feat: Remove writing of native camera RAW formats from SDK Writers of native formats cannot be easily tested and are beyond the scope of the SDK. --- sdk/src/asset_handlers/tiff_io.rs | 16 +++++++++++++++- sdk/src/jumbf_io.rs | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sdk/src/asset_handlers/tiff_io.rs b/sdk/src/asset_handlers/tiff_io.rs index f281fa9a6..2d9811e67 100644 --- a/sdk/src/asset_handlers/tiff_io.rs +++ b/sdk/src/asset_handlers/tiff_io.rs @@ -68,6 +68,16 @@ static SUPPORTED_TYPES: [&str; 10] = [ "image/x-nikon-nef", ]; +// Writing native formats is beyond the scope of the SDK. +static SUPPORTED_WRITER_TYPES: [&str; 6] = [ + "tif", + "tiff", + "image/tiff", + "dng", + "image/dng", + "image/x-adobe-dng", +]; + // The type of an IFD entry #[derive(Debug, PartialEq)] enum IFDEntryType { @@ -1414,7 +1424,11 @@ impl AssetIO for TiffIO { } fn get_writer(&self, asset_type: &str) -> Option> { - Some(Box::new(TiffIO::new(asset_type))) + if SUPPORTED_WRITER_TYPES.contains(&asset_type) { + Some(Box::new(TiffIO::new(asset_type))) + } else { + None + } } fn remote_ref_writer_ref(&self) -> Option<&dyn RemoteRefEmbed> { diff --git a/sdk/src/jumbf_io.rs b/sdk/src/jumbf_io.rs index baaf7f12f..d818f8fed 100644 --- a/sdk/src/jumbf_io.rs +++ b/sdk/src/jumbf_io.rs @@ -421,6 +421,10 @@ pub mod tests { assert!(get_caiwriter_handler(supported_type).is_some()); } } + + // Writing native formats is beyond the scope of the SDK. + assert!(get_caiwriter_handler("nef").is_none()); + assert!(get_caiwriter_handler("arw").is_none()); } #[test] From 2d56cac68e3159238f556e3fe8fb1913ccc5dbdd Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 3 Jan 2025 11:57:00 -0500 Subject: [PATCH 2/2] Add specific test for TIFF CAI writer handler. --- sdk/src/jumbf_io.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sdk/src/jumbf_io.rs b/sdk/src/jumbf_io.rs index d818f8fed..25e7448b8 100644 --- a/sdk/src/jumbf_io.rs +++ b/sdk/src/jumbf_io.rs @@ -421,10 +421,28 @@ pub mod tests { assert!(get_caiwriter_handler(supported_type).is_some()); } } + } + #[test] + fn test_get_writer_tiff() { + let h = TiffIO::new(""); // Writing native formats is beyond the scope of the SDK. - assert!(get_caiwriter_handler("nef").is_none()); - assert!(get_caiwriter_handler("arw").is_none()); + // Only the following are supported. + let supported_tiff_types: [&str; 6] = [ + "tif", + "tiff", + "image/tiff", + "dng", + "image/dng", + "image/x-adobe-dng", + ]; + for tiff_type in h.supported_types() { + if supported_tiff_types.contains(tiff_type) { + assert!(get_caiwriter_handler(tiff_type).is_some()); + } else { + assert!(get_caiwriter_handler(tiff_type).is_none()); + } + } } #[test]