hqx ("high quality scale") is a set of 3 image upscaling algorithms developed by Maxim Stepin. The algorithms are hq2x, hq3x, and hq4x, which magnify by a factor of 2, 3, and 4 respectively. It was initially created in 2003 for the Super NES emulator ZSNES, and is used in emulators such as Nestopia, FCEUX, higan, and Snes9x.
Algorithm
The source image's pixels are iterated through from top-left to bottom-right. For each pixel, the surrounding 8 pixels are compared to the color of the source pixel. Shapes are detected by checking for pixels of similar color according to a YUV threshold. hqx uses the YUV color space to calculate color differences, so that differences in brightness are weighted higher in order to mimic human perception. This gives a total of <math>2^8 = 256</math> combinations of similar or dissimilar neighbors. To expand the single pixel into a 2×2, 3×3, or 4×4 block of pixels, the arrangement of neighbors is looked up in a predefined table which contains the necessary interpolation patterns.
- A C++ port by byuu, the author of bsnes, which encodes the LUT in a space-efficient way. Byuu exploited the symmetry of patterns to make such an encoding, and wrote some notes on interpreting the original look up tables.
- libretro implements two families of shaders in Slang/HLSL, GLSL, and Cg:
- The hqx family, which is true hqx. As it runs on modern GPUs, lookup tables are substituted by textures. The textures were generated by interrogating a modified version of hqx for its switch/case.
- The scalehq family, which is frequently confused with hqx. It is not related to hqx, but is rather a generic upscaling-smoothing algorithm.
- hqx has also been implemented in ffmpeg for upscaling images and videos 2x, 3x, or 4x. An account of the production of the translation for ffmpeg is here and usage may be something like: <code>ffmpeg -i %1 -filter_complex hqx=2 hqx2-%1</code> to produce a 2x image or video.
See also
- Image scaling
- Pixel-art scaling algorithms
- Pixel art
References
External links
- hq2x, hq3x, and hq4x at the Wayback Machine
- Port of original project using DevIL A command line tool and C library
- hqxSharp project a port of hqx with added support for transparency, custom tolerances and seamless tiling (C#)
- 2d image filter project at code.google.com including the hqx filters and more (C#)
- hqx-java project Arcnor project - a free Java port of hqxSharp with a demo of usage (Java)
- HqxCli-Java A command line tool that use the Arcnor implementation (Java)
- ffmpeg implementation story ffmpeg -i %1 -filter_complex hqx=2 hqx2-%1 to produce a 2x image or video.
