MCPcopy Create free account
hub / github.com/ImageOptim/libimagequant / optionally_generate_dither_map

Method optionally_generate_dither_map

src/quant.rs:119–131  ·  view source on GitHub ↗
(use_dither_map: DitherMapMode, image: &mut Image<'_>, uses_background: bool, output_pixels: &mut RowBitmapMut<'_, MaybeUninit<PalIndexRemap>>, palette: &mut PalF)

Source from the content-addressed store, hash-verified

117 }
118
119 fn optionally_generate_dither_map(use_dither_map: DitherMapMode, image: &mut Image<'_>, uses_background: bool, output_pixels: &mut RowBitmapMut<'_, MaybeUninit<PalIndexRemap>>, palette: &mut PalF) -> Result<Option<f64>, Error> {
120 let is_image_huge = (image.px.width * image.px.height) > 2000 * 2000;
121 let allow_dither_map = use_dither_map == DitherMapMode::Always || (!is_image_huge && use_dither_map != DitherMapMode::None);
122 let generate_dither_map = allow_dither_map && image.dither_map.is_none();
123 if !generate_dither_map {
124 return Ok(None);
125 }
126
127 // If dithering (with dither map) is required, this image is used to find areas that require dithering
128 let (palette_error, row_pointers_remapped) = remap_to_palette(&mut image.px, None, image.importance_map.as_deref(), output_pixels, palette)?;
129 image.update_dither_map(&row_pointers_remapped, &*palette, uses_background)?;
130 Ok(Some(palette_error))
131 }
132
133 /// Set to 1.0 to get nice smooth image
134 pub fn set_dithering_level(&mut self, value: f32) -> Result<(), Error> {

Callers

nothing calls this directly

Calls 2

remap_to_paletteFunction · 0.85
update_dither_mapMethod · 0.80

Tested by

no test coverage detected