test(raw): lossy-JPEG and floating-point DNGs, calibration and list-3 maps

Covers compression 34892 with a linearisation table (42.8 dB), Deflate
with the floating-point predictor for CFA and LinearRaw data,
CameraCalibration1 with AnalogBalance in the colour transform, and a
value-mapping opcode in OpcodeList3 applied to unbalanced values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 12:28:41 +00:00
1 parent bcf0510a8e
commit 248439956f
2 files changed
+112 -10

No files matched your search

@@ -49,6 +49,59 @@ public sealed class DngDecoderTests(TestContext context)
Assert.SequenceEqual(reference.Image.Data.ToArray(), result.Image.Data.ToArray());
}
[Test]
public void LossyJpegTilesWithLinearizationTable()
{
// Compression 34892: 8-bit JPEG tiles of sRGB-shaped codes, mapped back to linear by a 256-entry table.
var table = Enumerable.Range(0, 256).Select(i => (ushort)double.Round(ColorSpace.SrgbToLinear(i / 255.0) * 16383)).ToArray();
using var scene = SyntheticRaw.Smooth(W, H);
using var result = Decode(SyntheticDng.Write(scene, new DngSpec { Cfa = null, Compression = 34892, Linearization = table, Black = [0], TileSize = 32 }));
var psnr = SyntheticRaw.Psnr(scene, result.Image, 0);
context.Log($"lossy JPEG DNG: PSNR {psnr:F1} dB");
Assert.GreaterOrEqual(psnr, 36);
}
[Theory]
[Case(false)]
[Case(true)]
public void FloatingPointPredictorWithDeflate(bool mosaic)
{
using var scene = SyntheticRaw.Smooth(W, H);
using var result = Decode(SyntheticDng.Write(scene, new DngSpec { Cfa = mosaic ? CfaPattern.Bayer("RGGB") : null, FloatingPoint = true }));
Assert.GreaterOrEqual(SyntheticRaw.Psnr(scene, result.Image, 4), mosaic ? 40 : 60);
}
[Test]
public void CameraCalibrationAndAnalogBalanceEnterTheColourTransform()
{
var cc = Matrix3.Diagonal(1.08, 1.0, 0.93);
var ab = new Vector3D(1.05, 1.0, 0.97);
using var scene = SyntheticRaw.Smooth(W, H);
var spec = new DngSpec
{
Cfa = null,
CameraCalibration1 = cc,
AnalogBalance = ab,
CaptureMatrix = Matrix3.Diagonal(ab.X, ab.Y, ab.Z) * cc * SyntheticRaw.CameraMatrix,
};
using var result = Decode(SyntheticDng.Write(scene, spec));
Assert.GreaterOrEqual(SyntheticRaw.Psnr(scene, result.Image, 0), 55);
}
[Test]
public void ValueMappingOpcodesInListThreeSeeUnbalancedValues()
{
// Stored halved; MapPolynomial ×2 in OpcodeList3 restores the scene only if applied before white balance.
var ops = new OpcodeListBuilder().Add(8, 0, p =>
{
OpcodeListBuilder.Area(p, 0, 0, H, W, planes: 3);
p.U32(1).F64(0).F64(2);
}).Build();
using var scene = SyntheticRaw.Smooth(W, H);
using var result = Decode(SyntheticDng.Write(scene, new DngSpec { Cfa = null, OpcodeList3 = ops, RawTransform = (_, _, v) => v / 2 }));
Assert.GreaterOrEqual(SyntheticRaw.Psnr(scene, result.Image, 0), 55);
}
[Test]
public void LinearRawRoundTripsExactly()
{