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 const MAX_PIXELS: usize

Maximum pixels per pixmap (64 megapixels, 256 MiB of RGBA).

Anything beyond this is a runaway DPI. Pixmap::try_new refuses it with PixmapError::TooLarge instead of attempting the allocation.

Source

pub fn try_new( width: u32, height: u32, r: u8, g: u8, b: u8, a: u8, ) -> Result<Pixmap, PixmapError>

Create a new pixmap filled with the given RGBA color.

§Errors

PixmapError::Overflow when width * height does not fit in usize; PixmapError::TooLarge when it exceeds Pixmap::MAX_PIXELS. Nothing is allocated in either case.

Source

pub fn new(width: u32, height: u32, r: u8, g: u8, b: u8, a: u8) -> Pixmap

👎Deprecated since 0.34.0:

use Pixmap::try_new, which reports an oversized request instead of returning an empty pixmap

Create a new pixmap filled with the given RGBA color.

Returns an empty 0×0 pixmap if width * height would exceed Pixmap::MAX_PIXELS or overflow usize. That silent fallback is why this constructor is deprecated: use Pixmap::try_new and handle the PixmapError instead.

Source

pub fn try_white(width: u32, height: u32) -> Result<Pixmap, PixmapError>

Create a white opaque pixmap.

§Errors

The same as Pixmap::try_new.

Source

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

Create a white opaque pixmap.

Returns an empty 0×0 pixmap when the size is refused; see Pixmap::try_white for the variant that reports why.

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 rotate_cw90(&self) -> Pixmap

Rotate this pixmap 90° clockwise.

Source

pub fn rotate_180(&self) -> Pixmap

Rotate this pixmap 180°.

Source

pub fn rotate_ccw90(&self) -> Pixmap

Rotate this pixmap 90° counter-clockwise.

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<(), Error>

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 Eq for Pixmap

Source§

impl PartialEq for Pixmap

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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> Any for T
where T: Any,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneAnySend for T
where T: Any + Send + Clone,

Source§

impl<T> CloneAnySendSync for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> CloneAnySync for T
where T: Any + Sync + Clone,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V