Files
chandra/docs/screenshot-editor.md
Claude 77fcc4db1c
CI / test (push) Canceled after 12m58s
Screenshot editor: annotate, blur, pixelate, redact and crop before saving
Every screenshot now opens in an editor after KDE Spectacle's annotation mode:
Arrow, Line, Rectangle, Ellipse, Pen, Highlighter, Text, Number markers, Blur,
Pixelate, Redact and Crop, 8 colours, 3 sizes, undo/redo. Enter saves and
copies, Ctrl+C copies only, Esc discards.

- Drawn by the compositor (shot_editor.mbt), keyboard owned by it while up.
- Annotations are drawn into the picture's pixels at full size (annotate.mbt),
  so what is shown is what is saved. Blur = 6x6 block average + 3 box-blur
  passes; redact is opaque; both touch only their box (pixel tests).
- The picture goes to the renderer as <=2 MB strips: one 8 MB image-pixels
  call exhausts wasmtime's hostcall fuel and killed the wasm host.
- Frame callbacks are held while the overlay/editor freeze the screen, so apps
  behind stop drawing (0% CPU vs 52% with a full-screen animating app).
- wasmhost: error buffer 16 KB so trap causes aren't cut off; image-pixels
  limit 1024 -> 16384 a side (both hosts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hh3TaFJh7nhCxAjV4Q
2026-11-26 05:37:03 +00:00

83 lines
4.4 KiB
Markdown

# Screenshot editor
Every screenshot (Super+Shift+S, Print, Super+Print, Super+Ctrl+Print, or the Screenshot panel
module) opens in the editor before it is saved, after KDE Spectacle's annotation mode. The
picture fills the screen. The tools are above it, and the colours, sizes, Undo/Redo and the
Discard / Copy / Save buttons are below it.
![Screenshot editor](screenshots/screenshot-editor.png)
## Tools
| Tool | Key | What it does |
|---|---|---|
| Arrow | A | Drag from the tail to the tip |
| Line | L | Drag |
| Rectangle | R | Drag an outline |
| Ellipse | E | Drag an outline (fits the dragged box) |
| Pen | P | Draw freehand |
| Highlighter | H | Freehand, wide and translucent, even where the stroke crosses itself |
| Text | T | Click, type, then Enter or a click elsewhere (Backspace deletes, Esc drops it) |
| Number | N | Click to drop a numbered disc: 1, 2, 3, ... |
| Blur | B | Drag a box: its content is destroyed (see below) |
| Pixelate | X | Drag a box: blocks of one colour (block size follows the size setting) |
| Redact | D | Drag a box: an opaque box in the chosen colour |
| Crop | C | Drag the part to keep; the last crop counts and can be undone |
Colours: 1-8 (red, orange, yellow, green, blue, purple, black, white). Size: `[` and `]`
(thin, medium, thick); text, markers and pixel blocks grow with it. The editor remembers the
tool, colour and size for the next screenshot.
## Keys
| Keys | Action |
|---|---|
| Enter, Ctrl+S, Save button | Save to `~/Pictures/Screenshots/` (XDG_PICTURES_DIR) and copy to the clipboard |
| Ctrl+C, Copy button | Copy to the clipboard only, no file |
| Esc, Discard button | Discard (Esc first drops a shape or text being made) |
| Ctrl+Z / Ctrl+Shift+Z, Ctrl+Y | Undo / redo |
| Right-click | Drop the shape being drawn |
## Hiding things for real
Annotations are drawn into the picture's pixels at full size the moment you finish them, and the
editor shows that picture, so what you see is what is saved.
- **Redact** paints every pixel of the box in the chosen colour with full opacity.
- **Pixelate** replaces each block with its average colour.
- **Blur** first replaces each 6 x 6 block with its average (the detail is gone at that point),
then runs three box-blur passes each way with a radius of a sixth of the box's smaller side
(6 to 24 px). It reads and writes only the pixels inside the box.
`compositor/host/annotate_test.mbt` checks this pixel by pixel. Pixels outside the box don't
change. Two different patterns with the same average blur to the same result. A blurred "word"
ends up flat, with neighbouring columns at most 4 levels apart (the word was 220 levels darker than its background). Redact stays opaque over a
translucent picture.
## How it is built
The editor is drawn by the compositor (`compositor/host/shot_editor.mbt`), like the selection
overlay, rather than being a separate component window:
- The picture is already there. When the host holds the frozen screen (the wasm compositor), the
selected part is handed over once with `snapshot-pixels`.
- The keyboard has a single owner: the editor takes it, and the window that had it gets it back
when the editor closes.
- On the CPU: each finished annotation is drawn once into a full-size copy of the picture
(`annotate.mbt`). That copy is scaled to the size it is shown at and handed to the renderer
as a few images of at most 2 MB each (`raster.image-pixels`), drawn 1:1 one under the other.
A single 8 MB call runs out wasmtime's hostcall fuel and kills the wasm host. A frame then
draws only the annotation in progress as plain draw ops, and nothing is redrawn while you
aren't drawing. Undo redraws the picture from the original.
- The windows behind are frozen, as under the selection overlay. Their commits are shown when
the editor closes, and their frame callbacks are held back until then
(`WaylandServer::set_hold_frames`), so apps stop drawing frames nobody sees. Measured on the
wasm host at 1920x1080 with an app redrawing full screen behind the editor: 0% CPU, against
52% for the same app on the desktop.
- A picture saved unchanged is encoded by the host (`snapshot-png`), as before. An edited one is
encoded with `@renderer.encode_png_compressed`.
Headless pictures of the editor: run the host tests with `CHANDRA_EDITOR_SHOTS=<folder>` set,
and the test "editor: headless screenshots" writes `screenshot-editor.png` (the editor) and
`screenshot-editor-saved.png` (what it would save) there.