pub struct Image { /* private fields */ }Expand description
A decoded image: rows top to bottom, each pixel its mode’s bytes, red
first. It holds the Charge for its pixels, returned when it drops,
after the pixels’ buffer is freed.
Implementations§
Source§impl Image
impl Image
Sourcepub fn pixels(&self) -> &[u8] ⓘ
pub fn pixels(&self) -> &[u8] ⓘ
The pixels: what Pillow’s tobytes() gives for the image UnityPy
returns. One exception: tobytes(), and so a PNG save, raises
MemoryError for an image wider than INT_MAX / bits - 7 pixels,
bits its mode’s (its raw encoder’s cap, src/encode.c:260-262):
67,108,856 for RGBA, 89,478,478 for RGB. The images that wide
that decode, in UnityPy as here, are a BCn texture’s in RGBA:
67,108,857 to 67,108,864 wide at a height of 1 or 2, and 67,108,860
or 67,108,864 wide at a height of 4 (a height of 3, or another width
at 4, is a DecodeError::DecompressionBomb); and a raw texture’s
whose raw mode takes fewer bits a pixel than its image’s mode, up to
that raw mode’s cap (step 5): Alpha8’s, ARGB4444’s and RGBA4444’s in
RGBA, R8’s and RGB565’s in RGB. A PNG writer mirrors that cap.
Sourcepub fn into_parts(self) -> (Vec<u8>, Charge)
pub fn into_parts(self) -> (Vec<u8>, Charge)
The pixels and their charge, which must live as long as the pixels’
allocation does: drop the charge last. Beware let (pixels, charge) = image.into_parts();: a pattern’s bindings drop in reverse order, so
that drops charge first, returning its bytes while the buffer still
holds them. Drop the pixels first (drop(pixels)), or keep the
charge in an owner that outlives them.