hqx 0.1.1

high-quality pixel-art image magnification (2x/3x/4x upscaling)
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented1 out of 7 items with examples
  • Size
  • Source code size: 1.6 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.5 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hey-jj/hqx
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hey-jj

hqx

High-quality pixel-art magnification by 2x, 3x, and 4x. The filter keeps sharp edges sharp and smooths diagonal edges, which suits sprites and tiles far better than bilinear scaling.

How it works

For each source pixel the filter reads a 3x3 neighborhood, classifies the eight neighbors as close or distant in an approximate YUV space, and fills the output block from a 256-entry rule table. Border pixels replicate their nearest in-image neighbor.

Pixel format

Each pixel is a u32 read as 0xAARRGGBB. Alpha sits in the top byte and rides through interpolation. Color comparison ignores alpha. Byte order in memory is the caller's concern.

Usage

// A 2x2 image of four colors, scaled 2x to 4x4.
let src = [
    0x00FF_0000, 0x0000_FF00,
    0x0000_00FF, 0x00FF_FFFF,
];
let mut dst = vec![0u32; 2 * 2 * src.len()];
hqx::hq2x(&src, &mut dst, 2, 2);
assert_eq!(dst.len(), 16);

The destination must hold scale * scale * width * height pixels. A short destination panics up front before any write. The _rb variants take explicit row strides in pixels for padded buffers.

Installation

[dependencies]
hqx = "0.1"

License

Distributed under the GNU Lesser General Public License version 2.1 or later. See LICENSE and NOTICE.