A high-performance implementation of the Scale2x upscaling algorithm in Rust, with support for multi-core CPU parallelization and GPU acceleration.
Install cargo and rust.
Download the source of the project, then run cargo build --release in the directory to generate the binary in ./target/release/rscale2x.
Upscale and save images using the scale2x algorithm.
Usage: rscale2x [OPTIONS] --input <INPUT> --output <OUTPUT>
Options:
-i, --input <INPUT> Input image file path
-o, --output <OUTPUT> Output image file path
-b, --blur <BLUR> Gaussian blur [default: 0]
-u, --unsharpen <UNSHARPEN> Unsharpen [default: 0]
--hue <HUE> Hue shift [default: 0]
-t, --threads <THREADS> Number of threads (0 = auto, 1 = single-threaded) [default: 0]
--gpu Use GPU acceleration via wgpu (Metal/Vulkan/DX12)
-h, --help Print help information
-V, --version Print version information
Tests include process startup, image decoding (PNG), algorithm execution, and encoding (PNG). Recorded on an 8-Core M1 Pro.
| Image Size | scalex (Original C) | rscale2x (Single-Core) | rscale2x (Multi-Core) | rscale2x (GPU) |
|---|---|---|---|---|
| 1024x1024 | 418ms | 202ms | 190ms | 208ms |
| 2048x2048 | 1.44s | 701ms | 661ms | 690ms |
| 4096x4096 | 4.90s | 2.66s | 2.50s | 2.56s |
Note: For smaller images, CPU paths are often faster due to zero initialization overhead. For very large images, Multi-core and GPU paths provide better scaling.
- Fast: Outperforms the original C implementation by ~2x end-to-end.
- Parallel: Uses
rayonfor efficient multi-core processing. - GPU Accelerated: Uses
wgpufor high-performance compute on supported hardware. - Robust: Includes automated unit tests to verify algorithm correctness.
Run the internal test suite:
cargo testOriginal Scale2x algorithm by Andrea Mazzoleni. tree.png: Unsplash