Skip to main content

Bitmap

Struct Bitmap 

Source
pub struct Bitmap {
    pub width: u32,
    pub height: u32,
    pub format: BitmapFormat,
    pub stride: u32,
    pub data: Vec<u8>,
}
Expand description

A bitmap image buffer.

Stores pixel data in row-major order. Each row is padded to stride bytes.

Fields§

§width: u32

Width in pixels.

§height: u32

Height in pixels.

§format: BitmapFormat

Pixel format.

§stride: u32

Row stride in bytes (may be larger than width * bytes_per_pixel).

§data: Vec<u8>

Raw pixel data.

Implementations§

Source§

impl Bitmap

Source

pub fn new(width: u32, height: u32, format: BitmapFormat) -> Self

Create a new bitmap filled with zeros.

Source

pub fn bitmap_create(width: u32, height: u32, alpha: bool) -> Self

Upstream-aligned alias for new().

Creates a new zero-filled bitmap. alpha = true selects BitmapFormat::Bgra32 (4 channels with alpha); alpha = false selects BitmapFormat::Rgb24 (3 channels, no alpha).

Corresponds to FPDFBitmap_Create.

Source

pub fn new_white(width: u32, height: u32, format: BitmapFormat) -> Self

Create a new bitmap filled with white (0xFF for all channels).

Source

pub fn width(&self) -> u32

Returns the bitmap width in pixels.

Corresponds to CFX_DIBBase::GetWidth() in PDFium.

Source

pub fn get_width(&self) -> u32

Upstream-aligned alias for width.

Corresponds to CFX_DIBBase::GetWidth() in PDFium.

Source

pub fn height(&self) -> u32

Returns the bitmap height in pixels.

Corresponds to CFX_DIBBase::GetHeight() in PDFium.

Source

pub fn get_height(&self) -> u32

Upstream-aligned alias for height.

Corresponds to CFX_DIBBase::GetHeight() in PDFium.

Source

pub fn format(&self) -> BitmapFormat

Returns the pixel format of this bitmap.

Corresponds to CFX_DIBBase::GetFormat() in PDFium.

Source

pub fn get_format(&self) -> BitmapFormat

Upstream-aligned alias for format.

Corresponds to CFX_DIBBase::GetFormat() in PDFium.

Source

pub fn bpp(&self) -> u32

Returns bits per pixel (8 × bytes_per_pixel).

Corresponds to CFX_DIBBase::GetBPP() in PDFium.

Source

pub fn get_bpp(&self) -> u32

Upstream-aligned alias for bpp.

Corresponds to CFX_DIBBase::GetBPP() in PDFium.

Source

pub fn pitch(&self) -> u32

Returns the number of bytes per scanline row.

Corresponds to CFX_DIBBase::GetPitch() / FPDFBitmap_GetStride in PDFium.

Source

pub fn get_pitch(&self) -> u32

ADR-019 alias for pitch().

Corresponds to CFX_DIBBase::GetPitch() in PDFium.

Source

pub fn bitmap_get_stride(&self) -> u32

Upstream-aligned alias for pitch().

Corresponds to FPDFBitmap_GetStride.

Source

pub fn get_stride(&self) -> u32

👎Deprecated:

use bitmap_get_stride() — matches upstream FPDFBitmap_GetStride

Deprecated — use bitmap_get_stride() — matches upstream FPDFBitmap_GetStride.

Source

pub fn stride(&self) -> u32

👎Deprecated since 0.0.0:

use pitch() or get_pitch() instead

Returns the number of bytes per scanline row.

Corresponds to FPDFBitmap_GetStride in PDFium’s public C API. Note: the upstream C++ method is CFX_DIBBase::GetPitch(); use pitch() / get_pitch() for the C++-aligned name.

Source

pub fn is_alpha_format(&self) -> bool

Returns true if the bitmap format has an alpha channel.

Corresponds to CFX_DIBBase::IsAlphaFormat() in PDFium.

Source

pub fn is_mask_format(&self) -> bool

Returns true if the bitmap is a mask format (1-bit or 8-bit alpha mask).

Corresponds to CFX_DIBBase::IsMaskFormat() in PDFium. In this implementation, Gray8 serves as the mask format (8-bit alpha mask).

Source

pub fn is_opaque_image(&self) -> bool

Returns true if the bitmap is opaque (no alpha channel and not a mask).

Corresponds to CFX_DIBBase::IsOpaqueImage() in PDFium. An image is opaque if it is neither a mask format nor has an alpha channel.

Source

pub fn is_premultiplied(&self) -> bool

Returns true if the bitmap uses premultiplied alpha.

Corresponds to CFX_DIBBase::IsPremultiplied() in PDFium. In PDFium with Skia, kBgraPremul format is premultiplied. In this implementation, Bgra32 is treated as premultiplied when used as a render target.

Source

pub fn bytes_per_pixel(&self) -> u32

Bytes per pixel for this bitmap’s format.

Source

pub fn data_size(&self) -> usize

Total data size in bytes.

Source

pub fn scanline(&self, y: u32) -> &[u8]

Get a row of pixel data by scanline index.

Corresponds to CFX_DIBBase::GetScanline() in PDFium.

§Panics

Panics if y >= self.height.

Source

pub fn get_scanline(&self, y: u32) -> &[u8]

Upstream-aligned Get* alias for scanline.

Corresponds to CFX_DIBBase::GetScanline() in PDFium.

§Panics

Panics if y >= self.height.

Source

pub fn row(&self, y: u32) -> &[u8]

👎Deprecated since 0.0.0:

use scanline() or get_scanline() instead

Rust-idiomatic alias for scanline.

§Panics

Panics if y >= self.height.

Source

pub fn convert_format(&self, target: BitmapFormat) -> Option<Self>

Convert this bitmap to a different pixel format.

Currently supports Rgba32 to Gray8 (luminosity formula: 0.299R + 0.587G + 0.114B). Returns a new Bitmap in the target format, or None if the conversion is not supported.

Source

pub fn scanline_mut(&mut self, y: u32) -> &mut [u8]

Get a mutable row of pixel data by scanline index.

Corresponds to CFX_DIBitmap::GetWritableScanline() in PDFium.

§Panics

Panics if y >= self.height.

Source

pub fn get_writable_scanline(&mut self, y: u32) -> &mut [u8]

Upstream-aligned Get* alias for scanline_mut.

Corresponds to CFX_DIBitmap::GetWritableScanline() in PDFium.

§Panics

Panics if y >= self.height.

Source

pub fn row_mut(&mut self, y: u32) -> &mut [u8]

👎Deprecated:

use scanline_mut() or get_writable_scanline() instead

Deprecated alias for scanline_mut.

§Panics

Panics if y >= self.height.

Source

pub fn fill_rect( &mut self, x: i32, y: i32, width: i32, height: i32, color: &[u8], ) -> bool

Fill a rectangle with color bytes (must match bytes_per_pixel()).

Clamps the rectangle to bitmap bounds. color slice length must equal bytes_per_pixel(). Returns false if color.len() != bytes_per_pixel().

Corresponds to FPDFBitmap_FillRect in PDFium’s public API.

Trait Implementations§

Source§

impl Clone for Bitmap

Source§

fn clone(&self) -> Bitmap

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bitmap

Source§

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

Formats the value using the given formatter. Read more

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.