pub struct HalfBlockImage {
pub width: u32,
pub height: u32,
pub pixels: Vec<(Color, Color)>,
}Expand description
A terminal-renderable image stored as a grid of Color values.
Each cell contains a foreground color (upper pixel) and background color
(lower pixel), rendered using the ▀ half-block character.
Create from an image::DynamicImage with HalfBlockImage::from_dynamic
(requires image feature), or construct manually from raw RGB data with
HalfBlockImage::from_rgb.
Fields§
§width: u32Width in terminal columns.
height: u32Height in terminal rows (each row = 2 image pixels).
pixels: Vec<(Color, Color)>Row-major pairs of (upper_color, lower_color) for each cell.
Implementations§
Source§impl HalfBlockImage
impl HalfBlockImage
Sourcepub fn from_dynamic(img: &DynamicImage, width: u32, height: u32) -> Self
Available on crate feature image only.
pub fn from_dynamic(img: &DynamicImage, width: u32, height: u32) -> Self
image only.Create a half-block image from a DynamicImage, resized to fit
the given terminal cell dimensions.
The image is resized to width x (height * 2) pixels using Lanczos3
filtering, then each pair of vertically adjacent pixels is packed
into one terminal cell.
If width * height * 2 would overflow or exceed the crate-internal
image pixel cap (~16M pixels), returns an empty image rather than
panicking or allocating gigabytes. Legitimate terminal-scale inputs
are far below this cap.
Source§impl HalfBlockImage
impl HalfBlockImage
Sourcepub fn from_rgb(rgb_data: &[u8], width: u32, height: u32) -> Self
pub fn from_rgb(rgb_data: &[u8], width: u32, height: u32) -> Self
Create a half-block image from raw RGB pixel data.
rgb_data must contain width x pixel_height x 3 bytes in row-major
RGB order, where pixel_height = height * 2. Oversized inputs that
would overflow or exceed the crate-internal image pixel cap are
returned as an empty image instead of allocating.