Skip to main content

Pixmap

Struct Pixmap 

Source
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

Source

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.

Source

pub fn white(width: u32, height: u32) -> Self

Create a white opaque pixmap.

Source

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).

Source

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.

Source

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.

Source

pub fn to_rgb(&self) -> Vec<u8>

Extract RGB pixel data (3 bytes per pixel), discarding alpha.

Source

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.

Source

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.

Trait Implementations§

Source§

impl AsRef<[u8]> for Pixmap

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Pixmap

Source§

fn clone(&self) -> Pixmap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Pixmap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pixmap

Source§

fn default() -> Pixmap

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Pixmap

Source§

fn eq(&self, other: &Pixmap) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Pixmap

Source§

impl StructuralPartialEq for Pixmap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.