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: u32Width in pixels.
height: u32Height in pixels.
format: BitmapFormatPixel format.
stride: u32Row stride in bytes (may be larger than width * bytes_per_pixel).
data: Vec<u8>Raw pixel data.
Implementations§
Source§impl Bitmap
impl Bitmap
Sourcepub fn new(width: u32, height: u32, format: BitmapFormat) -> Self
pub fn new(width: u32, height: u32, format: BitmapFormat) -> Self
Create a new bitmap filled with zeros.
Sourcepub fn bitmap_create(width: u32, height: u32, alpha: bool) -> Self
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.
Sourcepub fn new_white(width: u32, height: u32, format: BitmapFormat) -> Self
pub fn new_white(width: u32, height: u32, format: BitmapFormat) -> Self
Create a new bitmap filled with white (0xFF for all channels).
Sourcepub fn width(&self) -> u32
pub fn width(&self) -> u32
Returns the bitmap width in pixels.
Corresponds to CFX_DIBBase::GetWidth() in PDFium.
Sourcepub fn get_width(&self) -> u32
pub fn get_width(&self) -> u32
Upstream-aligned alias for width.
Corresponds to CFX_DIBBase::GetWidth() in PDFium.
Sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
Returns the bitmap height in pixels.
Corresponds to CFX_DIBBase::GetHeight() in PDFium.
Sourcepub fn get_height(&self) -> u32
pub fn get_height(&self) -> u32
Upstream-aligned alias for height.
Corresponds to CFX_DIBBase::GetHeight() in PDFium.
Sourcepub fn format(&self) -> BitmapFormat
pub fn format(&self) -> BitmapFormat
Returns the pixel format of this bitmap.
Corresponds to CFX_DIBBase::GetFormat() in PDFium.
Sourcepub fn get_format(&self) -> BitmapFormat
pub fn get_format(&self) -> BitmapFormat
Upstream-aligned alias for format.
Corresponds to CFX_DIBBase::GetFormat() in PDFium.
Sourcepub fn bpp(&self) -> u32
pub fn bpp(&self) -> u32
Returns bits per pixel (8 × bytes_per_pixel).
Corresponds to CFX_DIBBase::GetBPP() in PDFium.
Sourcepub fn get_bpp(&self) -> u32
pub fn get_bpp(&self) -> u32
Upstream-aligned alias for bpp.
Corresponds to CFX_DIBBase::GetBPP() in PDFium.
Sourcepub fn pitch(&self) -> u32
pub fn pitch(&self) -> u32
Returns the number of bytes per scanline row.
Corresponds to CFX_DIBBase::GetPitch() / FPDFBitmap_GetStride in PDFium.
Sourcepub fn get_pitch(&self) -> u32
pub fn get_pitch(&self) -> u32
ADR-019 alias for pitch().
Corresponds to CFX_DIBBase::GetPitch() in PDFium.
Sourcepub fn bitmap_get_stride(&self) -> u32
pub fn bitmap_get_stride(&self) -> u32
Upstream-aligned alias for pitch().
Corresponds to FPDFBitmap_GetStride.
Sourcepub fn get_stride(&self) -> u32
👎Deprecated: use bitmap_get_stride() — matches upstream FPDFBitmap_GetStride
pub fn get_stride(&self) -> u32
use bitmap_get_stride() — matches upstream FPDFBitmap_GetStride
Deprecated — use bitmap_get_stride() — matches upstream FPDFBitmap_GetStride.
Sourcepub fn stride(&self) -> u32
👎Deprecated since 0.0.0: use pitch() or get_pitch() instead
pub fn stride(&self) -> u32
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.
Sourcepub fn is_alpha_format(&self) -> bool
pub fn is_alpha_format(&self) -> bool
Returns true if the bitmap format has an alpha channel.
Corresponds to CFX_DIBBase::IsAlphaFormat() in PDFium.
Sourcepub fn is_mask_format(&self) -> bool
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).
Sourcepub fn is_opaque_image(&self) -> bool
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.
Sourcepub fn is_premultiplied(&self) -> bool
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.
Sourcepub fn bytes_per_pixel(&self) -> u32
pub fn bytes_per_pixel(&self) -> u32
Bytes per pixel for this bitmap’s format.
Sourcepub fn scanline(&self, y: u32) -> &[u8] ⓘ
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.
Sourcepub fn get_scanline(&self, y: u32) -> &[u8] ⓘ
pub fn get_scanline(&self, y: u32) -> &[u8] ⓘ
Sourcepub fn row(&self, y: u32) -> &[u8] ⓘ
👎Deprecated since 0.0.0: use scanline() or get_scanline() instead
pub fn row(&self, y: u32) -> &[u8] ⓘ
use scanline() or get_scanline() instead
Sourcepub fn convert_format(&self, target: BitmapFormat) -> Option<Self>
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.
Sourcepub fn scanline_mut(&mut self, y: u32) -> &mut [u8] ⓘ
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.
Sourcepub fn get_writable_scanline(&mut self, y: u32) -> &mut [u8] ⓘ
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.
Sourcepub fn row_mut(&mut self, y: u32) -> &mut [u8] ⓘ
👎Deprecated: use scanline_mut() or get_writable_scanline() instead
pub fn row_mut(&mut self, y: u32) -> &mut [u8] ⓘ
use scanline_mut() or get_writable_scanline() instead
Sourcepub fn fill_rect(
&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
color: &[u8],
) -> bool
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.