MCPcopy Index your code
hub / github.com/ImageOptim/libimagequant / main

Function main

examples/basic.rs:3–34  ·  view source on GitHub ↗

()

Source from the content-addressed store, hash-verified

1//! <https://pngquant.org/lib/>
2
3fn 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}

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
set_speedMethod · 0.80
set_qualityMethod · 0.80
new_imageMethod · 0.80
set_dithering_levelMethod · 0.80
remappedMethod · 0.80
quantizeMethod · 0.45

Tested by

no test coverage detected