Saliency-based smart crop #2

Merged
zyberzero merged 5 commits from smart-crop into main 2026-11-03 18:12:20 +00:00
Showing only changes of commit d910187c53 - Show all commits
+8 -2
View File
@@ -105,16 +105,22 @@ Each type lives in `src/FrameProcessor/Domain/`. Tests in `tests/FrameProcessor.
### [x] 3.3 `IImagePipeline` + `ImagePipeline` ### [x] 3.3 `IImagePipeline` + `ImagePipeline`
- Single method: `byte[] Process(Stream input, Frame frame)`. - 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. - Output dimensions always match the frame's *declared* `width × height` regardless of orientation.
### [x] 3.4 `ImagePipelineTests` golden fixtures ### [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/<algo>/<input>.png`. - Generate expected outputs once, commit under `Fixtures/expected/<algo>/<input>.png`.
- Assert byte-equality of produced PNG vs golden. - Assert byte-equality of produced PNG vs golden.
- Run for all four dithering algorithms against the canonical Spectra 6 palette. - Run for all four dithering algorithms against the canonical Spectra 6 palette.
- **DoD:** `dotnet test` green; deleting a fixture output and rerunning fails loud. - **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 ## Phase 4 — Storage