diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index eee9bb36..986f1c53 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -55,3 +55,8 @@ One line per decision: date · decision · alternative · reason. | 2026-10-02 | GIF: Wu-criterion median cut, frame differencing against the source last drawn, identical frames merged by holding one back. | Plain median cut / diff against dithered output | Max palette error 37 → small; 945 KB → 52 KB at equal PSNR; exact delays. | | 2026-10-02 | AVI always carries OpenDML indexes plus idx1 (1 GiB RIFF segments). | idx1 only | Files beyond 2 GB stay playable. | | 2026-10-02 | MF encoder capabilities: software H.264 ≤ 4096×2304, hardware assumed 4096² (H.264) / 8192² (HEVC/AV1); an unsupported size fails at media-type negotiation and the next encoder is tried. | Querying limits | MF has no reliable capability query. | +| 2026-10-02 | Full-size JPEG IDCT is a port of libjpeg's accurate integer IDCT (bit-identical to djpeg); reduced-size (1/2–1/8) decoding uses float IDCTs with triangle chroma upsampling. | SIMD float IDCT everywhere | Float produced rare ±3 differences after YCbCr; reduced sizes gain 6.7 dB with triangle upsampling. | +| 2026-10-02 | Codecs throw only `InvalidDataException` for bad structure or unsupported features; damaged scan data yields a partial image plus warnings. | NotSupportedException for features | One exception type for callers and fuzzing. | +| 2026-10-02 | Linear DNG export: raw image in IFD0, lossless-JPEG tiles, ColorMatrix1 + ForwardMatrix1 for Rec.709 D65; source camera Make/Model kept when Exif is supplied. | Preview IFD + SubIFD raw | Simplest valid DNG; LibRaw renders test patches back exactly. | +| 2026-10-02 | Resampler keeps negative/overshoot values in linear light. | Clamp to 0–1 | Ringing stays within each kernel's exact bound; clamping happens at encode. | +| 2026-10-02 | Codec fixtures (each < 12 KB) are generated by `tests/fixtures/codecs/make-fixtures.sh` with libjpeg-turbo/libtiff dev tools and committed. | Fetch at test time | Reference outputs must be stable; the tools are not build or runtime dependencies. | diff --git a/src/Titano.Core/Codecs/Jpeg/JpegEncoder.cs b/src/Titano.Core/Codecs/Jpeg/JpegEncoder.cs index e65fb43a..bbddbf19 100644 --- a/src/Titano.Core/Codecs/Jpeg/JpegEncoder.cs +++ b/src/Titano.Core/Codecs/Jpeg/JpegEncoder.cs @@ -133,7 +133,13 @@ public static class JpegEncoder var mcusY = JpegParser.DivUp(height, 8 * vy); var plan = new Plan { - Width = width, Height = height, Components = components, HY = hy, VY = vy, McusX = mcusX, McusY = mcusY, + Width = width, + Height = height, + Components = components, + HY = hy, + VY = vy, + McusX = mcusX, + McusY = mcusY, Quant = [ScaleTable(JpegTables.LumaQuant, o.Quality), ScaleTable(JpegTables.ChromaQuant, o.Quality)], Coefficients = new short[components][], }; diff --git a/src/Titano.Core/Codecs/Jpeg/JpegParser.cs b/src/Titano.Core/Codecs/Jpeg/JpegParser.cs index ec660afd..554583ff 100644 --- a/src/Titano.Core/Codecs/Jpeg/JpegParser.cs +++ b/src/Titano.Core/Codecs/Jpeg/JpegParser.cs @@ -301,8 +301,15 @@ internal sealed class JpegParser(JpegDecodeOptions options) } Frame = new JpegFrame { - Process = process, Precision = precision, Width = width, Height = height, Components = components, - HMax = hMax, VMax = vMax, McusX = mcusX, McusY = mcusY, + Process = process, + Precision = precision, + Width = width, + Height = height, + Components = components, + HMax = hMax, + VMax = vMax, + McusX = mcusX, + McusY = mcusY, }; } diff --git a/src/Titano.Core/Codecs/Jpeg/JpegRenderer.cs b/src/Titano.Core/Codecs/Jpeg/JpegRenderer.cs index 2bbe45cf..5004a96e 100644 --- a/src/Titano.Core/Codecs/Jpeg/JpegRenderer.cs +++ b/src/Titano.Core/Codecs/Jpeg/JpegRenderer.cs @@ -309,28 +309,28 @@ internal sealed class JpegRenderer YccToRgb(rows, ycc!, w, max); break; case JpegColorSpace.Cmyk or JpegColorSpace.Ycck: - { - if (_colorSpace == JpegColorSpace.Ycck) { - YccToRgb(rows, ycc!, w, max); + if (_colorSpace == JpegColorSpace.Ycck) + { + YccToRgb(rows, ycc!, w, max); + for (var c = 0; c < 3; c++) + { + var r = rows[c]; + for (var x = 0; x < w; x++) r[x] = max - r[x]; + } + } + var k = rows[3]; + var half = max / 2; for (var c = 0; c < 3; c++) { var r = rows[c]; - for (var x = 0; x < w; x++) r[x] = max - r[x]; + for (var x = 0; x < w; x++) + { + r[x] = _invertedCmyk ? (r[x] * k[x] + half) / max : ((max - r[x]) * (max - k[x]) + half) / max; + } } + break; } - var k = rows[3]; - var half = max / 2; - for (var c = 0; c < 3; c++) - { - var r = rows[c]; - for (var x = 0; x < w; x++) - { - r[x] = _invertedCmyk ? (r[x] * k[x] + half) / max : ((max - r[x]) * (max - k[x]) + half) / max; - } - } - break; - } } } diff --git a/src/Titano.Core/Codecs/Jpeg/JpegScanDecoder.cs b/src/Titano.Core/Codecs/Jpeg/JpegScanDecoder.cs index 3bd8b679..8a446dee 100644 --- a/src/Titano.Core/Codecs/Jpeg/JpegScanDecoder.cs +++ b/src/Titano.Core/Codecs/Jpeg/JpegScanDecoder.cs @@ -107,13 +107,13 @@ internal static class JpegScanDecoder DecodeSequential(ref r, block, scan.DcTables[index]!, scan.AcTables[index]!, ref c.DcPred); break; case Kind.DcFirst: - { - var t = r.Decode(scan.DcTables[index]!); - if (t > 16) throw new JpegEntropyException("JPEG: bad DC magnitude"); - c.DcPred += t == 0 ? 0 : r.Receive(t); - block[0] = (short)(c.DcPred * (1 << scan.Al)); - break; - } + { + var t = r.Decode(scan.DcTables[index]!); + if (t > 16) throw new JpegEntropyException("JPEG: bad DC magnitude"); + c.DcPred += t == 0 ? 0 : r.Receive(t); + block[0] = (short)(c.DcPred * (1 << scan.Al)); + break; + } case Kind.DcRefine: if (r.ReadBit() != 0) block[0] |= (short)(1 << scan.Al); break;