pub trait Pixel: Clone + Copy + Debug + Default + PartialEq + Sealed {
type Chan: Channel;
type Model: ColorModel;
type Alpha: Alpha;
type Gamma: Gamma;
Show 22 methods
// Required methods
fn from_channels(ch: &[Self::Chan]) -> Self;
fn from_bit_depth<P>(p: P) -> Self
where P: Pixel,
Self::Chan: From<P::Chan>;
fn channels(&self) -> &[Self::Chan];
fn channels_mut(&mut self) -> &mut [Self::Chan];
// Provided methods
fn one(self) -> Self::Chan { ... }
fn one_mut(&mut self) -> &mut Self::Chan { ... }
fn two(self) -> Self::Chan { ... }
fn two_mut(&mut self) -> &mut Self::Chan { ... }
fn three(self) -> Self::Chan { ... }
fn three_mut(&mut self) -> &mut Self::Chan { ... }
fn four(self) -> Self::Chan { ... }
fn four_mut(&mut self) -> &mut Self::Chan { ... }
fn alpha(self) -> Self::Chan { ... }
fn alpha_mut(&mut self) -> &mut Self::Chan { ... }
fn convert<D>(self) -> D
where D: Pixel,
D::Chan: From<Self::Chan> { ... }
fn copy_color(dst: &mut [Self], clr: &Self) { ... }
fn copy_slice(dst: &mut [Self], src: &[Self]) { ... }
fn composite_color<O>(dst: &mut [Self], clr: &Self, op: O)
where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend { ... }
fn composite_matte<M, O>(dst: &mut [Self], src: &[M], clr: &Self, op: O)
where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
M: Pixel<Chan = Self::Chan, Model = Matte, Gamma = Linear>,
O: Blend { ... }
fn composite_slice<O>(dst: &mut [Self], src: &[Self], op: O)
where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend { ... }
fn composite_channels<O>(&mut self, src: &Self, op: O)
where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend { ... }
fn composite_channels_alpha<O>(
&mut self,
src: &Self,
op: O,
alpha: &Self::Chan
)
where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend { ... }
}
Expand description
Pixel channel, color model, alpha and gamma mode.
A pixel can be converted to another format using the convert method.
Type Alias Naming Scheme
- Gamma:
S
for sRGB gamma encoding; linear if omitted. - Color model:
Rgb
/Bgr
/Gray
/Cmy
/Hsv
/Hsl
/Hwb
/YCbCr
/Matte
. - Alpha:
a
to include alpha channel enabling translucent pixels. - Bit depth:
8
/16
/32
for 8-bit integer, 16-bit integer and 32-bit floating-point channels. - Alpha mode:
p
for premultiplied; straight if omitted.
This trait is sealed, and cannot be implemented outside of this crate.
Required Associated Types§
sourcetype Model: ColorModel
type Model: ColorModel
Color model
Required Methods§
sourcefn from_channels(ch: &[Self::Chan]) -> Self
fn from_channels(ch: &[Self::Chan]) -> Self
Make a pixel from a slice of channels.
sourcefn from_bit_depth<P>(p: P) -> Selfwhere
P: Pixel,
Self::Chan: From<P::Chan>,
fn from_bit_depth<P>(p: P) -> Selfwhere P: Pixel, Self::Chan: From<P::Chan>,
Convert from a pixel with a different bit depth.
sourcefn channels_mut(&mut self) -> &mut [Self::Chan]
fn channels_mut(&mut self) -> &mut [Self::Chan]
Get the channels mutably.
Provided Methods§
sourcefn alpha(self) -> Self::Chan
fn alpha(self) -> Self::Chan
Get the alpha channel.
Example: Get Alpha
use pix::chan::Ch16;
use pix::el::Pixel;
use pix::gray::Graya16;
let p = Graya16::new(0x7090, 0x6010);
assert_eq!(p.alpha(), Ch16::new(0x6010));
sourcefn alpha_mut(&mut self) -> &mut Self::Chan
fn alpha_mut(&mut self) -> &mut Self::Chan
Get a mutable reference to the alpha channel.
Panics
Panics if the pixel does not contain an alpha channel.
Example: Set Alpha
use pix::chan::Ch8;
use pix::el::Pixel;
use pix::rgb::Rgba8;
let mut p = Rgba8::new(0xFF, 0x40, 0x80, 0xA5);
*p.alpha_mut() = Ch8::new(0x4B);
assert_eq!(p.alpha(), Ch8::new(0x4B));
sourcefn convert<D>(self) -> Dwhere
D: Pixel,
D::Chan: From<Self::Chan>,
fn convert<D>(self) -> Dwhere D: Pixel, D::Chan: From<Self::Chan>,
Convert a pixel to another format
D
Destination format.
sourcefn copy_color(dst: &mut [Self], clr: &Self)
fn copy_color(dst: &mut [Self], clr: &Self)
Copy a color to a pixel slice
sourcefn copy_slice(dst: &mut [Self], src: &[Self])
fn copy_slice(dst: &mut [Self], src: &[Self])
Copy a slice to another
sourcefn composite_color<O>(dst: &mut [Self], clr: &Self, op: O)where
Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend,
fn composite_color<O>(dst: &mut [Self], clr: &Self, op: O)where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>, O: Blend,
Composite a color with a pixel slice
sourcefn composite_matte<M, O>(dst: &mut [Self], src: &[M], clr: &Self, op: O)where
Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
M: Pixel<Chan = Self::Chan, Model = Matte, Gamma = Linear>,
O: Blend,
fn composite_matte<M, O>(dst: &mut [Self], src: &[M], clr: &Self, op: O)where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>, M: Pixel<Chan = Self::Chan, Model = Matte, Gamma = Linear>, O: Blend,
Composite matte with color to destination pixel slice
sourcefn composite_slice<O>(dst: &mut [Self], src: &[Self], op: O)where
Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend,
fn composite_slice<O>(dst: &mut [Self], src: &[Self], op: O)where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>, O: Blend,
Composite two slices of pixels
sourcefn composite_channels<O>(&mut self, src: &Self, op: O)where
Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend,
fn composite_channels<O>(&mut self, src: &Self, op: O)where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>, O: Blend,
Composite the channels of two pixels
sourcefn composite_channels_alpha<O>(&mut self, src: &Self, op: O, alpha: &Self::Chan)where
Self: Pixel<Alpha = Premultiplied, Gamma = Linear>,
O: Blend,
fn composite_channels_alpha<O>(&mut self, src: &Self, op: O, alpha: &Self::Chan)where Self: Pixel<Alpha = Premultiplied, Gamma = Linear>, O: Blend,
Composite the channels of two pixels with alpha