Struct lodepng::ffi::ColorMode

source ·
#[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

source

pub fn new() -> Self

source

pub fn colortype(&self) -> ColorType

source

pub fn set_colortype(&mut self, color: ColorType)

source

pub fn bitdepth(&self) -> u32

source

pub fn set_bitdepth(&mut self, d: u32)

source

pub fn try_set_bitdepth(&mut self, d: u32) -> Result<(), Error>

source

pub fn set_palette(&mut self, palette: &[RGBA]) -> Result<(), Error>

Set color depth to 8-bit palette and set the colors

source

pub fn palette_clear(&mut self)

Reset to 0 colors

source

pub fn palette_add(&mut self, p: RGBA) -> Result<(), Error>

add 1 color to the palette

source

pub fn palette(&self) -> &[RGBA]

source

pub fn palette_mut(&mut self) -> &mut [RGBA]

source

pub fn bpp(&self) -> u32

get the total amount of bits per pixel, based on colortype and bitdepth in the struct

source

pub fn bpp_(&self) -> NonZeroU8

source

pub fn set_key(&mut self, r: u16, g: u16, b: u16)

tRNS chunk

source

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.

source

pub fn is_greyscale_type(&self) -> bool

is it a greyscale type? (only colortype 0 or 4)

source

pub fn is_alpha_type(&self) -> bool

has it got an alpha channel? (only colortype 2 or 6)

source

pub fn is_palette_type(&self) -> bool

has it got a palette? (only colortype 3)

source

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.

source

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.

source

pub fn raw_size(&self, w: u32, h: u32) -> usize

Returns the byte size of a raw image buffer with given width, height and color mode

Trait Implementations§

source§

impl Clone for ColorMode

source§

fn clone(&self) -> ColorMode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ColorMode

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ColorMode

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.