Skip to content

Compare images in the viewer - #753

Merged
SimonCropp merged 4 commits into
mainfrom
viewer-images
Aug 13, 2026
Merged

Compare images in the viewer#753
SimonCropp merged 4 commits into
mainfrom
viewer-images

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

Image files are compared as pictures rather than as text, wherever they turn up: a pair passed on the command line, or a move or delete the tray is holding. Previously they were read as text, which meant a pane of mojibake — and DiffEngine never routed one to the viewer at all, since its BinaryExtensions was empty.

An image is a side, not a mode

FileSide.Read (the renamed FileText) decides text or picture by extension. It has to be the extension rather than sniffed content, because the expected side of a brand new snapshot has no bytes to sniff and still has to render as a missing image rather than as empty text.

ImageRows then produces the same aligned Row lists DiffRows does — one row per property, each carrying its own side's value and coloured against the other, so a matching format reads unchanged and a differing size reads modified. An image comparison is therefore described by rows every head already draws.

Whether the two are the same file belongs to the pair rather than to either side, so it is the status line: images are identical, images differ, or only <file> exists, which is the normal state of a new image snapshot.

The picture is an enrichment on top

Pane.Image carries a path and the file header's dimensions. All three heads paint the picture under those rows — Windows with GDI+, macOS with ImageIO, Linux with raylib — so which formats draw is per platform while what the comparison says is not. A format a head cannot decode draws nothing and the rows still carry the comparison, which is the property the ASCII snapshots pin.

All three fit from ImagePane.Width/Height rather than from their own decoder, one blank line under the pane's rows, so the placement rule lives in one place instead of three.

Head Drawn
Windows (GDI+) .png .jpg .jpeg .gif .bmp .ico
macOS (ImageIO) all seven
Linux (raylib) .png .jpg .jpeg .gif .bmp

ABI

DEVIEW_VERSION 6: DeviewPane gained the picture. That widens an array element, so an older library would read every pane after the first at the wrong offset — this is a bump worth honouring. The rebuilt binaries are in this branch already (#752).

Notes

  • Headers are sniffed by hand (ImageHeader) rather than by System.Drawing, which does not exist on macOS or Linux. Recognising the format and reading the size are separate answers, so a truncated JPEG stays a JPEG of unknown size.
  • The extension list lives in DiffEngine and is linked into the viewer, so the tool registration and the renderer cannot disagree about what a picture is.
  • Both image caches decode from a copy of the bytes and remember failures. GDI+ holds the stream it is handed, and a viewer keeping a handle on the received file is one that blocks the accept it exists to perform.
  • Pixel baselines use a PNG built byte by byte with stored deflate blocks, because the pane prints the file's byte count and an encoder that packs differently on one platform would fail a baseline for an unrelated reason.

Outstanding

PixelTests.Images has no Linux or macOS baseline yet — this PR's first test.yml run is what produces them, as *.received.* artifacts to accept.

🤖 Generated with Claude Code

SimonCropp and others added 4 commits August 14, 2026 08:58
Image files are compared as pictures rather than as text, wherever they turn
up: a pair passed on the command line, or a move or delete the tray is
holding. Previously they were read as text, which meant a pane of mojibake,
and DiffEngine never routed one here at all.

FileSide.Read decides text or picture by extension, because the expected side
of a brand new snapshot has no bytes to sniff and still has to render as a
missing image rather than empty text. ImageRows then produces the same aligned
Row lists DiffRows does, one per property and coloured against the other side,
so an image comparison is described by rows every head already draws. Whether
the two are the same file belongs to the pair rather than to either side, so
it is the status line.

Pane.Image is an enrichment on top of that: all three heads paint the picture
under those rows, each with its toolkit's own decoder, so which formats draw
is per platform while what the comparison says is not. All three fit from the
file header's dimensions rather than the decoder's, one blank line under the
pane's rows, so the placement rule lives in one place.

Headers are sniffed by hand rather than by System.Drawing, which does not
exist on macOS or Linux, and the extension list lives in DiffEngine and is
linked into the viewer so the tool registration and the renderer cannot
disagree.

DEVIEW_VERSION 6: DeviewPane carries the picture. That widens an array
element, so an older library would read every pane after the first at the
wrong offset and the committed native binaries have to be rebuilt before they
will load.
Co-authored-by: SimonCropp <122666+SimonCropp@users.noreply.github.com>
DiffRunnerTests reads two fixtures from beside its own source file, and one of
them was missing from the working tree and got swept into the previous commit
as a deletion. LaunchAsync guards that both paths exist before it does anything
else, so the four launch tests failed on the Windows CI job.
Captured by the Linux and macOS jobs, which build the shim from source, so they
describe the renderers in this branch rather than the committed binaries.

Both heads draw the two pictures at native size, one blank line under the
property rows, on a checkerboard the transparent half shows through. The byte
counts read the same on all three platforms, which is what SamplePng's stored
deflate blocks are for.
@SimonCropp
SimonCropp merged commit cbcbf9b into main Aug 13, 2026
12 checks passed
@SimonCropp
SimonCropp deleted the viewer-images branch August 13, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant