Skip to content

Add in-memory stroke transport#67

Open
codexbountylab wants to merge 3 commits into
moth-quantum:sourcefrom
codexbountylab:codex/quantumbrush-in-memory-strokes
Open

Add in-memory stroke transport#67
codexbountylab wants to merge 3 commits into
moth-quantum:sourcefrom
codexbountylab:codex/quantumbrush-in-memory-strokes

Conversation

@codexbountylab

Copy link
Copy Markdown

Summary

This PR addresses #47 by replacing the per-stroke PNG file transport with an in-memory Java/Python effect pipeline.

Previously, each stroke wrote image files such as _input.png and _output.png to disk. With large images and repeated strokes, that can quickly make a project directory grow. This change keeps new stroke inputs and processed results in memory during the active session instead.

Java now sends the current canvas image to Python through stdin as PNG bytes using a small length-prefixed binary protocol. Python decodes the image in memory, runs the selected effect, and returns the processed PNG bytes through stdout. Logs and debug output stay on stderr, so they do not interfere with the binary response.

I also added docs/in-memory-stroke-transport.md with the technical workflow.

Workflow

flowchart LR
    A["Java canvas PImage"] --> B["Encode PNG bytes in memory"]
    B --> C["stdin: JSON instructions + PNG bytes"]
    C --> D["Python apply_effect.py --stdio"]
    D --> E["Run brush/effect in memory"]
    E --> F["stdout: response JSON + result PNG bytes"]
    F --> G["Java decodes result into PImage"]
    G --> H["Apply result to canvas"]
Loading

Changes

  • Keep new stroke input images in memory instead of writing per-stroke input PNG files.
  • Run effects through apply_effect.py --stdio.
  • Send Java/Python payloads as length-prefixed binary messages.
  • Store processed stroke results in memory for the active session.
  • Keep legacy file-based output loading as a fallback for older projects.
  • Reset reopened in-memory strokes to pending if their temporary result is no longer available.
  • Update Stroke Manager previews so they do not expect per-stroke PNGs for the new transport.

Validation

  • Verified that the Java code compiles.
  • Verified that apply_effect.py has no Python syntax errors.

AI disclosure

I used AI assistance while developing this PR. I reviewed the generated changes and validation results before submitting.

@codexbountylab

codexbountylab commented Jun 18, 2026

Copy link
Copy Markdown
Author

@artreadcode Updated the PR with the follow-up fixes.

Main changes:

  • Persisted in-memory stroke previews/results in the stroke instructions so Stroke Manager can restore them after closing and reopening the app.
  • Updated Stroke Manager to show the actual in-memory input/output previews instead of placeholder panels.
  • Added fallback regeneration for completed in-memory strokes when reopening older project state.
  • Fixed Collage handling for the UI click/path data so it works with the recorded stroke format and clipped paste regions.

I tested the in-memory flow again, including reopening the project and checking Stroke Manager previews, and the previously failing Collage case now completes successfully.
QuantumBrush-combined-test.zip

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