Hqx Explained

hqx
Developer:Maxim Stepin
Latest Release Version:1.1
Programming Language:C++
Genre:Pixel-art scaling algorithm
License:LGPL 2.1

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,[1] and is used in emulators such as Nestopia, F. CEUXSnes9x., 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 to order to mimic human perception.[2] This gives a total of

28=256

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.[2]

The interpolation data in the lookup tables are constrained by the requirement that continuity of line segments must be preserved, while optimizing for smoothness. Generating these 256-filter lookup tables is relatively slow, and is the major source of complexity in the algorithm: the render stage is very simple and fast, and designed to be capable of being performed in real time on a MMX-capable CPU.[2]

In the source code, the interpolation data is represented as preprocessor macros to be inserted into switch case statements, and there is no source code leading to the generation of a lookup table. The author describes the process of generating a look-up table as:[2]

... for each combination the most probable vector representation of the area has to be determined, with the idea of edges between the different colored areas of the image to be preserved, with the edge direction to be as close to a correct one as possible. That vector representation is then rasterised with higher (3x) resolution using anti-aliasing, and the result is stored in the lookup table.

Implementations

See also

External links

Notes and References

  1. Web site: 2013-12-05 . HiEnd3D . 2023-02-12 . https://web.archive.org/web/20131205091805/http://www.hiend3d.com/hq2x.html . 2013-12-05 .
  2. Zemek . Cameron . hqx README (grom358 port) . 6 May 2019 .
  3. Web site: Garcia . Edu . hqx-java . GitHub . 6 March 2019.
  4. Web site: Tamschi . hqxsharp . GitHub.
  5. Byuu. Release announcement Accessed 2011-08-14. public domain implementation released on pastebin
  6. Web site: hqx . Libretro Docs.
  7. Web site: Blok . Jules . hqx-shader . GitHub . 12 April 2019.
  8. Web site: K . Hunter . Filthy Pants: A Computer Blog: True Hq2x Shader Comparison With xBR . Filthy Pants . 20 June 2014.