Skip to content

Add an opt-in hq4x pixel filter (desktop and browser) - #89

Open
sspilleman wants to merge 1 commit into
sergiou87:masterfrom
sspilleman:hq4x-pixel-filter
Open

sspilleman wants to merge 1 commit into
sergiou87:masterfrom
sspilleman:hq4x-pixel-filter

Conversation

@sspilleman

Copy link
Copy Markdown

Summary

Adds PIXEL FILTER: OFF / HQ4X to Advanced options, saved as pixelFilter in ADVANCED.CFG. OFF stays the default, so the game looks exactly the same unless the player turns it on.

  • How it works: hq4x blends colors, so each frame is converted with the current palette before it's filtered. Fades, the dimmed menu palette and color flashes keep working. The 1280x800 result is drawn with linear sampling.
  • Where it's offered: macOS, Windows, Linux and the browser. On the SDL2 console ports (PS2, PS3, Vita, Wii U, Switch) the menu entry is hidden: on PS2 the 1280x800 texture wouldn't fit in video memory, and the others are untested. The SDL1, PSP and null backends get stubs that hide it too.
  • The filter: vendored from grom358/hqx in src/lib/hqx/ (LGPL 2.1 or later, compatible with GPLv3; licence and README included). Two changes, both marked in the code:
    • Its 64 MB YUV lookup table is replaced by on-demand conversion with a small cache.
    • Upstream casts negative doubles to uint32_t, which is undefined behavior and gives wrong output on ARM. The output now matches upstream's intended (x86) result byte for byte.
  • Build files: src/sdl2/video.c #includes hq4x.c, so none of the ports' build files need changes.

Screenshots

The same demo frame on macOS, with the filter OFF and on HQ4X:

Pixel filter OFF and HQ4X, close-up

Full window (2560x1600)

OFF

Pixel filter OFF

HQ4X

Pixel filter HQ4X

Testing

  • Tested on macOS (Xcode build) and in the browser (WebAssembly). In the browser it holds 60 fps (median frame 16.7 ms).
  • Windows and Linux use the same code, but I haven't run them.
  • The test suite passes (6922/6922). The filter never runs in -u mode, so it can't affect game logic.

🤖 Generated with Claude Code

Advanced options get a "PIXEL FILTER: OFF/HQ4X" entry, saved as
pixelFilter in ADVANCED.CFG. OFF stays the default, so the game looks
the same unless the player turns it on.

hq4x blends colors, so every frame is converted with the current
palette before it's filtered. Fades, the dimmed menu palette and color
flashes keep working. The 1280x800 result is drawn with linear sampling.

The filter is only offered on desktop (macOS, Windows, Linux) and in the
browser, where it has been tested. The SDL2 console ports (PS2, PS3,
Vita, Wii U, Switch) and the backends without the filter (SDL1, PSP,
null) hide the menu entry. On PS2 the 1280x800 texture wouldn't fit in
video memory.

The filter comes from github.com/grom358/hqx (LGPL 2.1 or later),
vendored in src/lib/hqx/. Its 64 MB YUV lookup table is replaced by
on-demand conversion, and an undefined negative double to uint32_t cast
that breaks the output on ARM is fixed. src/sdl2/video.c includes hq4x.c
directly, so the ports' build files need no changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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