#[repr(C)]pub struct ColorMode {
pub colortype: ColorType,
/* private fields */
}
Expand description
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
Implementations§
source§impl ColorMode
impl ColorMode
pub fn new() -> Self
pub fn colortype(&self) -> ColorType
pub fn set_colortype(&mut self, color: ColorType)
pub fn bitdepth(&self) -> u32
pub fn set_bitdepth(&mut self, d: u32)
pub fn try_set_bitdepth(&mut self, d: u32) -> Result<(), Error>
sourcepub fn set_palette(&mut self, palette: &[RGBA]) -> Result<(), Error>
pub fn set_palette(&mut self, palette: &[RGBA]) -> Result<(), Error>
Set color depth to 8-bit palette and set the colors
sourcepub fn palette_clear(&mut self)
pub fn palette_clear(&mut self)
Reset to 0 colors
pub fn palette(&self) -> &[RGBA]
pub fn palette_mut(&mut self) -> &mut [RGBA]
sourcepub fn bpp(&self) -> u32
pub fn bpp(&self) -> u32
get the total amount of bits per pixel, based on colortype and bitdepth in the struct
pub fn bpp_(&self) -> NonZeroU8
sourcepub fn channels(&self) -> u8
pub fn channels(&self) -> u8
get the amount of color channels used, based on colortype in the struct. If a palette is used, it counts as 1 channel.
sourcepub fn is_greyscale_type(&self) -> bool
pub fn is_greyscale_type(&self) -> bool
is it a greyscale type? (only colortype 0 or 4)
sourcepub fn is_alpha_type(&self) -> bool
pub fn is_alpha_type(&self) -> bool
has it got an alpha channel? (only colortype 2 or 6)
sourcepub fn is_palette_type(&self) -> bool
pub fn is_palette_type(&self) -> bool
has it got a palette? (only colortype 3)
sourcepub fn has_palette_alpha(&self) -> bool
pub 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.
sourcepub fn can_have_alpha(&self) -> bool
pub 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.