Type Alias rsvg::surface_utils::Pixel
source · pub type Pixel = RGBA8;
Expand description
A pixel consisting of R, G, B and A values.
Aliased Type§
struct Pixel {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Fields§
§r: u8
Red Component
g: u8
Green Component
b: u8
Blue Component
a: u8
Alpha Component
Trait Implementations§
source§impl PixelOps for Pixel
impl PixelOps for Pixel
source§fn unpremultiply(self) -> Self
fn unpremultiply(self) -> Self
Returns an unpremultiplied value of this pixel.
For a fully transparent pixel, a transparent black pixel will be returned.
source§fn premultiply(self) -> Self
fn premultiply(self) -> Self
Returns a premultiplied value of this pixel.
source§fn to_luminance_mask(&self) -> Self
fn to_luminance_mask(&self) -> Self
Returns a ‘mask’ pixel with only the alpha channel
Assuming, the pixel is linear RGB (not sRGB) y = luminance Y = 0.2126 R + 0.7152 G + 0.0722 B 1.0 opacity = 255
When Y = 1.0, pixel for mask should be 0xFFFFFFFF (you get 1.0 luminance from 255 from R, G and B)
r_mult = 0xFFFFFFFF / (255.0 * 255.0) * .2126 = 14042.45 ~= 14042 g_mult = 0xFFFFFFFF / (255.0 * 255.0) * .7152 = 47239.69 ~= 47240 b_mult = 0xFFFFFFFF / (255.0 * 255.0) * .0722 = 4768.88 ~= 4769
This allows for the following expected behaviour: (we only care about the most significant byte) if pixel = 0x00FFFFFF, pixel’ = 0xFF…… if pixel = 0x00020202, pixel’ = 0x02…… if pixel = 0x00000000, pixel’ = 0x00……
source§fn to_u32(&self) -> u32
fn to_u32(&self) -> u32
Returns the pixel value as a u32
, in the same format as cairo::Format::ARgb32
.
source§fn from_u32(x: u32) -> Self
fn from_u32(x: u32) -> Self
Converts a u32
in the same format as cairo::Format::ARgb32
into a Pixel
.