()
| 1 | //! <https://pngquant.org/lib/> |
| 2 | |
| 3 | fn main() { |
| 4 | // Image loading/saving is outside scope of this library |
| 5 | let width = 10; |
| 6 | let height = 10; |
| 7 | let fakebitmap = vec![imagequant::RGBA {r:100, g:200, b:250, a:255}; width * height]; |
| 8 | |
| 9 | // Configure the library |
| 10 | let mut liq = imagequant::new(); |
| 11 | liq.set_speed(5).unwrap(); |
| 12 | liq.set_quality(70, 99).unwrap(); |
| 13 | |
| 14 | // Describe the bitmap |
| 15 | let mut img = liq.new_image(&fakebitmap[..], width, height, 0.0).unwrap(); |
| 16 | |
| 17 | // The magic happens in quantize() |
| 18 | let mut res = match liq.quantize(&mut img) { |
| 19 | Ok(res) => res, |
| 20 | Err(err) => panic!("Quantization failed, because: {err:?}"), |
| 21 | }; |
| 22 | |
| 23 | // Enable dithering for subsequent remappings |
| 24 | res.set_dithering_level(1.0).unwrap(); |
| 25 | |
| 26 | // You can reuse the result to generate several images with the same palette |
| 27 | let (palette, pixels) = res.remapped(&mut img).unwrap(); |
| 28 | |
| 29 | println!( |
| 30 | "Done! Got palette {palette:?} and {} pixels with {}% quality", |
| 31 | pixels.len(), |
| 32 | res.quantization_quality().unwrap() |
| 33 | ); |
| 34 | } |
nothing calls this directly
no test coverage detected