()
| 120 | |
| 121 | #[test] |
| 122 | fn poke_it() { |
| 123 | let width = 10usize; |
| 124 | let height = 10usize; |
| 125 | let mut fakebitmap = vec![RGBA::new(255, 255, 255, 255); width * height]; |
| 126 | |
| 127 | fakebitmap[0].r = 0x55; |
| 128 | fakebitmap[0].g = 0x66; |
| 129 | fakebitmap[0].b = 0x77; |
| 130 | |
| 131 | // Configure the library |
| 132 | let mut liq = Attributes::new(); |
| 133 | liq.set_speed(5).unwrap(); |
| 134 | liq.set_quality(70, 99).unwrap(); |
| 135 | liq.set_min_posterization(1).unwrap(); |
| 136 | assert_eq!(1, liq.min_posterization()); |
| 137 | liq.set_min_posterization(0).unwrap(); |
| 138 | |
| 139 | use std::sync::atomic::AtomicBool; |
| 140 | use std::sync::atomic::Ordering::SeqCst; |
| 141 | use std::sync::Arc; |
| 142 | |
| 143 | let log_called = Arc::new(AtomicBool::new(false)); |
| 144 | let log_called2 = log_called.clone(); |
| 145 | liq.set_log_callback(move |_attr, _msg| { |
| 146 | log_called2.store(true, SeqCst); |
| 147 | }); |
| 148 | |
| 149 | let prog_called = Arc::new(AtomicBool::new(false)); |
| 150 | let prog_called2 = prog_called.clone(); |
| 151 | liq.set_progress_callback(move |_perc| { |
| 152 | prog_called2.store(true, SeqCst); |
| 153 | ControlFlow::Continue |
| 154 | }); |
| 155 | |
| 156 | // Describe the bitmap |
| 157 | let img = &mut liq.new_image(&fakebitmap[..], width, height, 0.0).unwrap(); |
| 158 | |
| 159 | // The magic happens in quantize() |
| 160 | let mut res = match liq.quantize(img) { |
| 161 | Ok(res) => res, |
| 162 | Err(err) => panic!("Quantization failed, because: {err:?}"), |
| 163 | }; |
| 164 | |
| 165 | // Enable dithering for subsequent remappings |
| 166 | res.set_dithering_level(1.0).unwrap(); |
| 167 | |
| 168 | // You can reuse the result to generate several images with the same palette |
| 169 | let (palette, pixels) = res.remapped(img).unwrap(); |
| 170 | |
| 171 | assert_eq!(width * height, pixels.len()); |
| 172 | assert_eq!(100, res.quantization_quality().unwrap()); |
| 173 | assert_eq!(RGBA { r: 255, g: 255, b: 255, a: 255 }, palette[0]); |
| 174 | assert_eq!(RGBA { r: 0x55, g: 0x66, b: 0x77, a: 255 }, palette[1]); |
| 175 | |
| 176 | assert!(log_called.load(SeqCst)); |
| 177 | assert!(prog_called.load(SeqCst)); |
| 178 | } |
| 179 |
nothing calls this directly
no test coverage detected