mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 16:24:38 +00:00
Canonicalize DNG CFA at sensor origin
This commit is contained in:
2 files changed
+8
-11
No files matched your search
+7
-10
@@ -406,17 +406,14 @@ fn decode_ifd(bytes: &[u8], tiff: &Tiff, pixels: &Ifd, main: &Ifd, mode: Mode, f
|
||||
if cpp != 1 {
|
||||
return Err(RawError::Unsupported("CFA data with several samples per pixel".into()));
|
||||
}
|
||||
// the tag is anchored at the top-left of the ActiveArea (DNG spec); `RawImage::cfa` is anchored at the
|
||||
// sensor origin (the crop to the active area shifts it back), so move the anchor out by the area's offset
|
||||
// (DNGs that LightCraft wrote before its writer followed the spec carry the sensor-origin pattern; they are marked
|
||||
// by a bare "LightCraft" Software tag and keep their original reading)
|
||||
let mut at_origin = Cfa { width: cols, height: rows, pattern, origin_x: 0, origin_y: 0 };
|
||||
// DNG's CFAPattern is anchored at ActiveArea. Store one canonical CFA anchored at the
|
||||
// sensor origin instead: invert the ActiveArea phase before building RawImage::cfa.
|
||||
// Older LightCraft files wrote the pattern at the sensor origin and are identified by
|
||||
// their bare Software tag, so those keep the bytes as written.
|
||||
let at_area = Cfa { width: cols, height: rows, pattern, origin_x: 0, origin_y: 0 };
|
||||
let legacy_writer = [raw, ifd0].iter().any(|i| i.string(t::SOFTWARE).as_deref().map(str::trim) == Some("LightCraft"));
|
||||
if !legacy_writer {
|
||||
at_origin.origin_x = active_area.x;
|
||||
at_origin.origin_y = active_area.y;
|
||||
}
|
||||
Some(at_origin)
|
||||
let cfa = if legacy_writer { at_area } else { at_area.shifted((cols - active_area.x % cols) % cols, (rows - active_area.y % rows) % rows) };
|
||||
Some(cfa)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -862,7 +862,7 @@ impl Cfa {
|
||||
}
|
||||
/// Pattern name like `"RGGB"` for 2×2 patterns.
|
||||
pub fn name(&self) -> String {
|
||||
self.pattern.iter().map(|&c| ['R', 'G', 'B', '?'][c.min(3) as usize]).collect()
|
||||
self.shifted(0, 0).pattern.iter().map(|&c| ['R', 'G', 'B', '?'][c.min(3) as usize]).collect()
|
||||
}
|
||||
fn valid(&self) -> bool {
|
||||
self.width > 0 && self.height > 0 && self.width <= 16 && self.height <= 16 && self.pattern.len() == self.width * self.height
|
||||
|
||||
Reference in new issue
Block a user