Crates.io | xbrz-rs |
lib.rs | xbrz-rs |
version | 0.1.0 |
source | src |
created_at | 2024-07-28 16:15:09.114113 |
updated_at | 2024-07-28 16:15:09.114113 |
description | A high quality image upscaling algorithm designed to preserve key details in low-resolution pixel art. |
homepage | |
repository | https://github.com/bell345/xbrz-rs |
max_upload_size | |
id | 1318055 |
size | 90,082 |
This project is a Rust port of the C++ implementation of the xBRZ pixel scaling algorithm, originally created by Zenju. You can download the original C++ version on SourceForge. Both the C++ version and this port are licensed under the GNU General Public License v3.
See the example images section for a comparison of this library's output with nearest neighbour scaling.
There is currently one public function called scale_rgba
, which can scale an RGBA format image from 2x up to 6x the
original resolution:
use std::path::Path;
fn upscale_image(input_path: &Path, output_path: &Path, factor: usize) -> Result<(), image::ImageError> {
let in_image = image::open(input_path)?;
let width = in_image.width();
let height = in_image.height();
let rgba = image::RgbaImage::from(in_image);
let out_rgba = xbrz::scale_rgba(
&rgba,
width as usize,
height as usize,
factor
);
let out_width = width * factor as u32;
let out_height = height * factor as u32;
image::save_buffer(
output_path,
&out_rgba,
out_width,
out_height,
image::ExtendedColorType::Rgba8,
)
}
To compare pixels, the RGB values are converted into YCbCr representation. To do this efficiently, this package creates a lookup table (LUT) which converts between an RGB difference and scalar difference computed with YCbCr coordinates.
By default, this lookup table uses compressed 5-bit per channel indices such that the LUT only uses 128 KiB of memory.
However, by enabling the large_lut
feature, the full range of 8-bit differences is used, which causes the LUT to
take up 64 MiB of memory. The difference will be negligible, but you may enable it if you wish for higher accuracy.
Also see the test/images directory for examples at more scaling factors.
Nearest Neighbour x3 | xBRZ algorithm (xbrz-rs) x3 |
---|---|
Nearest Neighbour x3 | xBRZ algorithm (xbrz-rs) x3 |
---|---|
Nearest Neighbour x6 | xBRZ algorithm (xbrz-rs) x6 |
---|---|