Skip to content

Merge a color into a touching or similar one, pick colors from the image, and dim the rest - #254

Merged
vycdev merged 10 commits into
developfrom
t3/swatch-merge-into
Nov 30, 2026
Merged

vycdev merged 10 commits into
developfrom
t3/swatch-merge-into

Conversation

@vycdev

@vycdev vycdev commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Cleaning up colors meant guessing. You couldn't see where a 0.1% blur tone sat in the image or click it to find its swatch. Delete re-ran quantization with the remaining colors as a palette: it matched the target by RGB only and made every partly transparent pixel opaque.

Now a color can be merged into a neighbor in one click, with a preview first. This is decisions 2 and 3 (option A) of the approved color-cleanup plan.

Merge into…

  • Clicking a swatch, in the grid or list view, opens a popover with suggested targets:
    • Touching it in the image: colors that share a pixel edge with it. For a blur tone, these are the regions it sits between.
    • Closest colors: the nearest by CIEDE2000, plus any alpha difference.
  • Clicking the image picks any other color as the target, including colors beyond the listed swatches.
  • While a target is chosen, the canvas previews the merge, with a zoomed before/after inset where the color is densest. Merge into #… applies it as one Undo step.
  • Recolor… keeps today's color picker. Delete is gone; Merge replaces it.

Merging is a direct pixel remap, in the React-free src/lib/colorMerge.ts:

  • Only that color's pixels change, written as the target's exact RGBA.
  • Nothing is requantized. Every other pixel, partly transparent ones included, keeps its exact bytes. This fixes both Delete bugs.
  • Recolor uses the same remap. It now reads the canvas directly instead of round-tripping through a PNG.
  • The override-palette quantize path, which only Delete used, is removed.

Merge safety

  • A merge holds the same image-edit lock as Quantize, so Undo, Redo, Quantize, crop and imports wait for it.
  • It won't start while a touch-up is still being saved, so a stroke keeps its own Undo step.
  • A selection belongs to the image it was made on. A new image, an edit or Undo closes the popover.

Pick from image and highlight

  • With the Image colors card open, Pick from image turns the canvas into an eyedropper that opens the clicked pixel's swatch. It shows the hovered color's hex and share, and Escape leaves it.
  • Hovering, opening, or keyboard-focusing a swatch dims every other color to about a third of its brightness. The highlight is dim only, with no outline toggle.
  • The highlight and the preview keep live, unapplied adjustments.
  • Pick and the popover are off during crop, processing, touch-up tools and recounts.

