Trait rgb::ComponentMap

source ·
pub trait ComponentMap<DestPixel, SrcComponent, DestComponent> {
    // Required method
    fn map<Callback>(&self, f: Callback) -> DestPixel
       where Callback: FnMut(SrcComponent) -> DestComponent;
}
Expand description

Applying operation to every component

use rgb::ComponentMap;
let inverted = pixel.map(|c| 255 - c);

// For simple math there are Add/Sub/Mul implementations:
let halved = pixel.map(|c| c / 2);
let doubled = pixel * 2;

Required Methods§

source

fn map<Callback>(&self, f: Callback) -> DestPixelwhere Callback: FnMut(SrcComponent) -> DestComponent,

Convenience function (equivalent of self.iter().map().collect()) for applying the same formula to every component.

Note that it returns the pixel directly, not an Interator.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Copy, B> ComponentMap<ABGR<B>, T, B> for ABGR<T>

source§

impl<T: Copy, B> ComponentMap<ARGB<B>, T, B> for ARGB<T>

source§

impl<T: Copy, B> ComponentMap<BGR<B>, T, B> for BGR<T>

source§

impl<T: Copy, B> ComponentMap<BGRA<B>, T, B> for BGRA<T>

source§

impl<T: Copy, B> ComponentMap<Gray<B>, T, B> for Gray<T>

source§

impl<T: Copy, B> ComponentMap<GrayAlpha<B>, T, B> for GrayAlpha<T>

source§

impl<T: Copy, B> ComponentMap<RGB<B>, T, B> for RGB<T>

source§

impl<T: Copy, B> ComponentMap<RGBA<B>, T, B> for RGBA<T>