Repository navigation
Color spaces, pigment mixing and pen pressure: 3D Color Space, OKLab/pigment gradients, mix brush, tablet pressure + Pen Pressure panel - #147
Merged
Conversation
… 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
…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
- 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>
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
marked this pull request as ready for review
October 3, 2026 20:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses
QB64_GJ_LIB/COLORandQB64_GJ_LIB/PRESSURE_DEVICE, both now on QB64_GJ_LIBmain(grymmjack/QB64_GJ_LIB#27 and #29). The submodule points atmain(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.
CFG.COLOR_SPACE_3D_*).Gradient blending: OKLab (default) and Pigment
CFG.GRADIENT_BLEND_SPACEselects 0 sRGB (classic, byte-for-byte unchanged), 1 OKLab, 2 linear light, or 3 Pigment (paint). The blends are memoized inDRAWER_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.
pigment_mix(smudge color, brush color).Pen tablet pressure (new)
INPUT/PENwraps the new PRESSURE_DEVICE library. Its state variable isTABLET, becausePENis 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):
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):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)
HISTORY_apply_layer_snapshotblended 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.STROKE_commitdarkened strokes at less than 100% Opacity on empty pixels (50% white was stored as gray). It now interpolates in premultiplied space.Palette → Generate OKLCh Ramp from FG (2025) / Generate Pigment Mix FG > BG (2027)
Both generate a
.gplpalette, save it under Created palettes, and select it.Docs
SHORTCUTS.md..claude/instructions/draw-color-spaces.mdand the newdraw-pen-pressure.md.CLAUDE.md,DRAW.cfg.default.Verification
I built DRAW with QB64-PE and drove it under Xvfb with xdotool.
Pen pressure
Mix brush
60,148,63, brown66,62,54and sky blue68,148,205.Earlier checks
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