Skip to main content

Crate palpngrs

Crate palpngrs 

Source

Structs§

Offset
A 2-D offset in coordinate type T.
PalettizedImageWithMetadata
A palettized image plus the offsets and dimensions needed to place it inside its original canvas.
Size
A 2-D size (width by height) in coordinate type T.

Enums§

Error
Errors produced by the public API of palpngrs.
Palette0Pixels
How read_png treats opaque pixels whose colour exactly matches palette[0].

Traits§

Coord
Numeric type usable as an offset or size on PalettizedImageWithMetadata. Blanket-implemented for every Copy type that round-trips through u32 (u8, u16, u32, u64, i32, usize, …).

Functions§

draw_image_to_pixel_buffer
Draws a palettized image into an RGB(A) pixel buffer (Vec<u8>). Uses the given palette for colour lookups.
greyscale_palette
Returns greyscale palette with 256 entries
palettized_image_to_png
Given a palettized image and a palette, this function will create a PNG image in the specified output_path. When use_transparency is true the output is RGBA (palette index 0 is written with alpha 0, everything else with alpha 255); when false it is RGB.
palettized_image_with_metadata_to_png
Given a PalettizedImageWithMetadata and a palette, this function will create a PNG image in the specified output_path sized to the original_width × original_height canvas, with the palettized data placed at (x_offset, y_offset). This is the round-trip counterpart of read_png with trim_transparent_pixels = true.
read_png
Reads a PNG file and creates an PalettizedImageWithMetadata by doing colour lookups using the given palette. If trim_transparent_pixels is set to true, any rows or columns where all pixels are transparent will be trimmed away, so that only the non-transparent parts of the image remains.
read_rgb_palette
Reads a Palette file. Expects exactly 768 bytes (256 RGB entries * 3 bytes); returns Error::PaletteFileWrongLength if the file is shorter or longer than that. Underlying file-system failures are returned as Error::Io.
save_pixels_to_image_file
Saves the given pixel buffer to the given output path. When use_transparency is true the buffer is interpreted as RGBA (4 bytes per pixel); when false it is interpreted as RGB (3 bytes per pixel). Returns Error::Validation if the buffer length does not match width * height * channels (or if that product itself overflows usize), or Error::Image if the underlying encode/write fails.