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 const MAX_PIXELS: usize
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.
Sourcepub fn try_new(
width: u32,
height: u32,
r: u8,
g: u8,
b: u8,
a: u8,
) -> Result<Pixmap, PixmapError>
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.
Sourcepub 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
pub fn new(width: u32, height: u32, r: u8, g: u8, b: u8, a: u8) -> Pixmap
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.
Sourcepub fn white(width: u32, height: u32) -> Pixmap
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.
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 rotate_cw90(&self) -> Pixmap
pub fn rotate_cw90(&self) -> Pixmap
Rotate this pixmap 90° clockwise.
Sourcepub fn rotate_180(&self) -> Pixmap
pub fn rotate_180(&self) -> Pixmap
Rotate this pixmap 180°.
Sourcepub fn rotate_ccw90(&self) -> Pixmap
pub fn rotate_ccw90(&self) -> Pixmap
Rotate this pixmap 90° counter-clockwise.
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.
Trait Implementations§
impl Eq for Pixmap
impl StructuralPartialEq for Pixmap
Auto Trait Implementations§
impl Freeze for Pixmap
impl RefUnwindSafe for Pixmap
impl Send for Pixmap
impl Sync for Pixmap
impl Unpin for Pixmap
impl UnsafeUnpin for Pixmap
impl UnwindSafe for Pixmap
Blanket Implementations§
impl<T> Any for Twhere
T: Any,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> CloneAny for T
impl<T> CloneAny for T
impl<T> CloneAnySend for T
impl<T> CloneAnySendSync for T
impl<T> CloneAnySync for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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