pub struct ImageRef<'a> { /* private fields */ }Expand description
A borrowed, validated view of pixels to encode.
Rows run top to bottom with no padding between them. 16-bit samples are big-endian byte pairs (PNG’s own order); 1-, 2- and 4-bit grey samples are packed most significant bits first, each row starting on a fresh byte.
use pltrs_codec::png::{BitDepth, ColorType, ImageRef};
let pixels = [0u8; 3 * 2 * 4];
let image = ImageRef::rgba8(3, 2, &pixels)?;
assert_eq!(image.row_bytes(), 12);
// Two 16-bit grey pixels: 0x0102 and 0xFFFF.
let image = ImageRef::new(2, 1, ColorType::Gray, BitDepth::Sixteen, &[1, 2, 0xFF, 0xFF])?;
assert!(ImageRef::rgba8(3, 3, &pixels).is_err());Implementations§
Source§impl<'a> ImageRef<'a>
impl<'a> ImageRef<'a>
Sourcepub fn new(
width: u32,
height: u32,
color: ColorType,
bit_depth: BitDepth,
data: &'a [u8],
) -> Result<Self, EncodeError>
pub fn new( width: u32, height: u32, color: ColorType, bit_depth: BitDepth, data: &'a [u8], ) -> Result<Self, EncodeError>
Wraps data as a width × height image in the given format.
The encoder supports grey at every bit depth and grey + alpha, RGB and RGBA at 8 or 16 bits; indexed images are not supported.
Sourcepub fn rgba8(
width: u32,
height: u32,
data: &'a [u8],
) -> Result<Self, EncodeError>
pub fn rgba8( width: u32, height: u32, data: &'a [u8], ) -> Result<Self, EncodeError>
Wraps 8-bit RGBA pixels (4 bytes per pixel), the format of rendered figures.
Sourcepub fn rgb8(
width: u32,
height: u32,
data: &'a [u8],
) -> Result<Self, EncodeError>
pub fn rgb8( width: u32, height: u32, data: &'a [u8], ) -> Result<Self, EncodeError>
Wraps 8-bit RGB pixels (3 bytes per pixel).
Sourcepub const fn color_type(&self) -> ColorType
pub const fn color_type(&self) -> ColorType
Colour type of the pixels.
Trait Implementations§
impl<'a> Copy for ImageRef<'a>
impl<'a> Eq for ImageRef<'a>
impl<'a> StructuralPartialEq for ImageRef<'a>
Auto Trait Implementations§
impl<'a> Forget for ImageRef<'a>
impl<'a> Freeze for ImageRef<'a>
impl<'a> Move for ImageRef<'a>
impl<'a> RefUnwindSafe for ImageRef<'a>
impl<'a> Send for ImageRef<'a>
impl<'a> Sync for ImageRef<'a>
impl<'a> Unpin for ImageRef<'a>
impl<'a> UnsafeUnpin for ImageRef<'a>
impl<'a> UnwindSafe for ImageRef<'a>
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
Mutably borrows from an owned value. Read more