PdfBitmap

Struct PdfBitmap 

Source
pub struct PdfBitmap<'a> { /* private fields */ }
Expand description

A bitmap image with a specific width and height.

Implementations§

Source§

impl<'a> PdfBitmap<'a>

Source

pub fn empty( width: Pixels, height: Pixels, format: PdfBitmapFormat, bindings: &'a dyn PdfiumLibraryBindings, ) -> Result<PdfBitmap<'a>, PdfiumError>

Creates an empty PdfBitmap with a buffer capable of storing an image of the given pixel width and height in the given pixel format.

Source

pub unsafe fn from_bytes( width: Pixels, height: Pixels, format: PdfBitmapFormat, buffer: &'a mut [u8], bindings: &'a dyn PdfiumLibraryBindings, ) -> Result<PdfBitmap<'a>, PdfiumError>

Creates a new PdfBitmap that wraps the given byte buffer. The buffer must be capable of storing an image of the given pixel width and height in the given pixel format, otherwise a buffer overflow may occur during rendering.

This function is not available when compiling to WASM.

§Safety

This function is unsafe because a buffer overflow may occur during rendering if the buffer is too small to store a rendered image of the given pixel dimensions.

Source

pub fn bindings(&self) -> &dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings used by this PdfBitmap.

Source

pub fn width(&self) -> Pixels

Returns the width of the image in the bitmap buffer backing this PdfBitmap.

Source

pub fn height(&self) -> Pixels

Returns the height of the image in the bitmap buffer backing this PdfBitmap.

Source

pub fn format(&self) -> Result<PdfBitmapFormat, PdfiumError>

Returns the pixel format of the image in the bitmap buffer backing this PdfBitmap.

Source

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

Returns an immutable reference to the bitmap buffer backing this PdfBitmap.

Unlike PdfBitmap::as_rgba_bytes, this function does not attempt any color channel normalization. To adjust color channels in your own code, use the PdfiumLibraryBindings::bgr_to_rgba, PdfiumLibraryBindings::bgra_to_rgba, PdfiumLibraryBindings::rgb_to_bgra, and PdfiumLibraryBindings::rgba_to_bgra functions.

Source

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

Returns an owned copy of the bitmap buffer backing this PdfBitmap, normalizing all color channels into RGBA irrespective of the original pixel format.

Source

pub fn as_image(&self) -> DynamicImage

Returns a new Image::DynamicImage created from the bitmap buffer backing this PdfBitmap.

This function is only available when this crate’s image feature is enabled.

Source

pub fn as_array(&self) -> Uint8Array

Returns a Javascript Uint8Array object representing the bitmap buffer backing this PdfBitmap.

This function avoids a memory allocation and copy required by both PdfBitmap::as_rgba_bytes and PdfBitmap::as_image_data, making it preferable for situations where performance is paramount.

Unlike PdfBitmap::as_rgba_bytes, this function does not attempt any color channel normalization. To adjust color channels in your own code, use the PdfiumLibraryBindings::bgr_to_rgba, PdfiumLibraryBindings::bgra_to_rgba, PdfiumLibraryBindings::rgb_to_bgra, and PdfiumLibraryBindings::rgba_to_bgra functions.

This function is only available when compiling to WASM.

Source

pub fn as_image_data(&self) -> Result<ImageData, JsValue>

Returns a new Javascript ImageData object created from the bitmap buffer backing this PdfBitmap. The resulting ImageData can be easily displayed in an HTML <canvas> element like so:

canvas.getContext('2d').putImageData(image_data);

This function is slower than calling PdfBitmap::as_array because it must perform an additional memory allocation in order to create the ImageData object. Consider calling the PdfBitmap::as_array function directly if performance is paramount.

This function is only available when compiling to WASM.

Source

pub fn bytes_required_for_size(width: Pixels, height: Pixels) -> usize

Estimates the maximum memory buffer size required for a PdfBitmap of the given dimensions.

Certain platforms, architectures, and operating systems may limit the maximum size of a bitmap buffer that can be created by Pdfium.

The returned value assumes four bytes of memory will be consumed for each rendered pixel.

Trait Implementations§

Source§

impl<'a> Drop for PdfBitmap<'a>

Source§

fn drop(&mut self)

Closes this PdfBitmap, releasing the memory held by the bitmap buffer.

Auto Trait Implementations§

§

impl<'a> Freeze for PdfBitmap<'a>

§

impl<'a> !RefUnwindSafe for PdfBitmap<'a>

§

impl<'a> !Send for PdfBitmap<'a>

§

impl<'a> !Sync for PdfBitmap<'a>

§

impl<'a> Unpin for PdfBitmap<'a>

§

impl<'a> !UnwindSafe for PdfBitmap<'a>

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