Screenshots (1600×1600 test image after K-means at 64 colors; #411822 is a 0.1% blur tone)

Dark Light
Before: Delete dialog before dark before light
After: hover dims the rest dim dark dim light
After: Merge into… with live preview and inset merge dark merge light

Tests

  • tests/colorMerge.test.ts:
    • only the chosen color's pixels change;
    • alpha is preserved: same-RGB colors at other alphas, transparent pixels, and a semi-transparent target;
    • a merge changes exactly the pixels it reports, so the previous history image undoes it;
    • touching and closest suggestions, including the tie order;
    • the inset window and dimming.
  • @smoke tests/e2e/image-colors-merge.spec.ts:
    • pick from image selects the right swatch, and Escape leaves pick mode;
    • hover dims the rest;
    • merging into a touching color drops the count by one and leaves the other swatches unchanged;
    • every pixel outside the merged ones is identical, and one Undo restores the image pixel for pixel; Redo merges again;
    • list view: merge into a semi-transparent target that no suggestion offers, picked on the canvas, keeps its alpha and undoes in one step;
    • Recolor focus handling, and Recolor with alpha 0, then Undo.
  • The Delete-with-Posterize smoke test is removed along with Delete. The i18n color-picker test opens the picker through Recolor….
  • Local runs: lint, tsc -b, npm test, test:i18n, check:i18n, test:docs, and test:e2e:all on KROMACUT_E2E_PORT=49863.

Docs and locales are updated in all 12 languages:

#219's worker is still a draft, so the remap runs on the main thread. It is one scan per selection and one per merge.

Council review

Rounds: 7

Delegate Round 1 Round 2 Round 3 Round 4 Round 5 Round 6 Round 7
Claude Opus 5.5 7.5/10 8.5/10 8.5/10 8/10 8.5/10 9/10 9/10
GPT-6.2 Sol 6/10 7/10 7/10 7/10 8/10 8/10 8.5/10
Gemini Pro unavailable unavailable unavailable unavailable unavailable unavailable unavailable

Fixed along the way:

  • races between a saving merge and Quantize, crop, Undo, imports and touch-ups;
  • selections carrying over to a new image, and colors picked beyond the swatch cap;
  • crop gating;
  • keyboard focus around the popover, Recolor and the recount;
  • large-image cost: one scan per lookup, reused buffers, a delay before hover rebuilds, and top-N suggestions;
  • readback failures;
  • adjustments in the preview;
  • a pixel-exact Undo test.

Declined:

  • Moving the merge preview's adjustment pass off the main thread: it runs only with unapplied adjustments, at about 0.5 s per target change on a 4096² image.
  • Chunking the per-selection scan, or a compact neighbor counter for noise images with millions of distinct neighbors: it runs once per click.
  • Feedback when Merge is clicked while a touch-up is still saving: the wait is one PNG encode, and the popover closes when the stroke lands.
  • Diagram and troubleshooting rewording: the footnote already covers merging into the transparent swatch, and the advice about quantizing partly transparent pixels still holds for cutouts.
  • "Closest colors" wording for images over 16,384 colors: the row ranks the cached swatches.

Created with Claude Opus 5.5 in Claude Code (T3 Code). Doc translations by a Claude Opus 5.5 subagent; reviews by Claude Opus 5.5 and GPT-6.2 Sol.

🤖 Generated with Claude Code

vycdev and others added 10 commits November 30, 2026 18:38
…m the rest

Clicking a swatch opens a "Merge into…" popover with touching and
closest-ΔE targets, or any color clicked on the image, previews the
merge live on the canvas with a before/after inset, and applies it as
one Undo step. Recolor… keeps the color picker. Pick from image turns
the canvas into an eyedropper that selects a pixel's swatch, and
hovering or opening a swatch dims every other color.

Merge replaces Delete and rewrites only that color's pixels as exact
RGBA (src/lib/colorMerge.ts): no requantize, the target's alpha is
kept, and partly transparent pixels elsewhere stay as they were.
Recolor shares the remap. The override-palette quantize path that
only Delete used is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A merge in progress blocks another one; crop and processing close the
popover and disable Pick from image; colors are kept as RGBA, so a
color picked beyond the listed swatches is a valid source or target.
The highlight and merge preview keep live adjustments, reuse one
readback, buffer and source scan per selection, and rebuild a hover
after it settles. Only keyboard focus highlights a swatch; Recolor
moves focus into the picker and back. Escape in another dialog no
longer leaves pick mode. The browser test now compares every pixel
before the merge, after it, and after Undo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A selection and its target belong to the committed image they were
chosen on, so a new image, an edit, or Undo closes the popover instead
of carrying a merge over, and the canvas only samples pixels once the
current image has loaded. A merge holds the shared image-edit lock
while it encodes, and Undo, Redo, Quantize, crop, file picks, and the
sidebar wait for it. Dismissing the popover by clicking elsewhere keeps
that control's focus. The inset copies only its own area, pick mode
frees its pixel copy when it ends, and the unused override-palette
progress string is removed. The list-view browser test now merges
into a semi-transparent color picked on the canvas that no suggestion
row offers, and checks its alpha and Undo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A merge waits for touch-ups still being saved, so a stroke keeps its
own Undo step, then takes the edit lock from the latest render. An
open Recolor dialog closes when the image changes. Touching
suggestions keep only the top four while tallying, focus falls back to
the colors list when the opened color has no listed swatch, touch-up
tools draw on the live image instead of a highlight, and the pick-mode
cache release no longer rebuilds the highlight. The list-view browser
test now applies Recolor with alpha 0 and undoes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge and Recolor take the edit lock at once, on the image the
selection belongs to, and don't start while a touch-up is still being
saved; the popover or dialog then stays open, and the stroke landing
closes it like any edit. This replaces waiting for the touch-up, which
could drop the merge or move it to another image. Focus stays in the
card while the colors are recounted, Recolor closing on an image change
keeps focus there too, touching ties compare packed colors, and the
leftover slice is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A failed readback releases the edit lock and leaves the popover open, a
stroke still being drawn counts as pending, Recolor Apply keeps focus in
the card through the recount, and a selection made on an earlier image
is dropped so it doesn't keep that image's pixels alive. Adds a unit
test for the touching tie order with alpha variants and transparency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A full-image readback that fails leaves the normal canvas and editing
alone instead of throwing during render, the focus-return flag resets
whenever another swatch opens, the popover scrolls within the space a
short window leaves, and picking waits while the colors are recounted
after an edit, so a picked color always opens its popover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Council round 7 nits: a full-image readback that failed on this image
isn't retried on every pointer move, and picking falls back to reading
the one pixel; clearing a canvas-picked target chip moves focus to the
popover's close button.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A swatch now opens Merge into…, so the test clicks Recolor… first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vycdev
vycdev force-pushed the t3/swatch-merge-into branch from 854f848 to 0a722aa Compare November 30, 2026 16:38
@vycdev
vycdev merged commit 5fcf0e0 into develop Nov 30, 2026
14 checks passed
vycdev added a commit that referenced this pull request Nov 30, 2026
After #254, a swatch merge or recolor holds the image-edit lock through
imageEditBusy, and refuses to start while a touch-up stroke is saved.
Block Clean edges and Merge small colors on the same conditions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant