• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..07-May-2022-

src/H26-Jul-2014-13,21012,664

AUTHORSH A D26-Jul-2014148 63

COPYINGH A D26-Jul-201425.9 KiB503418

ChangeLogH A D26-Jul-2014638 1411

Makefile.am.hqxH A D26-Jul-201439 42

NEWSH A D26-Jul-2014300 97

READMEH A D26-Jul-20142.4 KiB7155

configure.ac.hqxH A D26-Jul-2014843 3427

README

1hqx Library README
2==================
3
4Introduction
5------------
6hqx is a fast, high-quality magnification filter designed for pixel art.
7
8Install
9-------
10NOTE: DevIL library and development headers are required.
11
12    ./configure
13    make && make install
14
15For more information refer to INSTALL.
16
17Usage
18-----
19hqx -s scaleBy input output
20Where scaleBy is either 2, 3 or 4
21
22For example:
23    hqx -s 4 test.png out.png
24
25Example
26-------
27#include <stdint.h>
28#include <hqx.h>
29
30uint32_t *src; // Pointer to source bitmap in RGB format
31size_t width, height; // Size of source bitmap
32
33/*
34 * Code to init src, width & height
35 */
36
37uint32_t *dest = (uint32_t *) malloc(width * 4 * height * 4 * sizeof(uint32_t));
38hqxInit();
39hq4x_32(src, dest, width, height);
40
41Implementation
42--------------
43The first step is an analysis of the 3x3 area of the source pixel. At first, we
44calculate the color difference between the central pixel and its 8 nearest
45neighbors. Then that difference is compared to a predefined threshold, and these
46pixels are sorted into two categories: "close" and "distant" colored. There are
478 neighbors, so we are getting 256 possible combinations.
48
49For the next step, which is filtering, a lookup table with 256 entries is used,
50one entry per each combination of close/distant colored neighbors. Each entry
51describes how to mix the colors of the source pixels from 3x3 area to get
52interpolated pixels of the filtered image.
53
54The present implementation is using YUV color space to calculate color
55differences, with more tolerance on Y (brightness) component, then on color
56components U and V. That color space conversion is quite easy to implement if
57the format of the source image is 16 bit per pixel, using a simple lookup table.
58It is also possible to calculate the color differences and compare them to a
59threshold very fast, using MMX instructions.
60
61Creating a lookup table was the most difficult part - for each combination the
62most probable vector representation of the area has to be determined, with the
63idea of edges between the different colored areas of the image to be preserved,
64with the edge direction to be as close to a correct one as possible. That vector
65representation is then rasterised with higher (3x) resolution using
66anti-aliasing, and the result is stored in the lookup table.
67
68The filter was not designed for photographs, but for images with clear sharp
69edges, like line graphics or cartoon sprites. It was also designed to be fast
70enough to process 256x256 images in real-time.
71