mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
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:
@@ -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());
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user