Struct lodepng::ffi::ColorMode
[−]
[src]
#[repr(C)]pub struct ColorMode { pub colortype: ColorType, pub bitdepth: c_uint, pub palette: *const RGBA<u8>, pub palettesize: usize, // some fields omitted }
Color mode of an image. Contains all information required to decode the pixel bits to RGBA colors. This information is the same as used in the PNG file format, and is used both for PNG and raw image data in LodePNG.
Fields
colortype: ColorType
color type, see PNG standard
bitdepth: c_uint
bits per sample, see PNG standard
palette: *const RGBA<u8>
palette (PLTE
and tRNS
)
Dynamically allocated with the colors of the palette, including alpha.
When encoding a PNG, to store your colors in the palette of the LodePNGColorMode, first use
lodepng_palette_clear, then for each color use lodepng_palette_add.
If you encode an image without alpha with palette, don't forget to put value 255 in each A byte of the palette.
When decoding, by default you can ignore this palette, since LodePNG already fills the palette colors in the pixels of the raw RGBA output.
The palette is only supported for color type 3.
palettesize: usize
palette size in number of colors (amount of bytes is 4 * palettesize
)
Methods
impl ColorMode
[src]
fn colortype(&self) -> ColorType
fn bitdepth(&self) -> u32
fn palette_clear(&mut self)
fn palette_add(&mut self, rgba: RGBA<u8>) -> Result<(), Error>
add 1 color to the palette
fn palette(&self) -> &[RGBA<u8>]
fn palette_mut(&mut self) -> &mut [RGBA<u8>]
fn bpp(&self) -> u32
get the total amount of bits per pixel, based on colortype and bitdepth in the struct
fn channels(&self) -> u32
get the amount of color channels used, based on colortype in the struct. If a palette is used, it counts as 1 channel.
fn is_greyscale_type(&self) -> bool
is it a greyscale type? (only colortype 0 or 4)
fn is_alpha_type(&self) -> bool
has it got an alpha channel? (only colortype 2 or 6)
fn is_palette_type(&self) -> bool
has it got a palette? (only colortype 3)
fn has_palette_alpha(&self) -> bool
only returns true if there is a palette and there is a value in the palette with alpha < 255. Loops through the palette to check this.
fn can_have_alpha(&self) -> bool
Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). Returns false if the image can only have opaque pixels. In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, or if "key_defined" is true.
fn raw_size(&self, w: c_uint, h: c_uint) -> usize
Returns the byte size of a raw image buffer with given width, height and color mode