Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

DNG: decode lossy (JPEG-compressed) DNG tiles (FILE-215-11) (#5112)

Fabio Lissi8a6af66cf69a
diff --git a/crates/raw/README.md b/crates/raw/README.md
index b66b53361..bb4815a4f 100644
--- a/crates/raw/README.md
+++ b/crates/raw/README.md
@@ -67,7 +67,7 @@ camera colour tables were copied.
| Format | Status |
|---|---|
-| DNG | Uncompressed (8–16 bit, packed or not), Deflate (compression 8, predictors 1 and 2), lossless JPEG and JPEG XL (DNG 1.7, e.g. Samsung Expert RAW; decoded by `jxl-oxide`; not in wasm32 builds, where it is `Unsupported`); strips and tiles; CFA (Bayer) and LinearRaw (three-sample colour, or one-sample monochrome such as Leica Monochrom and film-scanner DNGs, developed as neutral grey with no white balance or colour matrix); LinearizationTable, BlackLevel (+ repeat, DeltaH/V), WhiteLevel, ActiveArea, DefaultCrop, ColorMatrix1/2, CameraCalibration, ForwardMatrix, AnalogBalance, AsShotNeutral / AsShotWhiteXY, BaselineExposure, Orientation, OpcodeList2 GainMap (lens shading) |
+| DNG | Uncompressed (8–16 bit, packed or not), Deflate (compression 8, predictors 1 and 2), lossless JPEG, lossy JPEG (DNG 1.4 compression 34892: 8-bit baseline JPEG tiles or strips, gray for CFA, YCbCr-coded RGB for LinearRaw; decoded by `zune-jpeg`, the stored 8-bit values then go through the same LinearizationTable / BlackLevel / WhiteLevel as every other depth) and JPEG XL (DNG 1.7, e.g. Samsung Expert RAW; decoded by `jxl-oxide`; not in wasm32 builds, where it is `Unsupported`); strips and tiles; CFA (Bayer) and LinearRaw (three-sample colour, or one-sample monochrome such as Leica Monochrom and film-scanner DNGs, developed as neutral grey with no white balance or colour matrix); LinearizationTable, BlackLevel (+ repeat, DeltaH/V), WhiteLevel, ActiveArea, DefaultCrop, ColorMatrix1/2, CameraCalibration, ForwardMatrix, AnalogBalance, AsShotNeutral / AsShotWhiteXY, BaselineExposure, Orientation, OpcodeList2 GainMap (lens shading) |
| DNG (lossy JPEG, floating point; opcodes other than GainMap; ProfileGainTableMap) | Unsupported / not applied (reported) |
| CR2 | Lossless JPEG with slices, borders and as-shot white balance from the maker note, black measured on the masked border. CR2 has no CFA tag and the row phase varies by model, so it is measured from the data (the green diagonal), with a Canon model-ID table as the fallback (see `src/cr2.rs`) |
| CR2 sRAW / mRAW | Unsupported |
diff --git a/crates/raw/src/lib.rs b/crates/raw/src/lib.rs
index 0bccf8ffa..0d1a99e79 100644
--- a/crates/raw/src/lib.rs
+++ b/crates/raw/src/lib.rs
@@ -28,7 +28,7 @@
//! Bodies whose full profile is not measured yet can still carry a measured
//! image area (the D800E, the ILCE-7).
//!
-//! Decoded today: DNG (uncompressed, lossless-JPEG and JPEG XL, strips and
+//! Decoded today: DNG (uncompressed, deflate, lossless-JPEG, lossy-JPEG and JPEG XL, strips and
//! tiles, CFA and LinearRaw), CR2 (lossless JPEG with Canon slices), uncompressed or
//! lossless-JPEG TIFF/EP raws (NEF, ARW, PEF… when not vendor-compressed),
//! Nikon compressed NEF (lossless and lossy), Sony compressed ARW (cRAW),
diff --git a/crates/raw/src/sensor.rs b/crates/raw/src/sensor.rs
index d71c4a905..f2cffdb80 100644
--- a/crates/raw/src/sensor.rs
+++ b/crates/raw/src/sensor.rs
@@ -227,7 +227,7 @@ fn inflate_tile(src: &[u8], need: usize) -> Result<Vec<u8>> {
Ok(out)
}
-/// Reads the (uncompressed, lossless-JPEG or JPEG XL) image of a raw IFD.
+/// Reads the (uncompressed, deflate, lossless-JPEG, lossy-JPEG or JPEG XL) image of a raw IFD.
pub(crate) fn read_plane(t: &Tiff, ifd: &Ifd, limits: &Limits, layout: JpegLayout) -> Result<Plane> {
let width = t.tag_uint(ifd, tag::IMAGE_WIDTH).ok_or_else(|| RawError::malformed("raw image has no width"))? as usize;
let height = t.tag_uint(ifd, tag::IMAGE_LENGTH).ok_or_else(|| RawError::malformed("raw image has no height"))? as usize;
@@ -256,6 +256,7 @@ pub(crate) fn read_plane(t: &Tiff, ifd: &Ifd, limits: &Limits, layout: JpegLayou
limits.check(width as u64, height as u64, samples as u64 * 2)?;
let segments = segments(t, ifd, width, height)?;
let le = t.le;
+ let tiled = t.tag_uint(ifd, tag::TILE_WIDTH).is_some();
let decoded: Vec<Result<Vec<u16>>> = par::map(segments.len(), |i| {
let s = &segments[i];
let rows = s.h.min(height - s.y);
@@ -286,37 +287,12 @@ pub(crate) fn read_plane(t: &Tiff, ifd: &Ifd, limits: &Limits, layout: JpegLayou
}
// A JPEG XL segment codes only the rows inside the image (strips) or the whole tile.
JPEG_XL => {
- let coded_rows = if t.tag_uint(ifd, tag::TILE_WIDTH).is_some() { s.h } else { rows };
+ let coded_rows = if tiled { s.h } else { rows };
let mut v = jxl::decode(src, s.w, coded_rows, samples, bits, limits)?;
v.resize(s.w * s.h * samples, 0);
Ok(v)
}
- 34892 => {
- // Adobe DNG compression 34892: baseline JPEG tiles (lossy, 8-bit). The tile is
- // a complete JPEG stream: a CFA part decodes to gray samples, a 3-sample
- // LinearRaw part holds YCbCr, which zune-jpeg converts to RGB. The header is
- // decoded and size-checked before any pixel allocation, so a hostile tile
- // cannot size the decoder's buffers (up to 16384x16384) with a fake SOF.
- let out = match samples {
- 1 => zune_core::colorspace::ColorSpace::Luma,
- 3 => zune_core::colorspace::ColorSpace::RGB,
- n => return Err(RawError::unsupported(format!("lossy DNG with {n} samples per pixel (1 or 3 are supported)"))),
- };
- let options = zune_core::options::DecoderOptions::default().jpeg_set_out_colorspace(out);
- let mut dec = zune_jpeg::JpegDecoder::new_with_options(zune_core::bytestream::ZCursor::new(src), options);
- dec.decode_headers().map_err(|e| RawError::malformed(format!("lossy JPEG tile header: {e:?}")))?;
- let f = dec.info().ok_or_else(|| RawError::malformed("lossy JPEG tile has no header"))?;
- if (f.width as usize, f.height as usize) != (s.w, rows) {
- return Err(RawError::malformed(format!("lossy JPEG tile is {}x{}, expected {}x{}", f.width, f.height, s.w, rows)));
- }
- let decoded = dec.decode().map_err(|e| RawError::malformed(format!("lossy JPEG tile: {e:?}")))?;
- let need = s.w * rows * samples;
- if decoded.len() != need {
- return Err(RawError::malformed(format!("lossy JPEG tile holds {} samples, expected {need}", decoded.len())));
- }
- // The 8-bit samples widen to the document's 16-bit range (0xFF -> 0xFFFF).
- Ok(decoded.into_iter().map(|b| u16::from(b) * 257).collect())
- }
+ 34892 => lossy_jpeg(src, s, rows, samples, bits, tiled, limits),
// Compression 7 (lossless JPEG): the frame the entropy stream declares is capped
// by the budget, not only by the segment, and the `Quads` scatter buffer below
// comes out of the same budget. `max_alloc` counts bytes, a sample is two.
@@ -401,6 +377,54 @@ pub(crate) fn segments(t: &Tiff, ifd: &Ifd, width: usize, height: usize) -> Resu
Ok(out)
}
+/// Decodes one segment of a lossy DNG (Adobe DNG compression 34892): a complete baseline-DCT
+/// JPEG stream (ITU-T T.81), 8 bits per sample, as DNG 1.4 defines it. A CFA segment is a
+/// one-component (gray) JPEG; a 3-sample LinearRaw segment is a three-component one in YCbCr,
+/// which the JPEG decoder turns back into the stored R, G, B. The decoded 8-bit values are the
+/// stored sample values: the LinearizationTable, BlackLevel and WhiteLevel apply to them later,
+/// as for every other compression, and WhiteLevel defaults to 255 for 8-bit data.
+///
+/// `rows` is the number of segment rows inside the image. A tile is always coded at the full
+/// tile size (edge tiles are padded); a strip is coded at its row count (the last strip is
+/// shorter). Either height is accepted, the width must be the segment's. The frame header is
+/// checked before any pixel is decoded, and the decoder's own size cap is the segment, so a
+/// hostile SOF cannot size a buffer larger than the tile the IFD declares (which `limits` has
+/// already charged).
+fn lossy_jpeg(src: &[u8], s: &Segment, rows: usize, samples: usize, bits: u32, tiled: bool, limits: &Limits) -> Result<Vec<u16>> {
+ use zune_core::{bytestream::ZCursor, colorspace::ColorSpace, options::DecoderOptions};
+ if bits != 8 {
+ return Err(RawError::unsupported(format!("lossy DNG with {bits}-bit samples (lossy JPEG tiles are 8-bit)")));
+ }
+ let out = match samples {
+ 1 => ColorSpace::Luma,
+ 3 => ColorSpace::RGB,
+ n => return Err(RawError::unsupported(format!("lossy DNG with {n} samples per pixel (1 or 3 are supported)"))),
+ };
+ let options = DecoderOptions::default().jpeg_set_out_colorspace(out).set_max_width(s.w).set_max_height(s.h);
+ let mut dec = zune_jpeg::JpegDecoder::new_with_options(ZCursor::new(src), options);
+ dec.decode_headers().map_err(|e| RawError::malformed(format!("lossy JPEG tile header: {e:?}")))?;
+ let f = dec.info().ok_or_else(|| RawError::malformed("lossy JPEG tile has no header"))?;
+ let (fw, fh) = (usize::from(f.width), usize::from(f.height));
+ let coded_rows = if tiled { s.h } else { rows };
+ if fw != s.w || (fh != coded_rows && fh != rows) {
+ return Err(RawError::malformed(format!("lossy JPEG tile is {fw}x{fh}, expected {}x{coded_rows}", s.w)));
+ }
+ if usize::from(f.components) != samples {
+ return Err(RawError::malformed(format!("lossy JPEG tile has {} components, expected {samples}", f.components)));
+ }
+ let need = fw.checked_mul(fh).and_then(|n| n.checked_mul(samples)).ok_or_else(|| RawError::malformed("lossy JPEG tile is too large"))?;
+ limits.check(fw as u64, fh as u64, samples as u64 * 2)?;
+ let decoded = dec.decode().map_err(|e| RawError::malformed(format!("lossy JPEG tile: {e:?}")))?;
+ if decoded.len() != need {
+ return Err(RawError::malformed(format!("lossy JPEG tile holds {} samples, expected {need}", decoded.len())));
+ }
+ let mut v: Vec<u16> = decoded.into_iter().map(u16::from).collect();
+ // A strip coded at its own row count still fills the segment's declared height.
+ let full = s.w.checked_mul(s.h).and_then(|n| n.checked_mul(samples)).ok_or_else(|| RawError::malformed("lossy JPEG tile is too large"))?;
+ v.resize(full, 0);
+ Ok(v)
+}
+
/// Reverses TIFF predictor 2 (horizontal differencing) on interleaved samples: each sample
/// gains its channel's predecessor in the row, wrapping at the sample's container (8 or 16 bits).
fn undelta(v: &[u16], plane: usize, row_samples: usize, rows: usize, bits: u32) -> Vec<u16> {
diff --git a/crates/raw/src/testgen.rs b/crates/raw/src/testgen.rs
index 2de64ae4b..9d8b8fb94 100644
--- a/crates/raw/src/testgen.rs
+++ b/crates/raw/src/testgen.rs
@@ -398,14 +398,30 @@ fn urat(v: f64) -> (u32, u32) {
// ---------------------------------------------------------------- DNG
+/// Encodes 8-bit samples (1 gray or 3 RGB per pixel, row-major) as a baseline JPEG at
+/// quality 60, the way a lossy DNG segment is stored (an RGB segment is coded as YCbCr).
+pub fn baseline_jpeg(samples: &[u8], width: usize, height: usize, per_pixel: usize) -> Vec<u8> {
+ use image::ImageEncoder as _;
+ let colour = if per_pixel == 3 { image::ExtendedColorType::Rgb8 } else { image::ExtendedColorType::L8 };
+ let mut j = Vec::new();
+ let enc = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut j, 60);
+ enc.write_image(samples, width as u32, height as u32, colour).expect("jpeg segment");
+ j
+}
+
/// How the DNG stores its raw data.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DngStorage {
/// One strip per `rows` rows, uncompressed at `bits` per sample (8, 12, 16…).
Strips { rows: usize },
- /// Adobe DNG compression 34892: baseline JPEG tiles, 8-bit luma at tile size (the reader
- /// decodes and widens to 16 bits). Quality 60 leaves visible-but-mild artifacts.
+ /// Adobe DNG compression 34892: baseline JPEG tiles at tile size (edge tiles padded), one
+ /// gray component for CFA and monochrome data, three (YCbCr-coded RGB) for LinearRaw. The
+ /// spec's `bits` should be 8 (the DNG spec's depth for lossy JPEG; the reader rejects others);
+ /// wider samples are written as their top 8 bits. Quality 60 leaves visible-but-mild artifacts.
LossyJpegTiles { width: usize, height: usize },
+ /// Adobe DNG compression 34892 in strips of this many rows: each strip is a baseline JPEG
+ /// of the image width by the strip's own row count (the last strip is shorter).
+ LossyJpegStrips { rows: usize },
/// Adobe DNG compression 8: zlib streams with the TIFF predictor (1 = none, 2 = horizontal
/// differencing) applied before compressing.
DeflateStrips { rows: usize, predictor: u16 },
@@ -438,6 +454,7 @@ pub struct DngSpec {
pub big_endian: bool,
pub black: Vec<u32>,
pub black_repeat: (u16, u16),
+ /// WhiteLevel; 0 leaves the tag out (the reader then defaults to the bit depth's maximum).
pub white: u32,
/// top, left, bottom, right
pub active_area: Option<[u32; 4]>,
@@ -459,6 +476,10 @@ pub struct DngSpec {
pub opcode_list2: Option<Vec<u8>>,
/// Encoded segments for [`DngStorage::JxlStrips`] / [`DngStorage::JxlTiles`].
pub jxl_segments: Vec<Vec<u8>>,
+ /// Pre-encoded segments for [`DngStorage::LossyJpegTiles`] / [`DngStorage::LossyJpegStrips`]
+ /// (row-major), used instead of encoding `data` where present: for tiles that disagree with
+ /// the IFD (hostile-input tests).
+ pub lossy_segments: Vec<Vec<u8>>,
/// Raw ProfileGainTableMap bytes, written to IFD0 (contents are not interpreted).
pub profile_gain_table_map: Option<Vec<u8>>,
pub orientation: u16,
@@ -498,6 +519,7 @@ impl DngSpec {
orientation: 1,
opcode_list2: None,
jxl_segments: Vec::new(),
+ lossy_segments: Vec::new(),
profile_gain_table_map: None,
make: "Photocraft".into(),
model: "Synthetic".into(),
@@ -515,6 +537,12 @@ impl DngSpec {
self.samples == 1 && !self.monochrome
}
+ /// The 8-bit sample a lossy JPEG segment stores for `v`: the value itself at 8 bits, else
+ /// its top 8 bits.
+ fn sample8(&self, v: u16) -> u8 {
+ (v >> self.bits.saturating_sub(8)) as u8
+ }
+
fn pack(&self, rows: std::ops::Range<usize>) -> Vec<u8> {
let n = self.width * self.samples;
let vals = &self.data[rows.start * n..rows.end * n];
@@ -554,10 +582,12 @@ impl DngSpec {
(262, Val::Short(vec![if self.is_cfa() { 32803 } else { 34892 }])),
(277, Val::Short(vec![self.samples as u16])),
(284, Val::Short(vec![1])),
- (50717, Val::Long(vec![self.white; self.samples])),
(50713, Val::Short(vec![self.black_repeat.0, self.black_repeat.1])),
(50714, Val::Long(self.black.clone())),
];
+ if self.white != 0 {
+ raw.push((50717, Val::Long(vec![self.white; self.samples])));
+ }
if self.is_cfa() {
raw.push((33421, Val::Short(vec![2, 2])));
raw.push((33422, Val::Byte(self.cfa.to_vec())));
@@ -620,23 +650,18 @@ impl DngSpec {
let s = self.samples;
for ty in (0..self.height).step_by(th) {
for tx in (0..self.width).step_by(tw) {
- // Edge tiles are padded by repeating the last row / column. A 3-sample
- // (LinearRaw) spec writes RGB tiles, a CFA spec gray ones.
+ // Edge tiles are padded by repeating the last row / column.
let mut tile = vec![0u8; tw * th * s];
for y in 0..th {
for x in 0..tw {
let sy = (ty + y).min(self.height - 1);
let sx = (tx + x).min(self.width - 1);
for c in 0..s {
- tile[(y * tw + x) * s + c] = (self.data[(sy * self.width + sx) * s + c] >> 8) as u8;
+ tile[(y * tw + x) * s + c] = self.sample8(self.data[(sy * self.width + sx) * s + c]);
}
}
}
- let colour = if s == 3 { image::ExtendedColorType::Rgb8 } else { image::ExtendedColorType::L8 };
- let mut j = Vec::new();
- let enc = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut j, 60);
- use image::ImageEncoder as _;
- enc.write_image(&tile, tw as u32, th as u32, colour).expect("jpeg tile");
+ let j = self.lossy_segments.get(offs.len()).cloned().unwrap_or_else(|| baseline_jpeg(&tile, tw, th, s));
lens.push(j.len() as u32);
offs.push(t.blob(j));
}
@@ -647,6 +672,22 @@ impl DngSpec {
raw.push((324, Val::Blobs(offs)));
raw.push((325, Val::Long(lens)));
}
+ DngStorage::LossyJpegStrips { rows } => {
+ let mut offs = Vec::new();
+ let mut lens = Vec::new();
+ let n = self.width * self.samples;
+ for y in (0..self.height).step_by(rows) {
+ let r = (y + rows).min(self.height) - y;
+ let strip: Vec<u8> = self.data[y * n..(y + r) * n].iter().map(|&v| self.sample8(v)).collect();
+ let j = self.lossy_segments.get(offs.len()).cloned().unwrap_or_else(|| baseline_jpeg(&strip, self.width, r, self.samples));
+ lens.push(j.len() as u32);
+ offs.push(t.blob(j));
+ }
+ raw.push((259, Val::Short(vec![34892])));
+ raw.push((278, Val::Long(vec![rows as u32])));
+ raw.push((273, Val::Blobs(offs)));
+ raw.push((279, Val::Long(lens)));
+ }
DngStorage::Lj92Strips { rows } => {
let mut offs = Vec::new();
let mut lens = Vec::new();
diff --git a/crates/raw/tests/dng.rs b/crates/raw/tests/dng.rs
index e13fb920d..7cc04d2a9 100644
--- a/crates/raw/tests/dng.rs
+++ b/crates/raw/tests/dng.rs
@@ -1,7 +1,7 @@
//! Synthetic DNG files: every storage layout decodes to the exact sensor
//! samples, and development reproduces known colours.
-use photocraft_raw::testgen::{DngSpec, DngStorage, Val, mosaic, scene};
+use photocraft_raw::testgen::{DngSpec, DngStorage, Val, baseline_jpeg, mosaic, scene};
use photocraft_raw::*;
fn sensor(bytes: &[u8]) -> Sensor {
@@ -99,8 +99,8 @@ fn monochrome_linear_raw_develops_to_neutral_grey() {
("LJ92 strips", 14, DngStorage::Lj92Strips { rows: 6 }),
("LJ92 tiles", 16, DngStorage::Lj92Tiles { width: 16, height: 8 }),
("deflate predictor 2", 16, DngStorage::DeflateStrips { rows: 7, predictor: 2 }),
- // One whole tile: a partial edge tile is a separate decoder limitation.
- ("lossy JPEG tile", 16, DngStorage::LossyJpegTiles { width: 37, height: 23 }),
+ ("lossy JPEG tiles", 8, DngStorage::LossyJpegTiles { width: 16, height: 8 }),
+ ("lossy JPEG strips", 8, DngStorage::LossyJpegStrips { rows: 5 }),
];
for (name, bits, storage) in cases {
let white = ((1u32 << bits) - 1) as u16;
@@ -109,7 +109,7 @@ fn monochrome_linear_raw_develops_to_neutral_grey() {
spec.bits = bits;
spec.white = u32::from(white);
spec.storage = storage;
- let lossy = matches!(storage, DngStorage::LossyJpegTiles { .. });
+ let lossy = matches!(storage, DngStorage::LossyJpegTiles { .. } | DngStorage::LossyJpegStrips { .. });
let s = sensor(&spec.build());
assert_eq!((s.samples, s.cfa.is_none(), s.is_monochrome()), (1, true, true), "{name}");
if !lossy {
@@ -712,87 +712,236 @@ fn profile_gain_table_map_is_reported() {
assert!(gain_table(&sensor(&spec.build())));
}
-/// Adobe DNG compression 34892 (lossy baseline JPEG, 8-bit luma tiles): decodes to the tile
-/// samples widened to 16 bits, within the JPEG quality band (Q60 artifacts are mild but real).
+// ---------------------------------------------------------------- lossy DNG (compression 34892)
+
+/// The largest difference between decoded and source samples, in stored (8-bit) levels.
+fn worst_diff(got: &[u16], want: &[u16]) -> u16 {
+ assert_eq!(got.len(), want.len());
+ got.iter().zip(want).map(|(g, w)| g.abs_diff(*w)).max().unwrap_or(0)
+}
+
+/// An 8-bit lossy DNG around `data` (every value below 256): BitsPerSample 8, WhiteLevel 255.
+fn lossy_spec(w: usize, h: usize, data: Vec<u16>, storage: DngStorage) -> DngSpec {
+ assert!(data.iter().all(|&v| v <= 255));
+ let mut spec = DngSpec::cfa(w, h, data);
+ spec.bits = 8;
+ spec.white = 255;
+ spec.storage = storage;
+ spec
+}
+
+/// Adobe DNG compression 34892 (DNG 1.4 lossy JPEG): a CFA image whose tiles or strips are
+/// baseline JPEGs of 8-bit gray samples. They decode as the stored values (0..255, like any
+/// other 8-bit raw: levels and the linearization table apply afterwards), within the JPEG
+/// quality band (Q60 artifacts are mild but real), from whole and partial edge tiles and
+/// from strips with a short last strip.
#[test]
-fn lossy_jpeg_tiles_decode() {
- let (w, h) = (32, 32);
+fn lossy_jpeg_cfa_tiles_and_strips_decode_stored_values() {
+ let (w, h) = (37, 23); // odd: partial edge tiles and a short last strip
// A smooth ramp: baseline JPEG at Q60 keeps it within a few quantisation steps.
- let data: Vec<u16> = (0..w * h).map(|i| 4096 + (i / w) as u16 * 16).collect();
- let mut spec = DngSpec::cfa(w, h, data.clone());
- spec.storage = DngStorage::LossyJpegTiles { width: 16, height: 16 };
- let s = sensor(&spec.build());
- assert_eq!((s.width, s.height, s.samples), (w, h, 1));
- let mut worst = 0u32;
- for (got, want) in s.data.iter().zip(&data) {
- // The tile was written 8-bit (>>8), so the quantised expectation is (want>>8)<<8.
- let quant = u32::from(*want >> 8) << 8;
- worst = worst.max(u32::from(got.abs_diff(quant as u16)));
+ let data: Vec<u16> = (0..w * h).map(|i| ((i % w) * 5 + (i / w) * 2) as u16).collect();
+ let cases = [
+ ("16x8 tiles", DngStorage::LossyJpegTiles { width: 16, height: 8 }),
+ ("one tile", DngStorage::LossyJpegTiles { width: 37, height: 23 }),
+ ("strips of 5", DngStorage::LossyJpegStrips { rows: 5 }),
+ ("one strip", DngStorage::LossyJpegStrips { rows: 23 }),
+ ];
+ for (name, storage) in cases {
+ let bytes = lossy_spec(w, h, data.clone(), storage).build();
+ assert_eq!(identify(&bytes), Some(RawFormat::Dng), "{name}");
+ let s = sensor(&bytes);
+ assert_eq!((s.width, s.height, s.samples, s.cfa.is_some()), (w, h, 1, true), "{name}");
+ assert_eq!(s.white, [255.0; 3], "{name}");
+ assert!(s.data.iter().all(|&v| v <= 255), "{name}: a sample above the 8-bit range");
+ let worst = worst_diff(&s.data, &data);
+ assert!(worst <= 4, "{name}: worst deviation from the source: {worst} levels");
+ let d = develop_sensor(&s, &DevelopOptions::default()).unwrap_or_else(|e| panic!("{name}: {e}"));
+ assert_eq!((d.width as usize, d.height as usize, d.rgb.len()), (w, h, w * h * 3), "{name}");
+ assert!(d.info.cfa.is_some(), "{name}");
}
- assert!(worst <= 4 * 256, "worst deviation from the 8-bit quantisation: {worst}");
+}
+
+/// A 3-sample LinearRaw lossy DNG (as Adobe writes them: demosaiced, YCbCr-coded JPEG tiles)
+/// decodes to the stored R, G, B, each channel at its own level, from tiles and strips.
+#[test]
+fn lossy_jpeg_linearraw_rgb_tiles_and_strips_decode_stored_values() {
+ let (w, h) = (37, 23);
+ // Channel offsets of 64 levels survive JPEG chroma quantisation at Q60; the ramp is smooth.
+ let data: Vec<u16> = (0..w * h * 3).map(|i| ((i / 3 % w) * 2 + i / 3 / w) as u16 + (i % 3) as u16 * 64).collect();
+ let cases = [
+ ("16x16 tiles", DngStorage::LossyJpegTiles { width: 16, height: 16 }),
+ ("one tile", DngStorage::LossyJpegTiles { width: 37, height: 23 }),
+ ("strips of 7", DngStorage::LossyJpegStrips { rows: 7 }),
+ ];
+ for (name, storage) in cases {
+ let mut spec = lossy_spec(w, h, data.clone(), storage);
+ spec.samples = 3;
+ let s = sensor(&spec.build());
+ assert_eq!((s.width, s.height, s.samples, s.cfa.is_none()), (w, h, 3, true), "{name}");
+ assert!(s.data.iter().all(|&v| v <= 255), "{name}: a sample above the 8-bit range");
+ let worst = worst_diff(&s.data, &data);
+ assert!(worst <= 8, "{name}: worst deviation from the source: {worst} levels");
+ // Each channel carries its own level: R and B stay apart everywhere.
+ for p in 0..w * h {
+ let (r, b) = (s.data[p * 3], s.data[p * 3 + 2]);
+ assert!(b >= r + 64 - 8, "{name}: channels collapsed at pixel {p}: R {r}, B {b}");
+ }
+ let d = develop_sensor(&s, &DevelopOptions::default()).unwrap_or_else(|e| panic!("{name}: {e}"));
+ assert_eq!((d.width as usize, d.height as usize, d.rgb.len()), (w, h, w * h * 3), "{name}");
+ }
+}
+
+/// The decoded 8-bit values are the stored samples, so WhiteLevel defaults to 255 when absent,
+/// BlackLevel / WhiteLevel scale them and a LinearizationTable maps them, exactly as for an
+/// uncompressed 8-bit DNG. Flat images keep the comparison inside the JPEG's DC rounding.
+#[test]
+fn lossy_jpeg_levels_and_linearization_apply_to_stored_values() {
+ let (w, h) = (24, 16);
+ let tiles = DngStorage::LossyJpegTiles { width: 16, height: 8 };
+ let flat = |v: u16| vec![v; w * h];
+ let grey = |d: &Developed| d.rgb.chunks(3).map(|p| p[0]).collect::<Vec<u16>>();
+
+ // No WhiteLevel: 255 is white. A flat 255 develops to full white, a flat 0 to black.
+ for (v, lo, hi) in [(255u16, 65000u16, 65535u16), (0, 0, 300)] {
+ let mut spec = DngSpec::monochrome(w, h, flat(v));
+ spec.bits = 8;
+ spec.white = 0;
+ spec.storage = tiles;
+ let s = sensor(&spec.build());
+ assert_eq!(s.white, [255.0; 3]);
+ let d = develop_sensor(&s, &DevelopOptions::default()).unwrap();
+ assert!(grey(&d).iter().all(|&g| (lo..=hi).contains(&g)), "flat {v}: {:?}", &grey(&d)[..4]);
+ }
+
+ // BlackLevel 20 / WhiteLevel 220 scale the stored values like the uncompressed path.
+ let levels = |storage: DngStorage| {
+ let mut spec = DngSpec::monochrome(w, h, flat(200));
+ spec.bits = 8;
+ spec.black = vec![20];
+ spec.white = 220;
+ spec.storage = storage;
+ let s = sensor(&spec.build());
+ assert_eq!((s.white, s.black.at(0, 0, 0, 1)), ([220.0; 3], 20.0));
+ grey(&develop_sensor(&s, &DevelopOptions::default()).unwrap())
+ };
+ let (lossy, plain) = (levels(tiles), levels(DngStorage::Strips { rows: h }));
+ assert!(plain[0] > 50_000 && plain[0] < 65_000, "{}", plain[0]);
+ let worst = worst_diff(&lossy, &plain);
+ assert!(worst <= 600, "levels: lossy and uncompressed differ by {worst}");
+
+ // A LinearizationTable indexed by the stored value. It is flat around 200, so the JPEG's
+ // DC rounding (199 or 200) lands on the same output: the two paths develop identically.
+ let table: Vec<u16> = (0..256u32).map(|v| if (190..=210).contains(&v) { 40_000 } else { (v * 257) as u16 }).collect();
+ let linearized = |storage: DngStorage| {
+ let mut spec = DngSpec::monochrome(w, h, flat(200));
+ spec.bits = 8;
+ spec.white = 0;
+ spec.linearization = Some(table.clone());
+ spec.storage = storage;
+ let s = sensor(&spec.build());
+ assert_eq!(s.linearization.as_deref(), Some(table.as_slice()));
+ assert_eq!(s.white, [65535.0; 3], "the table's maximum is white");
+ grey(&develop_sensor(&s, &DevelopOptions::default()).unwrap())
+ };
+ let (lossy, plain) = (linearized(tiles), linearized(DngStorage::Strips { rows: h }));
+ assert!(plain[0] > 40_000 && plain[0] < 60_000, "{}", plain[0]);
+ assert_eq!(lossy, plain, "linearization: the lossy path differs from the uncompressed one");
}
/// A lossy JPEG tile cut mid-stream fails cleanly.
#[test]
-fn lossy_jpeg_tiles_hostile() {
+fn lossy_jpeg_truncated_tile_errors() {
let (w, h) = (32, 32);
- let data: Vec<u16> = (0..w * h).map(|_i| 8192u16).collect();
- let mut spec = DngSpec::cfa(w, h, data);
- spec.storage = DngStorage::LossyJpegTiles { width: 32, height: 32 };
- let bytes = spec.build();
+ let bytes = lossy_spec(w, h, vec![128; w * h], DngStorage::LossyJpegTiles { width: 32, height: 32 }).build();
let at = bytes.windows(2).position(|w| w == [0xFF, 0xD8]).expect("jpeg SOI") + 2;
let cut = &bytes[..at + (bytes.len() - at) / 2];
- assert!(decode(cut, &Limits::default()).is_err(), "a cut JPEG tile must not decode");
+ assert!(matches!(decode(cut, &Limits::default()), Err(RawError::Malformed(_))), "a cut JPEG tile must not decode");
}
-/// A tile JPEG whose header lies about its size fails the header check, before any pixel
-/// decode (a hostile SOF must not be able to size the decoder's buffers first).
+/// A tile JPEG whose header disagrees with the tile size fails the header check, before any
+/// pixel decode (a hostile SOF must not be able to size the decoder's buffers first).
#[test]
fn lossy_jpeg_tile_dimension_mismatch_errors() {
- use image::ImageEncoder as _;
let (w, h) = (32, 32);
- let data: Vec<u16> = (0..w * h).map(|i| 4096 + (i / w) as u16 * 16).collect();
- let mut spec = DngSpec::cfa(w, h, data);
- spec.storage = DngStorage::LossyJpegTiles { width: 32, height: 32 };
- let mut bytes = spec.build();
- // Swap the 32x32 tile JPEG for a 16x16 one, inside the same segment (the trailing bytes
- // after its EOI stay; the JPEG decoder stops at EOI).
- let small = {
- let img = image::GrayImage::from_fn(16, 16, |x, _| image::Luma([(x as u16 * 16) as u8]));
- let mut j = Vec::new();
- let enc = image::codecs::jpeg::JpegEncoder::new_with_quality(&mut j, 60);
- enc.write_image(img.as_raw(), 16, 16, image::ExtendedColorType::L8).unwrap();
- j
- };
- let soi = bytes.windows(3).position(|w| w == [0xFF, 0xD8, 0xFF]).expect("SOI");
- let eoi = soi + bytes[soi..].windows(2).position(|w| w == [0xFF, 0xD9]).expect("EOI") + 2;
- bytes.splice(soi..eoi, small);
- let err = decode(&bytes, &Limits::default()).unwrap_err().to_string();
+ let mut spec = lossy_spec(w, h, vec![100; w * h], DngStorage::LossyJpegTiles { width: 32, height: 32 });
+ let small: Vec<u8> = (0..16 * 16).map(|i| (i % 16 * 16) as u8).collect();
+ spec.lossy_segments = vec![baseline_jpeg(&small, 16, 16, 1)];
+ let err = decode(&spec.build(), &Limits::default()).unwrap_err().to_string();
assert!(err.contains("16x16") && err.contains("32x32"), "{err}");
+ // A tile coded at the image's row count instead of the tile's is tolerated (a strip-like
+ // encoder); anything else is not.
+ let (w, h) = (16, 12);
+ let mut spec = lossy_spec(w, h, vec![100; w * h], DngStorage::LossyJpegTiles { width: 16, height: 16 });
+ spec.lossy_segments = vec![baseline_jpeg(&[100u8; 16 * 12], 16, 12, 1)];
+ let s = sensor(&spec.build());
+ assert_eq!((s.width, s.height), (w, h));
+ assert!(s.data.iter().all(|&v| v.abs_diff(100) <= 2));
+ for (tw, th) in [(16, 14), (16, 18), (12, 16), (18, 16)] {
+ spec.lossy_segments = vec![baseline_jpeg(&vec![100u8; tw * th], tw, th, 1)];
+ assert!(matches!(decode(&spec.build(), &Limits::default()), Err(RawError::Malformed(_))), "{tw}x{th}");
+ }
+ // A strip must be coded at its own row count.
+ let mut spec = lossy_spec(w, h, vec![100; w * h], DngStorage::LossyJpegStrips { rows: 8 });
+ spec.lossy_segments = vec![baseline_jpeg(&[100u8; 16 * 8], 16, 8, 1), baseline_jpeg(&[100u8; 16 * 8], 16, 8, 1)];
+ assert!(matches!(decode(&spec.build(), &Limits::default()), Err(RawError::Malformed(_))));
}
-/// A 3-sample LinearRaw lossy DNG (YCbCr on disk, as real camera files are) decodes to RGB
-/// tiles widened to 16 bits, within the JPEG quality band; a LinearizationTable maps the
-/// decoded samples in the develop stage, so the sensor sees the raw widened values.
+/// A tile with the wrong number of JPEG components (a colour JPEG in a CFA DNG, a gray one in a
+/// 3-sample LinearRaw DNG) is rejected rather than silently converted.
#[test]
-fn lossy_jpeg_rgb_linearraw_decodes() {
- let (w, h) = (32, 32);
- // Channel offsets of 64 8-bit steps survive JPEG chroma quantisation at Q60.
- let data: Vec<u16> = (0..w * h * 3).map(|i| 4096 + ((i / (w * 3)) as u16 * 16) + (i % 3) as u16 * 64 * 256).collect();
- let mut spec = DngSpec::cfa(w, h, data.clone());
- spec.samples = 3;
- spec.storage = DngStorage::LossyJpegTiles { width: 16, height: 16 };
- let s = sensor(&spec.build());
- assert_eq!((s.width, s.height, s.samples), (w, h, 3));
- let mut worst = 0u32;
- for (got, want) in s.data.iter().zip(&data) {
- let quant = u32::from(*want >> 8) << 8;
- worst = worst.max(u32::from(got.abs_diff(quant as u16)));
+fn lossy_jpeg_component_count_mismatch_errors() {
+ let (w, h) = (16, 16);
+ let mut cfa = lossy_spec(w, h, vec![90; w * h], DngStorage::LossyJpegTiles { width: 16, height: 16 });
+ cfa.lossy_segments = vec![baseline_jpeg(&vec![90u8; w * h * 3], w, h, 3)];
+ let err = decode(&cfa.build(), &Limits::default()).unwrap_err();
+ assert!(matches!(&err, RawError::Malformed(m) if m.contains("3 components")), "{err}");
+
+ let mut rgb = lossy_spec(w, h, vec![90; w * h * 3], DngStorage::LossyJpegTiles { width: 16, height: 16 });
+ rgb.samples = 3;
+ rgb.lossy_segments = vec![baseline_jpeg(&vec![90u8; w * h], w, h, 1)];
+ let err = decode(&rgb.build(), &Limits::default()).unwrap_err();
+ assert!(matches!(&err, RawError::Malformed(m) if m.contains("1 components")), "{err}");
+}
+
+/// A SOF claiming a 65535x65535 frame inside a 16x16 tile is refused at the header, under the
+/// default limits as well as tight ones: the frame is never allocated.
+#[test]
+fn lossy_jpeg_oversized_frame_header_errors() {
+ let (w, h) = (16, 16);
+ let mut bytes = lossy_spec(w, h, vec![90; w * h], DngStorage::LossyJpegTiles { width: 16, height: 16 }).build();
+ let sof = bytes.windows(2).position(|m| m == [0xFF, 0xC0]).expect("SOF0");
+ // FF C0 | length (2) | precision (1) | height (2) | width (2)
+ bytes[sof + 5..sof + 9].copy_from_slice(&[0xFF, 0xFF, 0xFF, 0xFF]);
+ for limits in [Limits::default(), Limits { max_width: 64, max_height: 64, max_pixels: 1 << 12, max_alloc: 1 << 16 }] {
+ assert!(matches!(decode(&bytes, &limits), Err(RawError::Malformed(_))));
}
- assert!(worst <= 8 * 256, "worst deviation from the 8-bit quantisation: {worst}");
- // Each channel carries its own level: R and B stay apart everywhere.
- for p in 0..w * h {
- let (r, b) = (s.data[p * 3], s.data[p * 3 + 2]);
- assert!(r.abs_diff(b) >= 64 * 256 - 8 * 256, "channels collapsed at pixel {p}");
+ // The IFD cannot grow a tile past the limits either: a tile larger than the budget is
+ // refused before its JPEG is looked at.
+ let tight = Limits { max_width: 64, max_height: 64, max_pixels: 1 << 12, max_alloc: 1 << 10 };
+ let big = lossy_spec(40, 40, vec![90; 1600], DngStorage::LossyJpegTiles { width: 40, height: 40 }).build();
+ assert!(decode(&big, &tight).is_err());
+}
+
+/// DNG 1.4 stores lossy JPEG at 8 bits per sample; other depths and sample counts are reported
+/// as unsupported, not decoded as something else.
+#[test]
+fn lossy_jpeg_rejects_other_depths_and_sample_counts() {
+ let (w, h) = (16, 16);
+ let mut spec = DngSpec::cfa(w, h, vec![4000; w * h]);
+ spec.storage = DngStorage::LossyJpegTiles { width: 16, height: 16 };
+ for bits in [12u16, 16] {
+ spec.bits = bits;
+ spec.white = (1 << bits) - 1;
+ let err = decode(&spec.build(), &Limits::default()).unwrap_err();
+ assert!(matches!(&err, RawError::Unsupported(m) if m.contains(&format!("{bits}-bit"))), "{err}");
}
+ // Four samples per pixel (the IFD's claim; the JPEG itself is three-component).
+ let mut spec = lossy_spec(w, h, vec![90; w * h * 3], DngStorage::LossyJpegTiles { width: 16, height: 16 });
+ spec.samples = 3;
+ let mut bytes = spec.build();
+ let samples_tag = 277u16.to_le_bytes();
+ let at = bytes.windows(4).position(|e| e[..2] == samples_tag && e[2..] == 3u16.to_le_bytes()).expect("SamplesPerPixel entry");
+ bytes[at + 8] = 4;
+ let err = decode(&bytes, &Limits::default()).unwrap_err();
+ assert!(matches!(&err, RawError::Unsupported(m) if m.contains("4 samples")), "{err}");
}
diff --git a/crates/raw/tests/hostile.rs b/crates/raw/tests/hostile.rs
index 4b91f2f10..3212d554e 100644
--- a/crates/raw/tests/hostile.rs
+++ b/crates/raw/tests/hostile.rs
@@ -49,6 +49,21 @@ fn samples() -> Vec<Vec<u8>> {
out.push(m.build());
m.storage = DngStorage::DeflateStrips { rows: 5, predictor: 2 };
out.push(m.build());
+ // Lossy DNG (compression 34892): 8-bit baseline JPEG tiles of a CFA, and strips of LinearRaw RGB.
+ let mut l = DngSpec::cfa(w, h, cfa.iter().map(|&v| ((u32::from(v) - 64) * 255 / (4000 - 64)) as u16).collect());
+ l.bits = 8;
+ l.white = 255;
+ l.storage = DngStorage::LossyJpegTiles { width: 16, height: 8 };
+ l.active_area = Some([1, 2, 11, 22]);
+ out.push(l.build());
+ let rgb8: Vec<u16> = scene(w, h).iter().flat_map(|p| p.map(|v| (v * 255.0) as u16)).collect();
+ let mut l = DngSpec::cfa(w, h, rgb8);
+ l.samples = 3;
+ l.bits = 8;
+ l.white = 255;
+ l.linearization = Some((0..256u32).map(|v| (v * v / 4) as u16).collect());
+ l.storage = DngStorage::LossyJpegStrips { rows: 5 };
+ out.push(l.build());
let mut data = vec![600u16; 40 * 10];
for (i, v) in data.iter_mut().enumerate() {
*v = 600 + (i as u16 * 7) % 3000;
diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md
index 689d96520..6055bebae 100644
--- a/docs/file-format-parity.md
+++ b/docs/file-format-parity.md
@@ -1,6 +1,6 @@
# File-format parity
-> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-13 · **Change:** minor (lossy DNG, compression 34892, decodes with its levels and LinearizationTable applied to the stored 8-bit samples, FILE-215-11; CMYK Hue/Saturation and Color Balance keep the black ink; CMYK Posterize on the stored values, psd-tools oracle floor 242/309; CMYK adjustment layers composite on the document's inks; Photoshop-oracle floor 165/258; CMYK Brightness/Contrast on the inks, CMYK Threshold's luma; modern Brightness/Contrast's brightness curve; Photoshop-oracle floor 151/258; Lab documents composite on their stored L, a, b; Photoshop-oracle floor 152/258; Levels on whole levels at every step with Photoshop's shadow toe; Photoshop-oracle floor 146/258, psd-tools 238/309; 32-bit adjustments unclipped; Photoshop-oracle floor 149/258; mask feathers blur with their exact variance; Threshold splits on Photoshop's luminosity; a pass-through clipping base with an adjustment renders isolated; psd-tools oracle floor 240/309; 16-bit Posterize as Photoshop bins it; psd-tools oracle floor 241/309; Gradient Map luminosity; Photoshop-oracle floor 147/258; PSD: `Mt16`/`Mt32` merged transparency read; palette PNGs open in Indexed Color mode, #4804; earlier: CMYK Invert, Posterize and Threshold on the inks; 16-bit Lab Invert; Photoshop-oracle floor 145/258; `.atn` import maps 112 events; DDS textures open, #1327; DPX read and write, #1049; #2465 fixed: CS2 placed layers with only a `PlLd` block open their contents; Photoshop Actions `.atn` read and write; `.shc` contour files read and write; earlier the same day: indexed BMP palette mode; Save keeps a JPEG's quality and a WebP's encoding) · **Target:** Adobe Photoshop 2026
Every format Photoshop 2026 (27.11.0) reads or writes, with PhotoCraft's support, fidelity and
tests. Photoshop's list comes from its `Info.plist` `CFBundleDocumentTypes`, the PiPL read/write
@@ -63,7 +63,7 @@ supports many more, including CR3).
| Camera format | PhotoCraft | Evidence |
|---|---|---|
-| DNG (incl. LJPEG and JPEG XL tiles) | yes; lossy DNG no | FILE-215-11 |
+| DNG (incl. LJPEG, lossy JPEG and JPEG XL tiles) | yes | 2026-10-13: lossy DNG (DNG 1.4 compression 34892: 8-bit baseline JPEG tiles or strips, CFA and LinearRaw, partial edge tiles) decodes to the stored samples, which go through LinearizationTable / BlackLevel / WhiteLevel (default 255) like every other depth; `crates/raw/tests/dng.rs` `lossy_jpeg_*` (FILE-215-11, lossy DNG part; no lossy file in the raw corpus yet) |
| Canon CR2 | yes | |
| Canon CR3 | detected, unsupported | `crates/raw/src/lib.rs:219` |
| Nikon NEF/NRW (lossless, lossy) | yes; "lossy after split" no | #50; D5100 and D90 image areas measured (14-bit NEFs); [validation](nikon-nef-development.md) |
@@ -142,6 +142,7 @@ remaining gaps in #1606 stay tracked with per-sample corpus ceilings.
| Date | Change | Summary |
|---|---|---|
+| 2026-10-13 | minor | Lossy DNG (compression 34892) decodes: 8-bit baseline JPEG tiles and strips, CFA and LinearRaw, partial edge tiles; the stored values take the normal levels and LinearizationTable (FILE-215-11, lossy DNG part) |
| 2026-10-14 | minor | Corpus floors raised to the measured results of the CMYK, Lab, 32-bit, Levels, Threshold, Posterize, feather and pass-through fixes landed together: Photoshop-authored 165 → 185 of 258, io 146 → 148 of 170, psd-tools 242 → 249 of 309 |
| 2026-10-13 | minor | CMYK Hue/Saturation (not Colorize) and Color Balance work on C, M and Y as inverted RGB with black kept, on the inks for display, export and destructive edits; cmyk8/16 hue-saturation 100% → 0.4–0.7% bad pixels, color-balance 74% → 25% |
| 2026-10-13 | minor | CMYK Posterize works on the stored values (1 − ink), as Photoshop does: psd-tools posterize_cmyk passes (13.8 % → 0 of pixels off on the ink path); psd-tools floor → 242 of 309 |