Struct bevy_retrograde::core::image::math::nq::NeuQuant [−]
pub struct NeuQuant { /* fields omitted */ }
Use the color_quant
crate instead
Expand description
Neural network color quantizer
Examples
use image::imageops::colorops::{index_colors, ColorMap}; use image::math::nq::NeuQuant; use image::{ImageBuffer, Rgba, RgbaImage}; // Create simple color image with RGBA pixels. let (w, h) = (2, 2); let red: Rgba<u8> = [255, 0, 0, 255].into(); let green: Rgba<u8> = [0, 255, 0, 255].into(); let blue: Rgba<u8> = [0, 0, 255, 255].into(); let white: Rgba<u8> = [255, 255, 255, 255].into(); let mut color_image = RgbaImage::new(w, h); color_image.put_pixel(0, 0, red); color_image.put_pixel(1, 0, green); color_image.put_pixel(0, 1, blue); color_image.put_pixel(1, 1, white); // Create a `NeuQuant` colormap that will build an approximate color palette that best matches // the original image. // Note, the NeuQuant algorithm is only designed to work with 6-8 bit output, so `colors` // should be a power of 2 in the range [64, 256]. let pixels = color_image.clone().into_raw(); let cmap = NeuQuant::new(1, 256, &pixels); // Map the original image through the color map to create an indexed image stored in a // `GrayImage`. let palletized = index_colors(&color_image, &cmap); // Map indexed image back `RgbaImage`. Note the NeuQuant algorithm creates an approximation of // the original colors, so even in this simple example the output is not pixel equivalent to // the original. let mapped = ImageBuffer::from_fn(w, h, |x, y| -> Rgba<u8> { let p = palletized.get_pixel(x, y); cmap.lookup(p.0[0] as usize) .expect("indexed color out-of-range") .into() });
Implementations
impl NeuQuant
impl NeuQuant
The implementation only calls the corresponding inner color_quant
methods.
These exist purely to keep a type separate from color_quant::NeuQuant
and the interface
stable for this major version. The type will be changed to a pure re-export in the next
version or might be removed.
Trait Implementations
pub fn has_lookup(&self) -> bool
pub fn has_lookup(&self) -> bool
Indicate NeuQuant implements lookup
.
Returns the index of the closest match of color
in the color map. Read more
Looks up color by index in the color map. If idx
is out of range for the color map, or
ColorMap doesn’t implement lookup
None
is returned. Read more
Auto Trait Implementations
impl RefUnwindSafe for NeuQuant
impl UnwindSafe for NeuQuant
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V