RAW-ORF-PREVIEW: scan for JPEGs when preview pointers are missing

An enabled ORF reader makes the format report supported even when a
particular sensor stream cannot be decoded. Keep the existing JPEG scan
fallback available for these files when their preview tags are missing
or damaged.

Cover both preview entry points with an unsupported ORF containing an
unreferenced JPEG.
This commit is contained in:
pancake
2026-11-19 20:21:36 +01:00
parent 08da5e1486
commit 9e81d13691
2 changed files with 26 additions and 1 deletions
+4 -1
View File
@@ -410,7 +410,10 @@ fn preview_covering(bytes: &[u8], min_edge: Option<u32>, jpeg_only: bool) -> Opt
.or(largest)
.map(|s| if is_jxl(s) { s.to_vec() } else { trim_eoi(s).to_vec() });
// a TIFF raw whose preview no tag points to: one we can't decode (Leaf MOS), or Epson ERF (in its maker note)
let best = best.or_else(|| format.filter(|f| !f.is_supported() || *f == crate::RawFormat::Erf).and_then(|_| scan_for_jpeg(bytes)));
// ORF capability must not remove the scan fallback for unsupported modes and damaged preview pointers.
let best = best.or_else(|| {
format.filter(|f| !f.is_supported() || matches!(f, crate::RawFormat::Erf | crate::RawFormat::Orf)).and_then(|_| scan_for_jpeg(bytes))
});
// Hasselblad 3FR / FFF carry no JPEG, only uncompressed RGB images: one wrapped as a baseline TIFF
#[cfg(feature = "hasselblad")]
let best = best.or_else(|| (format == Some(crate::RawFormat::CfaTiff)).then(|| crate::hasselblad::rgb_preview(&tiff, bytes)).flatten());
+22
View File
@@ -952,3 +952,25 @@ fn the_cr3_copy_chosen_for_a_thumbnail_decodes() {
assert_eq!(((w, h), c), (want, 3), "covering {min} px");
}
}
#[cfg(feature = "orf")]
/// ORF capability reporting must not disable preview scanning for an unrecognized stream.
#[test]
fn supported_orf_keeps_unreferenced_jpeg_fallback() {
let mut ifd = IfdBuilder::new();
ifd.set(t::IMAGE_WIDTH, Value::Long(vec![64]));
ifd.set(t::IMAGE_LENGTH, Value::Long(vec![64]));
ifd.set(t::BITS_PER_SAMPLE, Value::Short(vec![16]));
ifd.set(t::COMPRESSION, Value::Short(vec![1]));
ifd.set_image(ImageData::Strips { rows_per_strip: 64, strips: vec![vec![0; 16]] });
let mut file = TiffWriter::default().write(&[ifd]).unwrap();
file[2..4].copy_from_slice(b"RO");
let jpeg = scan_jpeg(3, 900);
file.extend_from_slice(&jpeg);
let format = crate::probe(&file).unwrap();
assert_eq!(format, crate::RawFormat::Orf);
assert!(format.is_supported());
assert!(matches!(crate::decode(&file), Err(crate::RawError::Unsupported(_))));
assert_eq!(embedded_preview(&file).as_deref(), Some(jpeg.as_slice()));
assert_eq!(embedded_preview_covering(&file, 1).as_deref(), Some(jpeg.as_slice()));
}