From d910187c53b631527106d57596071c83673e27d8 Mon Sep 17 00:00:00 2001 From: Fritiof Hedman Date: Tue, 3 Nov 2026 19:04:42 +0100 Subject: [PATCH] Document smart crop in IMPLEMENTATION.md Co-Authored-By: Claude Opus 5.5 (1M context) --- IMPLEMENTATION.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/IMPLEMENTATION.md b/IMPLEMENTATION.md index add3577..423710e 100644 --- a/IMPLEMENTATION.md +++ b/IMPLEMENTATION.md @@ -105,16 +105,22 @@ Each type lives in `src/FrameProcessor/Domain/`. Tests in `tests/FrameProcessor. ### [x] 3.3 `IImagePipeline` + `ImagePipeline` - Single method: `byte[] Process(Stream input, Frame frame)`. -- Steps (`SPEC.md` §3.2): decode → resize (cover/center-crop to oriented resolution) → dither against display palette → remap pixels display→device → rotate 90° CW if portrait → encode indexed PNG (`PngColorType.Palette`, smallest bit depth fitting the palette, `PaletteQuantizer(deviceColors)`). +- Steps (`SPEC.md` §3.2): decode → smart crop to oriented aspect (see 3.5) → resize to oriented resolution → dither against display palette → remap pixels display→device → rotate 90° CW if portrait → encode indexed PNG (`PngColorType.Palette`, smallest bit depth fitting the palette, `PaletteQuantizer(deviceColors)`). - Output dimensions always match the frame's *declared* `width × height` regardless of orientation. ### [x] 3.4 `ImagePipelineTests` golden fixtures -- Check in `tests/FrameProcessor.Tests/Fixtures/inputs/` (landscape.jpg, portrait.jpg, tiny-1x1.png, non-divisible.jpg). +- Check in `tests/FrameProcessor.Tests/Fixtures/inputs/` (landscape.jpg, portrait.jpg, tiny-1x1.png, non-divisible.jpg, asymmetric-edges.jpg). - Generate expected outputs once, commit under `Fixtures/expected//.png`. - Assert byte-equality of produced PNG vs golden. - Run for all four dithering algorithms against the canonical Spectra 6 palette. - **DoD:** `dotnet test` green; deleting a fixture output and rerunning fails loud. +### [x] 3.5 Smart crop (`PLAN.md` "Smart cropping") +- `ISmartCropper` + `SaliencySmartCropper`: Sobel edge density on a 256 px analysis canvas, summed-area table, slide the max-fitting target-aspect window, keep the highest-energy position. +- Same-aspect inputs return full bounds; any exception logs a warning and falls back to the centered max-fitting crop. +- `ImagePipeline` applies the crop, then a pure `Resize` to the oriented resolution. +- **Tests:** `SaliencySmartCropperTests` (bias on both axes, edge-hugging subject, bounds/aspect); `asymmetric-edges.jpg` golden fixture. + --- ## Phase 4 — Storage