pub struct Bitmap {
pub width: u32,
pub height: u32,
pub data: Vec<u8>,
}Expand description
A 1-bit-per-pixel packed bitmap image.
Pixels are packed 8-per-byte, MSB first within each byte. Each row is padded to a byte boundary. Pixel value 1 = black, 0 = white (matching PBM convention).
Fields§
§width: u32§height: u32§data: Vec<u8>Packed pixel data, row-major. Row stride = row_stride() bytes.
Implementations§
Source§impl Bitmap
impl Bitmap
Sourcepub fn row_stride(&self) -> usize
pub fn row_stride(&self) -> usize
Bytes per row (each row padded to byte boundary).
Sourcepub fn get(&self, x: u32, y: u32) -> bool
pub fn get(&self, x: u32, y: u32) -> bool
Get pixel value at (x, y). Returns true if black (1).
Panics if out of bounds.
Sourcepub fn set(&mut self, x: u32, y: u32, val: bool)
pub fn set(&mut self, x: u32, y: u32, val: bool)
Set pixel value at (x, y). val = true means black (1).
Panics if out of bounds.
Sourcepub fn set_black(&mut self, x: u32, y: u32)
pub fn set_black(&mut self, x: u32, y: u32)
OR a black pixel at (x, y). Used for JB2 blit compositing.
Sourcepub fn dilate(&self) -> Bitmap
pub fn dilate(&self) -> Bitmap
Return a new bitmap with each black pixel expanded to its 4-connected neighbors (1-pixel morphological dilation). Thickens every stroke by ~2 pixels total, improving legibility at reduced display sizes.
Sourcepub fn to_pbm(&self) -> Vec<u8> ⓘ
pub fn to_pbm(&self) -> Vec<u8> ⓘ
Encode as PBM (binary, P4 format).
This is the format produced by ddjvu -format=pbm.
Sourcepub fn dilate_n(self, passes: u32) -> Self
pub fn dilate_n(self, passes: u32) -> Self
Perform passes rounds of 4-connected morphological dilation using
packed bitwise operations and two pre-allocated ping-pong buffers.
Zero allocations after the initial setup; much faster than calling
dilate() N times for passes > 1.
Pixel layout (MSB-first): bit 7 of each byte = leftmost pixel in that
group of 8. Horizontal dilation uses byte >> 1 (right) and
byte << 1 (left) with cross-byte carries; vertical dilation ORs
each row into its neighbours.
Trait Implementations§
impl Eq for Bitmap
impl StructuralPartialEq for Bitmap
Auto Trait Implementations§
impl Freeze for Bitmap
impl RefUnwindSafe for Bitmap
impl Send for Bitmap
impl Sync for Bitmap
impl Unpin for Bitmap
impl UnsafeUnpin for Bitmap
impl UnwindSafe for Bitmap
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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