1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
// matte.rs Alpha matte color model. // // Copyright (c) 2019-2020 Douglas P Lau // Copyright (c) 2019-2020 Jeron Aldaron Lau // //! Matte color model and types. use crate::chan::{Ch16, Ch32, Ch8, Channel, Linear, Straight}; use crate::el::{Pix1, PixRgba, Pixel}; use crate::ColorModel; use std::ops::Range; /// Matte [color model]. /// /// The component is *[alpha]* only. /// /// [alpha]: ../el/trait.Pixel.html#method.alpha /// [color model]: ../trait.ColorModel.html #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct Matte {} impl ColorModel for Matte { const CIRCULAR: Range<usize> = 0..0; const LINEAR: Range<usize> = 0..0; const ALPHA: usize = 0; /// Convert into *red*, *green*, *blue* and *alpha* components fn into_rgba<P>(p: P) -> PixRgba<P> where P: Pixel<Model = Self>, { let max = P::Chan::MAX; PixRgba::<P>::new::<P::Chan>(max, max, max, p.alpha()) } /// Convert from *red*, *green*, *blue* and *alpha* components fn from_rgba<P>(rgba: PixRgba<P>) -> P where P: Pixel<Model = Self>, { let chan = rgba.channels(); P::from_channels(&[chan[3]]) } } /// [Matte](struct.Matte.html) 8-bit [straight](../chan/struct.Straight.html) /// alpha [linear](../chan/struct.Linear.html) gamma /// [pixel](../el/trait.Pixel.html) format. pub type Matte8 = Pix1<Ch8, Matte, Straight, Linear>; /// [Matte](struct.Matte.html) 16-bit [straight](../chan/struct.Straight.html) /// alpha [linear](../chan/struct.Linear.html) gamma /// [pixel](../el/trait.Pixel.html) format. pub type Matte16 = Pix1<Ch16, Matte, Straight, Linear>; /// [Matte](struct.Matte.html) 32-bit [straight](../chan/struct.Straight.html) /// alpha [linear](../chan/struct.Linear.html) gamma /// [pixel](../el/trait.Pixel.html) format. pub type Matte32 = Pix1<Ch32, Matte, Straight, Linear>;