Skip to content

F14.1b — Generate a bounded palette and numbered guide buffer #305

Description

@Flow-Fly

Parent: #129. Depends on the sampled grid from the previous F14.1 child.

Scope

Convert sampled grid pixels into a deterministic generated palette and a one-based numbered guide buffer.

Implementation

  • Add a pure palette-reduction module under src/services/paint-by-number/.
  • Accept sampled ImageData plus a maximum generated color count.
  • Use a deterministic bounded quantization strategy suitable for small grids.
  • Map transparent cells to index 0.
  • Map opaque cells to palette indices 1..N using one consistent perceptual color-distance function.
  • Return { palette, target, width, height } with a compact typed target buffer.
  • Do not reuse extractColorsFromDrawing as if it were already a bounded quantizer; share only genuinely reusable color helpers.

Acceptance

  • The palette never exceeds the requested color count.
  • Every nonzero target index resolves to an existing palette entry.
  • Transparent cells remain 0.
  • Fixed fixtures produce stable palette and target hashes.
  • No project state or UI is introduced.

Verification

  • Targeted Vitest coverage
  • npm run lint
  • git diff --check

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions