Raw: scale floating-point samples by the highest white level, not the first

WhiteLevel holds one value per sample plane, but the float scale came
from the first only. A plane whose white level was higher than the
first's was clipped before the DNG reader applied its own level. The
scale now comes from the highest valid white level (default 1.0).
This commit is contained in:
SBaksa committed 2026-10-23 09:58:18 +11:00
1 parent 7fe111704b
commit a4fc3a714e
2 files changed
+19 -3

No files matched your search

+6 -3
View File
@@ -250,9 +250,12 @@ pub(crate) fn read_plane(t: &Tiff, ifd: &Ifd, limits: &Limits, layout: JpegLayou
return Err(RawError::unsupported(format!("{bits}-bit floating-point raw samples")));
}
let bits = if float { 16 } else { bits };
// The floats' white level (default 1.0, DNG 1.7 WhiteLevel) becomes 65535.
let float_scale =
float.then(|| 65535.0 / t.tag_floats(ifd, tag::WHITE_LEVEL).first().map(|v| *v as f32).filter(|v| v.is_finite() && *v > 0.0).unwrap_or(1.0));
// The floats' highest white level (default 1.0; DNG 1.7 WhiteLevel has one per sample plane)
// becomes 65535, so no plane is clipped below its own white level.
let float_scale = float.then(|| {
let white = t.tag_floats(ifd, tag::WHITE_LEVEL).iter().map(|v| *v as f32).filter(|v| v.is_finite() && *v > 0.0).fold(0.0f32, f32::max);
65535.0 / if white > 0.0 { white } else { 1.0 }
});
if !(1..=16).contains(&bits) {
return Err(RawError::unsupported(format!("{bits}-bit raw samples")));
}
+13
View File
@@ -736,6 +736,19 @@ fn floating_point_raw_data_that_isnt_jpeg_xl_is_unsupported() {
}
}
/// WhiteLevel has one value per sample plane: the floats are scaled by the highest, so a plane
/// with a higher white level than the first keeps its highlights.
#[test]
fn floating_point_white_levels_per_plane_scale_from_the_highest() {
let (w, h) = (24, 16);
let data = noise(w * h * 3, 16);
let mut spec = float_jxl_dng(&data, w, h, None);
spec.raw_extra.push((50717, Val::Double(vec![0.5, 1.0, 0.5])));
let s = sensor(&spec.build());
assert_eq!(s.data, data, "scaled by 1.0, the highest: nothing clipped");
assert_eq!(s.white, [32767.5, 65535.0, 32767.5]);
}
/// Floating-point samples are read into four bytes each before they become 16-bit: the limits
/// are charged for that buffer, not for the two-byte result.
#[test]