(&mut self, image: &DynamicRows<'_, '_>, importance_map: Option<&[u8]>, posterize_bits: u8)
| 248 | } |
| 249 | |
| 250 | pub(crate) fn add_pixel_rows(&mut self, image: &DynamicRows<'_, '_>, importance_map: Option<&[u8]>, posterize_bits: u8) -> Result<(), Error> { |
| 251 | let width = image.width as usize; |
| 252 | let height = image.height as usize; |
| 253 | |
| 254 | debug_assert!(importance_map.map_or(true, |m| m.len() == image.width() * image.height())); |
| 255 | |
| 256 | let mut importance_map = importance_map.unwrap_or(&[]).chunks_exact(width).fuse(); |
| 257 | let image_iter = image.rgba_rows_iter()?; |
| 258 | |
| 259 | let mut temp_row = temp_buf(width)?; |
| 260 | for row in 0..height { |
| 261 | let pixels_row = &image_iter.row_rgba(&mut temp_row, row)[..width]; |
| 262 | let importance_map = importance_map.next().map(move |m| &m[..width]).unwrap_or(&[]); |
| 263 | for (col, px) in pixels_row.iter().copied().enumerate() { |
| 264 | let boost = importance_map.get(col).copied().unwrap_or(255); |
| 265 | self.add_color(px, boost.into()); |
| 266 | } |
| 267 | } |
| 268 | self.init_posterize_bits(posterize_bits); |
| 269 | |
| 270 | if self.hashmap.len() > self.max_histogram_entries as usize && self.posterize_bits < 3 { |
| 271 | self.init_posterize_bits(self.posterize_bits + 1); |
| 272 | } |
| 273 | Ok(()) |
| 274 | } |
| 275 | |
| 276 | pub(crate) fn finalize_builder(&mut self, gamma: f64) -> Result<HistogramInternal, Error> { |
| 277 | debug_assert!(gamma > 0.); |
no test coverage detected