mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-12-28 17:08:18 +01:00
286f7c643f
When this option is enabled all png images will be converted to PNG-8 (8 bit per pixel).
33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
// Don't forget to add -L . (or whatever dir has .rlib) to rustc!
|
|
|
|
fn main() {
|
|
// Image loading/saving is outside scope of this library
|
|
let width = 10usize;
|
|
let height = 10usize;
|
|
let fakebitmap = vec![255u8; 4 * width * height];
|
|
|
|
// http://pngquant.org/lib/
|
|
|
|
// Configure the library
|
|
let mut liq = imagequant::new();
|
|
liq.set_speed(5);
|
|
liq.set_quality(70, 99);
|
|
|
|
// Describe the bitmap
|
|
let ref mut img = liq.new_image(&fakebitmap[..], width, height, 0.0).unwrap();
|
|
|
|
// The magic happens in quantize()
|
|
let mut res = match liq.quantize(img) {
|
|
Ok(res) => res,
|
|
Err(err) => panic!("Quantization failed, because: {:?}", err),
|
|
};
|
|
|
|
// Enable dithering for subsequent remappings
|
|
res.set_dithering_level(1.0);
|
|
|
|
// You can reuse the result to generate several images with the same palette
|
|
let (palette, pixels) = res.remapped(img).unwrap();
|
|
|
|
println!("Done! Got palette {:?} and {} pixels with {}% quality", palette, pixels.len(), res.quantization_quality());
|
|
}
|