1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
//! `ncpalette_*` reimplemented functions.
use crate::{
c_api::{self, NcChannel_u32, NcRgb_u32},
NcPalette, NcPaletteIndex,
};
/// Returns the [`NcRgb_u32`] value from an [`NcChannel_u32`] entry inside
/// an [`NcPalette`].
///
/// *Method: NcPalette.[get()][NcPalette#method.get].*
#[inline]
pub fn ncpalette_get(palette: &NcPalette, index: impl Into<NcPaletteIndex>) -> NcRgb_u32 {
c_api::ncchannel_rgb(palette.chans[index.into() as usize])
}
/// Extracts the RGB components from an [`NcChannel_u32`] entry inside
/// an [`NcPalette`], and returns the `NcChannel_u32`.
///
/// *Method: NcPalette.[get_rgb8()][NcPalette#method.get_rgb8].*
#[inline]
pub fn ncpalette_get_rgb8(
palette: &NcPalette,
index: impl Into<NcPaletteIndex>,
red: &mut u8,
green: &mut u8,
blue: &mut u8,
) -> NcChannel_u32 {
c_api::ncchannel_rgb8(palette.chans[index.into() as usize], red, green, blue)
}
/// Sets the [`NcRgb_u32`] value of an [`NcChannel_u32`] entry inside an
/// [`NcPalette`].
///
/// *Method: NcPalette.[set()][NcPalette#method.set].*
#[inline]
pub fn ncpalette_set(palette: &mut NcPalette, index: impl Into<NcPaletteIndex>, rgb: NcRgb_u32) {
c_api::ncchannel_set(&mut palette.chans[index.into() as usize], rgb);
}
/// Sets the RGB components of an [`NcChannel_u32`] entry inside an
/// [`NcPalette`].
///
/// *Method: NcPalette.[set_rgb8()][NcPalette#method.set_rgb8].*
#[inline]
pub fn ncpalette_set_rgb8(
palette: &mut NcPalette,
index: impl Into<NcPaletteIndex>,
red: u8,
green: u8,
blue: u8,
) {
c_api::ncchannel_set_rgb8(&mut palette.chans[index.into() as usize], red, green, blue)
}