Skip to content

Color spaces, pigment mixing and pen pressure: 3D Color Space, OKLab/pigment gradients, mix brush, tablet pressure + Pen Pressure panel - #147

Merged
grymmjack merged 9 commits into
mainfrom
claude/bold-brahmagupta-29e25j
Oct 3, 2026
Merged

grymmjack merged 9 commits into
mainfrom
claude/bold-brahmagupta-29e25j

Conversation

@grymmjack

@grymmjack grymmjack commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Uses QB64_GJ_LIB/COLOR and QB64_GJ_LIB/PRESSURE_DEVICE, both now on QB64_GJ_LIB main (grymmjack/QB64_GJ_LIB#27 and #29). The submodule points at main (23db828), so this PR can be merged on its own.

What's new

View → 3D Color Space (action 2024)

A floating panel that shows the sRGB gamut as a 3D solid you can spin, zoom, slice and pick from. It works in OKLab (default), CIELAB, XYZ or the RGB cube.

  • Controls: SOLID / CLOUD, a lightness SLICE, and readouts in hex, OKLab, OKLCh, CIELAB and XYZ.
  • Behaves like the other floating color panels: it auto-hides while you draw over it, hides and restores with F11, and remembers its settings (CFG.COLOR_SPACE_3D_*).

Gradient blending: OKLab (default) and Pigment

CFG.GRADIENT_BLEND_SPACE selects 0 sRGB (classic, byte-for-byte unchanged), 1 OKLab, 2 linear light, or 3 Pigment (paint). The blends are memoized in DRAWER_gradient_lerp_color~&.

Brush → Mix Colors (Pigment) (action 2026)

A mix brush with a smudge model after libmypaint, mixed with Kubelka–Munk pigment math. Blue dragged through yellow paints green.

  • How it works: before every dab it samples the layer as it was at stroke start, then draws pigment_mix(smudge color, brush color).
  • Settings: Smudge %, Smudge Length % and Smudge Radius %. Smudge 100 is a pure smudge tool.
  • Also works with: pixel-perfect mode (the release redraw replays each pixel's own color), undo, and raster export.

Pen tablet pressure (new)

INPUT/PEN wraps the new PRESSURE_DEVICE library. Its state variable is TABLET, because PEN is a QB64 keyword. A mouse is never affected.

  • Size by pressure: each frame's segment is drawn as one dab per pixel, sized from the pressure interpolated along the segment (PAINT_on_pressure). The width changes smoothly within a stroke.

  • Opacity by pressure (new; off by default):

    • each pixel is recomposited from a stroke-start snapshot at the strongest opacity reached there, so overlaps never compound;
    • it shows live while drawing;
    • it covers hard, AA and eraser pixels, using straight-alpha source-over so light strokes don't darken on empty pixels;
    • pattern and gradient holes leave pixels alone, and only erasing strokes erase. This fixes flicker and holes when drawing with patterns.
  • Mix paint by pressure: the paint each dab lays is scaled by pressure, from a lightest-touch amount up.

  • Tip threshold (default 3%): a pen that grazes the tablet registers clicks at almost no pressure. Nothing is drawn until the pen passes the threshold, and a stroke that never passes it records no undo step.

  • Clean stroke ends: readings below 2% hold the last real value, which avoids a blob at landing and a flick at lift-off.

  • Pressure curve: applies to all of the above.

  • View → Pen Pressure panel (action 2028, GUI/PEN-PANEL):

    • a live meter, with the tip threshold marked;
    • a checkbox and a lightest-touch slider each for size, opacity and mix;
    • a log-scale curve slider, a TIP slider, and a response graph with the live point.

    It uses the same frame model as the 3D Color Space panel (auto-hide while drawing over it, F11). Everything is also in Settings → General → Pen Tablet (CFG.PEN_*).

  • Brush outline only over the canvas: the brush, spray and custom-brush footprints are no longer drawn in the empty area around the canvas. The apron counts only mid-stroke.

  • Export: pressure-varied strokes export as raster.

Undo/redo fix (found while testing pressure opacity)

  • Undo and redo darkened translucent pixels. Every undo or redo made soft edges and translucent strokes darker and fainter: HISTORY_apply_layer_snapshot blended the snapshot onto the cleared layer, multiplying color by alpha. It's now an exact copy (_DONTBLEND), and the PNG-import fallback had the same fix.
  • Opacity strokes were stored too dark. STROKE_commit darkened strokes at less than 100% Opacity on empty pixels (50% white was stored as gray). It now interpolates in premultiplied space.
  • Verified under Xvfb: undo ×1/×3 and redo ×1/×3 match the original captures pixel for pixel, both with the mouse at 50% Opacity and with pressure opacity.

Palette → Generate OKLCh Ramp from FG (2025) / Generate Pigment Mix FG > BG (2027)

Both generate a .gpl palette, save it under Created palettes, and select it.

Docs

  • Manual chapters 02 and 03.
  • SHORTCUTS.md.
  • .claude/instructions/draw-color-spaces.md and the new draw-pen-pressure.md.
  • CLAUDE.md, DRAW.cfg.default.

Verification

I built DRAW with QB64-PE and drove it under Xvfb with xdotool.

Pen pressure

  • The library: confirmed on real hardware by @grymmjack with a HUION Inspiroy 2 M on Linux (Wayland/XWayland), macOS and Windows.
  • Inside DRAW: @grymmjack confirmed size by pressure with the Inspiroy. That testing also turned up four bugs, all fixed here:
    • pattern strokes with opacity by pressure punched holes and flickered;
    • grazes left stray dots;
    • [Linux] hover movement was lost, so the brush outline froze;
    • the brush outline was drawn off the canvas.
  • Checked under Xvfb, with a temporary build where the pointer's X position stood in for pressure:
    • opacity fades from light to full;
    • repeated passes don't build up;
    • undo restores each step exactly;
    • grazes under the threshold leave the canvas untouched and add no undo step;
    • hover works with the backend running;
    • the outline is hidden off the canvas.
  • Mouse unaffected: mouse strokes are pixel-identical with every pen option on or off.

Mix brush

  • Measured: blue over yellow, red and white gives green 60,148,63, brown 66,62,54 and sky blue 68,148,205.
  • Behavior: strokes blend smoothly dab by dab, with no banding. Smudge Length and Smudge 100 behave as described.
  • Pixel-perfect: each pixel keeps its own color through the release redraw. With the replay disabled as a control, the whole stroke turned one color.
  • Undo: works as for any stroke.

Earlier checks

  • 3D panel: picking, the controls, F11 and draw-over auto-hide.
  • The OKLCh ramp and the pigment mix palette.
  • OKLab gradient parity: 200k cases.
  • The library pigment test matches spectral.js exactly in all 307 cases.

Housekeeping: the duplicate action-ID audit prints nothing, and the build is clean.

Not done yet: the pen's eraser end switching to the Eraser automatically.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD

claude added 3 commits October 1, 2026 19:12
… ramps

Uses the new QB64_GJ_LIB COLOR module (submodule bumped to
claude/color-spaces-oklab, grymmjack/QB64_GJ_LIB):

- View > 3D Color Space (action 2024): floating panel wrapping the C3D
  widget. It shows the sRGB gamut as a rotatable solid or point cloud in
  OKLab (default), CIELAB, XYZ or the RGB cube, with a lightness slice
  that makes interior colors pickable. Left-click/drag the solid sets
  FG; right/middle-drag spins; the wheel zooms. Readouts show hex/RGB,
  OKLab, OKLCh, CIELAB and XYZ. It auto-hides while drawing over it,
  follows F11 toggle-all, and persists view state in
  CFG.COLOR_SPACE_3D_*. REGION_COLOR_SPACE_3D = 29.
- Gradient fills blend in OKLab by default (CFG.GRADIENT_BLEND_SPACE:
  0 sRGB classic, 1 OKLab, 2 linear light) through
  DRAWER_gradient_lerp_color, with t quantized to 1/1023 and a memo
  cache (0.13 s per 1M pixels; sRGB mode unchanged byte-for-byte).
- Palette > Generate OKLCh Ramp from FG (action 2025): a perceptually
  even dark->light ramp saved as "Ramp RRGGBB.gpl" under Created
  palettes and selected.
- Settings > Panels > Color Blending + Ramps for the blend space and
  ramp parameters.
- Docs: manual ch. 03, SHORTCUTS.md, action table, file map, and
  .claude/instructions/draw-color-spaces.md.

Verified under Xvfb: pick sets FG (painted pixel = picked color);
rotate, space/view/slice buttons; F11 hides and restores; draw-over
auto-hide and restore; ramp palette written and loaded. The extracted
gradient function matches a direct OKLab mix in 200k random cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD
…anel

The widget only receives mouse input while the pointer is over the panel,
so the readout kept showing the last hovered color after the pointer left
instead of returning to the current color. Found on the screenshot tour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD
…alette

Uses the new QB64_GJ_LIB COLOR-PIGMENT (Kubelka-Munk, Spectral.js port):
- Brush > Mix Colors (Pigment) (action 2026, TOOLS/BRUSH-MIX): brush
  strokes mix with the pre-stroke pixels like wet paint (blue over yellow
  = green), with Mix Strength and Mix Pickup (smear) settings. Hooked in
  DRAWER_resolve_paint_color; forces raster export; undo unchanged.
- Gradient Blend gains 'Pigment (paint)' (GRADIENT_BLEND_SPACE=3).
- Palette > Generate Pigment Mix FG > BG (action 2027).
- Settings, cfg defaults, docs, and the submodule bump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD
@grymmjack grymmjack changed the title OKLab color spaces: 3D Color Space picker, OKLab gradients, OKLCh ramps Color spaces + pigment mixing: 3D Color Space picker, OKLab/pigment gradients, OKLCh ramps, mix brush Oct 1, 2026
claude added 2 commits October 2, 2026 16:02
…Smudge Radius)

The brush now carries one smudge color. Before every dab it samples the
layer under the dab (alpha-weighted, linear light, a disc of Smudge
Radius % of the brush radius) and moves the smudge color toward the
sample, keeping Smudge Length % of the old color; samples are spaced
size/4 px apart (libmypaint's 2 dabs per radius), so the result no
longer depends on FPS. Each dab is pigment_mix(smudge, paint) with
Smudge %; 100 is a pure smudge tool.

Samples come from a snapshot taken at stroke start: hard pixel dabs
re-sampling their own fresh paint turned the brush back into plain paint
within a few pixels. Pixel-perfect redraw at release now replays each
pixel's stroke color (BMIX_begin_replay) instead of recoloring the whole
stroke with the final smudge color.

Replaces BRUSH_MIX_STRENGTH / BRUSH_MIX_PICKUP with BRUSH_MIX_SMUDGE,
BRUSH_MIX_LENGTH and BRUSH_MIX_RADIUS; removes the per-frame pickup that
banded on fast strokes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD
Uses the new QB64_GJ_LIB PRESSURE_DEVICE library (Windows Ink, macOS
sendEvent, XInput2), confirmed on all three OSes with a HUION Inspiroy 2 M.

- INPUT/PEN (TABLET state; PEN is a QB64 keyword): PEN_init before the
  main loop, PEN_poll each frame before mouse handling, PEN_stroke_begin
  on brush press.
- PAINT_on fixes the pressure at both ends of each frame's segment; with
  pressure sizing on, PAINT_on_pressure stamps a dab per pixel sized from
  the interpolated pressure (PAINT_stamp_brush now wraps the new
  PAINT_stamp_size). Readings below 0.02 hold the last real value so
  strokes don't start with a blob or end with a hairline flick.
- Mix brush: a light touch smears more (PEN_mix_smudge).
- Pressure-varied strokes set HISTORY_FLAG_PAINT_MODE (raster export).
- Settings > General > Pen Tablet: PEN_PRESSURE, PEN_PRESSURE_SIZE,
  PEN_MIN_SIZE, PEN_PRESSURE_CURVE, PEN_PRESSURE_MIX. A mouse is never
  affected (pressure 1): mouse strokes are pixel-identical to before.
- Docs: manual ch02, SHORTCUTS, draw-pen-pressure.md, CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6w1daXFyqncBmNzt5yYsD
@grymmjack grymmjack changed the title Color spaces + pigment mixing: 3D Color Space picker, OKLab/pigment gradients, OKLCh ramps, mix brush Color spaces, pigment mixing and pen pressure: 3D Color Space, OKLab/pigment gradients, OKLCh ramps, mix brush, tablet pressure Oct 3, 2026
grymmjack and others added 2 commits October 3, 2026 16:05
- View > Pen Pressure (action 2028, GUI/PEN-PANEL): floating panel with a
  live pressure meter, a checkbox + lightest-touch slider each for size,
  opacity and mix paint, a log-scale curve slider and a response graph.
  Same frame model as the 3D Color Space panel (auto-hide while drawing
  over it, F11, drag, region, pan/wheel exclusions).
- Pressure -> opacity (PEN_PRESSURE_OPACITY, PEN_MIN_OPACITY): each pixel
  is recomposited from a stroke-start snapshot at the strongest opacity
  reached there (per-pixel mask), so overlapping dabs never compound and
  the result shows live. Covers hard, AA and eraser pixels; straight-alpha
  source-over so light strokes on empty pixels don't darken.
- Mix paint by pressure gets a lightest-touch amount (PEN_MIX_MIN).
- Brush / spray / custom-brush footprint only drawn over the canvas (the
  apron counts while a stroke is in progress).
- QB64_GJ_LIB bump: the Linux pressure backend no longer selects XI_Motion
  on DRAW's window, which had stopped hover movement reaching DRAW and
  left the brush outline frozen where the pen left off.

Verified under Xvfb with a temporary simulated pen: pressure opacity
fades light->full, repeated passes don't build up, undo restores each
step exactly; hover works with the backend running; mouse strokes are
pixel-identical with the pen options on or off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… pressure opacity

- Tip threshold (PEN_TIP_THRESHOLD, default 3%): a pen grazing the tablet
  registered clicks at almost no pressure and left stray dots along the
  hover path. Segments below the threshold draw nothing, and a pen stroke
  that never passes it records no undo step. Panel TIP slider (red mark
  on the meter) + Settings > Pen Tablet.
- With opacity by pressure, a transparent resolved color (pattern or
  gradient hole) was treated as erase: pattern strokes punched holes in
  existing paint and made it flicker. It now erases only in an erasing
  stroke (Eraser / transparent paint) and otherwise leaves the pixel, as
  plain PSET does.
- Panel: CURVE/TIP rows no longer overlap; curve value shows two
  decimals (1.30, was 1.3.).
- QB64_GJ_LIB bump: PRESSURE_DEVICE docs, screenshots, example, XInput2
  unit test; Linux in-range clears when another device moves.

Verified under Xvfb with a temporary simulated pen: grazes below the
threshold leave the canvas untouched and add no undo step (one Ctrl+Z
removes the preceding real stroke).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@grymmjack grymmjack changed the title Color spaces, pigment mixing and pen pressure: 3D Color Space, OKLab/pigment gradients, OKLCh ramps, mix brush, tablet pressure Color spaces, pigment mixing and pen pressure: 3D Color Space, OKLab/pigment gradients, mix brush, tablet pressure + Pen Pressure panel Oct 3, 2026
grymmjack and others added 2 commits October 3, 2026 16:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d too dark

- HISTORY_apply_layer_snapshot cleared the layer and then _PUTIMAGE'd the
  snapshot with blending on, which composites onto the cleared black
  (RGB x alpha): every undo/redo made soft edges, Opacity strokes and
  pressure-opacity strokes darker and fainter (50% white 126 -> 63).
  Copy with _DONTBLEND instead. Same fix for the PNG-import fallback in
  DRW_load (semi-transparent pixels came in darkened).
- STROKE_commit lerped RGB toward a transparent backup pixel's black, so
  50% white on an empty pixel was stored as dark gray. Interpolate in
  premultiplied space and un-premultiply (LONG math).
- QB64_GJ_LIB submodule now on main (23db828 = #27 + #29), identical
  COLOR / PRESSURE_DEVICE contents.

Verified under Xvfb: strokes at 50% Opacity (mouse) and with pressure
opacity (simulated pen): undo x1/x3 then redo x1/x3 all match the
original captures pixel-for-pixel (before the fix: thousands of pixels
differed and each round trip darkened further).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@grymmjack
grymmjack marked this pull request as ready for review October 3, 2026 20:50
@grymmjack
grymmjack merged commit 3d05003 into main Oct 3, 2026
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.

2 participants