pub struct Pixmap {
pub width: u32,
pub height: u32,
pub data: Vec<u8>,
}Expand description
An RGBA pixel image, 4 bytes per pixel.
Row-major, top-to-bottom. Alpha is always 255 for DjVu pages.
Fields§
§width: u32§height: u32§data: Vec<u8>RGBA pixel data, row-major. Length = width * height * 4.
Implementations§
Source§impl Pixmap
impl Pixmap
Sourcepub fn new(width: u32, height: u32, r: u8, g: u8, b: u8, a: u8) -> Self
pub fn new(width: u32, height: u32, r: u8, g: u8, b: u8, a: u8) -> Self
Create a new pixmap filled with the given RGBA color.
Returns an empty 0×0 pixmap if width * height would exceed
64 MiB pixels or overflow usize, preventing OOM from extreme
DPI values.
Sourcepub fn set_rgb(&mut self, x: u32, y: u32, r: u8, g: u8, b: u8)
pub fn set_rgb(&mut self, x: u32, y: u32, r: u8, g: u8, b: u8)
Set pixel at (x, y) to an RGB value (alpha = 255). Silently ignores out-of-bounds writes (e.g. on an empty overflow pixmap).
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<&[u8]>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<&[u8]>
Get the 4 RGBA bytes at pixel (x, y), or None if out of bounds.
Sourcepub fn get_rgb(&self, x: u32, y: u32) -> (u8, u8, u8)
pub fn get_rgb(&self, x: u32, y: u32) -> (u8, u8, u8)
Get RGB at (x, y). Returns (0, 0, 0) for out-of-bounds reads.
Sourcepub fn to_rgb(&self) -> Vec<u8> ⓘ
pub fn to_rgb(&self) -> Vec<u8> ⓘ
Extract RGB pixel data (3 bytes per pixel), discarding alpha.
Sourcepub fn to_ppm(&self) -> Vec<u8> ⓘ
pub fn to_ppm(&self) -> Vec<u8> ⓘ
Encode as PPM (binary, P6 format).
This is the format produced by ddjvu -format=ppm.
Discards alpha channel.
Sourcepub fn to_gray8(&self) -> GrayPixmap
pub fn to_gray8(&self) -> GrayPixmap
Convert to 8-bit grayscale using ITU-R BT.601 luminance weights.
Y = 0.299·R + 0.587·G + 0.114·B
Returns a GrayPixmap with data.len() == width * height.