Preserve floating point raw samples in develop pipeline

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 00:50:50 -05:00
1 parent 4addec32c2
commit b5320bdb0c
12 files changed
+42 -7

No files matched your search

+1
View File
@@ -216,6 +216,7 @@ mod tests {
height,
samples: 1,
data: Vec::new(),
float_data: None,
cfa: None,
linearization: None,
black: BlackLevels::uniform(0.0),
+2
View File
@@ -256,6 +256,7 @@ fn decode_sraw(t: &Tiff, ifds: &[Ifd], ifd0: &Ifd, slices: &[u32], src: &[u8], f
height,
samples: 3,
data,
float_data: None,
cfa: None,
linearization: None,
// Y is stored black-subtracted.
@@ -361,6 +362,7 @@ pub(crate) fn decode(t: &Tiff, limits: &Limits) -> Result<Sensor> {
height,
samples: 1,
data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,
+20 -6
View File
@@ -102,10 +102,15 @@ impl<'a> Scale<'a> {
#[inline]
pub(crate) fn value(&self, x: usize, y: usize, sample: usize) -> f32 {
let s = self.s;
let raw = s.data[(y * s.width + x) * s.samples + sample];
let v = match self.lin {
Some(l) => f32::from(l.get(usize::from(raw)).or_else(|| l.last()).copied().unwrap_or(raw)),
None => f32::from(raw),
let index = (y * s.width + x) * s.samples + sample;
let v = if let Some(samples) = &s.float_data {
samples[index]
} else {
let raw = s.data[index];
match self.lin {
Some(l) => f32::from(l.get(usize::from(raw)).or_else(|| l.last()).copied().unwrap_or(raw)),
None => f32::from(raw),
}
};
let black = s.black.at(x.saturating_sub(s.active.x), y.saturating_sub(s.active.y), sample, s.samples);
let white = s.white[sample.min(2)];
@@ -128,6 +133,14 @@ fn fill_linear_row(sc: &Scale, mult: &[f32; 3], x0: usize, y: usize, row: &mut [
let s = sc.s;
let spp = s.samples;
let w = row.len() / 3;
if s.float_data.is_some() {
for (i, px) in row.as_chunks_mut::<3>().0.iter_mut().enumerate() {
for k in 0..3 {
px[k] = (sc.value(x0 + i, y, k.min(spp.saturating_sub(1))) * mult[k]).clamp(0.0, 1.0);
}
}
return;
}
let bl = &s.black;
let cols = bl.cols.max(1);
if !bl.delta_h.is_empty() || !bl.delta_v.is_empty() || x0 < s.active.x || cols > 16 || !matches!(spp, 1 | 3) {
@@ -269,7 +282,7 @@ fn develop(s: &Sensor, opts: &DevelopOptions, allow_fused: bool) -> Result<Devel
if c.is_empty()
|| c.x.checked_add(c.width).is_none_or(|x| x > s.width)
|| c.y.checked_add(c.height).is_none_or(|y| y > s.height)
|| samples.is_none_or(|n| s.data.len() < n)
|| samples.is_none_or(|n| s.sample_count() < n)
{
return Err(RawError::malformed("crop lies outside the sensor data"));
}
@@ -381,7 +394,7 @@ fn develop(s: &Sensor, opts: &DevelopOptions, allow_fused: bool) -> Result<Devel
let period = if cfa.width % 2 == 0 { cfa.width.max(2) } else { cfa.width * 2 };
let fill_row = |iy: usize, row: &mut [f32]| {
let y = c.y + iy;
if periodic {
if periodic && s.float_data.is_none() {
// Per column of the period: black and the combined scale × white-balance gain.
let k: Vec<(f32, f32)> = (0..period)
.map(|p| {
@@ -837,6 +850,7 @@ mod tests {
height: h,
samples,
data,
float_data: None,
cfa,
linearization: None,
black: BlackLevels::uniform(64.0),
+1
View File
@@ -283,6 +283,7 @@ pub(crate) fn decode(t: &Tiff, limits: &Limits) -> Result<Sensor> {
height: plane.height,
samples,
data,
float_data: None,
cfa,
linearization,
black,
+1
View File
@@ -110,6 +110,7 @@ pub(crate) fn decode(t: &Tiff, limits: &Limits) -> Result<Sensor> {
height: plane.height,
samples: 1,
data: plane.data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,
+1 -1
View File
@@ -294,7 +294,7 @@ fn grid(s: &Sensor, opts: &DevelopOptions, r: &Reference) -> Result<(usize, Vec<
let c = s.crop;
let in_data = c.x.checked_add(c.width).is_some_and(|v| v <= s.width) && c.y.checked_add(c.height).is_some_and(|v| v <= s.height);
let need = s.width.checked_mul(s.height).and_then(|v| v.checked_mul(s.samples));
if c.is_empty() || !in_data || need.is_none_or(|n| s.data.len() < n) {
if c.is_empty() || !in_data || need.is_none_or(|n| s.sample_count() < n) {
return reject("the crop lies outside the sensor data");
}
if !(s.samples == 3 || (s.samples == 1 && s.cfa.is_some())) {
+1
View File
@@ -138,6 +138,7 @@ pub(crate) fn decode(t: &Tiff, limits: &Limits) -> Result<Sensor> {
height: plane.height,
samples: 1,
data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,
+1
View File
@@ -320,6 +320,7 @@ pub(crate) fn decode(bytes: &[u8], limits: &Limits) -> Result<Sensor> {
height,
samples: 1,
data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,
+1
View File
@@ -292,6 +292,7 @@ pub(crate) fn decode(t: &Tiff, limits: &Limits) -> Result<Sensor> {
height,
samples: 1,
data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,
+1
View File
@@ -175,6 +175,7 @@ mod tests {
height: 64,
samples: 1,
data,
float_data: None,
cfa: Cfa::bayer("RGGB"),
linearization: None,
black: BlackLevels::uniform(528.0),
+11
View File
@@ -143,6 +143,8 @@ pub struct Sensor {
pub samples: usize,
/// Row-major interleaved samples, `width * height * samples`.
pub data: Vec<u16>,
/// Floating-point sensor samples, kept without quantizing. When present, `data` is empty.
pub float_data: Option<Vec<f32>>,
/// The CFA pattern (CFA data only).
pub cfa: Option<Cfa>,
/// Maps stored values to linear values (DNG LinearizationTable).
@@ -175,6 +177,15 @@ pub struct Sensor {
}
impl Sensor {
pub fn sample_count(&self) -> usize {
self.float_data.as_ref().map_or(self.data.len(), Vec::len)
}
#[inline]
pub fn sample(&self, index: usize) -> f32 {
self.float_data.as_ref().map_or_else(|| f32::from(self.data[index]), |samples| samples[index])
}
/// `true` for monochrome data (one-sample LinearRaw: monochrome cameras, scanner DNGs), which
/// develops to neutral grey with no white balance or colour calibration.
pub fn is_monochrome(&self) -> bool {
+1
View File
@@ -245,6 +245,7 @@ pub(crate) fn decode(t: &Tiff, format: RawFormat, limits: &Limits) -> Result<Sen
height: plane.height,
samples: 1,
data: plane.data,
float_data: None,
cfa: Some(cfa),
linearization: None,
black,