Hq3x
   HOME

TheInfoList



OR:

In
image processing An image is a visual representation of something. It can be two-dimensional, three-dimensional, or somehow otherwise feed into the visual system to convey information. An image can be an artifact, such as a photograph or other two-dimensiona ...
, hqx ("high quality scale") is one of the pixel art scaling algorithms developed by Maxim Stepin, used in
emulator In computing, an emulator is Computer hardware, hardware or software that enables one computer system (called the ''host'') to behave like another computer system (called the ''guest''). An emulator typically enables the host system to run so ...
s such as
Nestopia Nestopia UE - and its predecessor Nestopia - are an open-source NES/Famicom emulator designed to emulate the NES hardware as accurately as possible. Features The requirements for the original Nestopia were considered higher than some of its c ...
, FCEUX,
higan is a Buddhist holiday exclusively celebrated by Japanese sects for seven days; three days before and after both the Spring equinox ( shunbun) and Autumnal equinox ( shūbun). It is observed by nearly every Buddhist school in Japan. The tra ...
, Snes9x,
ZSNES ZSNES is a free software Super Nintendo Entertainment System emulator written mostly in x86 assembly with official ports for Linux, DOS, Windows, and unofficial ports for Xbox and macOS. Background Development of ZSNES began on 3 July 1997 an ...
and many more. There are three hqx filters defined: hq2x, hq3x, and hq4x, which magnify by a factor of 2, 3, and 4 respectively. For other magnification factors, this filter is used with nearest-neighbor scaling.


Algorithm

First, the color of each of the 8 pixels around the source pixel is compared to the color of the source pixel. Shapes are detected by checking for
pixel In digital imaging, a pixel (abbreviated px), pel, or picture element is the smallest addressable element in a raster image, or the smallest point in an all points addressable display device. In most digital display devices, pixels are the smal ...
s of similar color according to a threshold. 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. Hqx uses the YUV color space to calculate color differences, so that differences in brightness is weighted higher to mimic human perception. It is possible to use a look-up table for the color space conversion if the source image is 16 bit per pixel. 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. 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 In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
leading to the generation of a lookup table. The author describes the process of generating a look-up table as:
... 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

* The original algorithm has been ported to DevIL (but kept in the C language). * Ports to Java and C# languages are available. These implementations expand the macros. * A
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
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.Byuu
Release announcement
Accessed 2011-08-14
public domain implementation released on pastebin
/ref> * libretro implements two families of shaders in Slang/
HLSL The High-Level Shader Language or High-Level Shading Language (HLSL) is a proprietary shading language developed by Microsoft for the Direct3D 9 API to augment the shader assembly language, and went on to become the required shading language ...
,
GLSL OpenGL Shading Language (GLSL) is a high-level shading language with a syntax based on the C programming language. It was created by the OpenGL ARB (OpenGL Architecture Review Board) to give developers more direct control of the graphics pipelin ...
, and Cg: ** The hqx family, which is true hqx. As it runs on modern
GPU A graphics processing unit (GPU) is a specialized electronic circuit designed to manipulate and alter memory to accelerate the creation of images in a frame buffer intended for output to a display device. GPUs are used in embedded systems, mobi ...
s, 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 FFmpeg is a free and open-source software project consisting of a suite of libraries and programs for handling video, audio, and other multimedia files and streams. At its core is the command-line ffmpeg tool itself, designed for processing of vid ...
for upscaling images and videos 2x, 3x, or 4x. An account of the production of the translation for ffmpeg is here: http://blog.pkh.me/p/19-butchering-hqx-scaling-filters.html and usage may be something like: ffmpeg -i %1 -filter_complex hqx=2 hqx2-%1 to produce a 2x image or video.


See also

*
Image scaling In computer graphics and digital imaging, image scaling refers to the resizing of a digital image. In video technology, the magnification of digital material is known as upscaling or resolution enhancement. When scaling a vector graphic image, ...


References

{{Reflist


External links


hq2x
an

at the
Wayback Machine The Wayback Machine is a digital archive of the World Wide Web founded by the Internet Archive, a nonprofit based in San Francisco, California. Created in 1996 and launched to the public in 2001, it allows the user to go "back in time" and see ...

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 -i %1 -filter_complex hqx=2 hqx2-%1 to produce a 2x image or video. Image processing