mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
fix(io): a layered TIFF export warns that retained EXIF will be dropped (#1545)
A TIFF export with --tiff-layers reported "EXIF not supported; it will be dropped" even though the file kept the tags. export_layered puts EXIF into the Photoshop image resources as 1058, which the TIFF writer emits as tag 34377 and the importer reads back, so reopening the file restored the original tags. ExportResult.warnings is documented as notes about what an export will lose, so the message was an incorrect loss report for an export that loses nothing. The TIFF codec has no EXIF directory, so the second copy handed to it in meta.exif was never written; it only existed to make the codec warn. That copy is gone, and with it the false warning. The flat-TIFF path still hands the codec the tags, still drops them, and still says so. The test is the issue's own claim checked in both directions: a layered export reports no EXIF loss AND the Artist tag survives the round trip, so the missing warning reflects a real absence of loss rather than a silenced one; a flat export is the control and keeps warning. It fails on the exact reported message before this change. Co-authored-by: Space Bunny Free <[email protected]>
This commit is contained in:
1 parent
b693d690e1
commit
6ea2f563e7
2 files changed
+42
-1
No files matched your search
@@ -218,7 +218,10 @@ pub(crate) fn export_layered(doc: &Document, opts: &ExportOptions) -> Result<Exp
|
||||
let mut img = Image::from_raw(w, h, layout, sample, data)?;
|
||||
img.icc = doc.icc_profile.as_ref().map(|i| i.to_vec());
|
||||
img.meta = codecs::Metadata {
|
||||
exif: doc.metadata.exif.as_ref().map(|e| e.to_vec()),
|
||||
// EXIF is deliberately not set here: the TIFF codec has no EXIF directory, so the tags
|
||||
// above carry it as resource 1058 and the importer reads them back from there. Handing the
|
||||
// codec a second copy in `meta.exif` bought nothing and made the export claim it would
|
||||
// drop metadata it had in fact kept (#1545).
|
||||
xmp: doc.metadata.xmp.clone().filter(|_| opts.xmp == crate::XmpEmbed::All),
|
||||
dpi: Some((doc.resolution_dpi, doc.resolution_dpi)),
|
||||
photoshop_resources: Some(resources),
|
||||
|
||||
@@ -107,6 +107,44 @@ fn every_compression_keeps_the_layers() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Artist tag's text, and the bytes every EXIF assertion looks for.
|
||||
const ARTIST: &[u8] = b"fixture-artist";
|
||||
|
||||
/// A minimal little-endian EXIF (TIFF) block with a single Artist tag and no Orientation, so
|
||||
/// `upright_exif` passes it through untouched.
|
||||
fn exif() -> Vec<u8> {
|
||||
let mut artist = ARTIST.to_vec();
|
||||
artist.push(0); // ASCII NUL terminator
|
||||
let mut v = b"II*\0\x08\0\0\0".to_vec(); // TIFF header, first IFD at 8
|
||||
v.extend_from_slice(&1u16.to_le_bytes()); // one entry
|
||||
v.extend_from_slice(&0x013bu16.to_le_bytes()); // Artist
|
||||
v.extend_from_slice(&2u16.to_le_bytes()); // ASCII
|
||||
v.extend_from_slice(&(artist.len() as u32).to_le_bytes());
|
||||
v.extend_from_slice(&26u32.to_le_bytes()); // value offset: 8 + 2 + 12 + 4
|
||||
v.extend_from_slice(&0u32.to_le_bytes()); // no next IFD
|
||||
v.extend_from_slice(&artist);
|
||||
v
|
||||
}
|
||||
|
||||
/// #1545: a layered TIFF carries EXIF as Photoshop resource 1058 and reads it back, so it must
|
||||
/// not report a loss it never makes. A flat TIFF really does lose the tags and still says so.
|
||||
#[test]
|
||||
fn layered_tiff_keeps_exif_without_claiming_a_loss() {
|
||||
let mut d = gen_doc(ColorMode::Rgb, SampleType::U8, Features::PIXELS);
|
||||
d.metadata.exif = Some(std::sync::Arc::new(exif()));
|
||||
|
||||
let r = tiff(&d, true);
|
||||
assert!(!r.warnings.iter().any(|w| w.contains("EXIF")), "a layered TIFF keeps EXIF, so it must not claim to drop it: {:?}", r.warnings);
|
||||
// ...and the tags really are in the file, so the missing warning is a true absence of loss.
|
||||
let back = import("x.tif", &r.bytes).unwrap().document;
|
||||
let kept = back.metadata.exif.as_deref().expect("EXIF survives the layered export");
|
||||
assert!(kept.windows(ARTIST.len()).any(|w| w == ARTIST), "the Artist tag did not survive: {kept:?}");
|
||||
|
||||
// The control from the issue: the flat path drops it for real, and keeps reporting that.
|
||||
let flat = tiff(&d, false);
|
||||
assert!(flat.warnings.iter().any(|w| w.contains("EXIF")), "a flat TIFF really does lose EXIF: {:?}", flat.warnings);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discard_layers_writes_a_flat_file() {
|
||||
let d = gen_doc(ColorMode::Rgb, SampleType::U8, Features::PIXELS);
|
||||
|
||||
Reference in new issue
Block a user