use crate::{c_api, error, Nc, NcPalette, NcPaletteIndex, NcResult, NcRgb};
impl NcPalette {
pub fn new<'a>(nc: &mut Nc) -> &'a mut Self {
unsafe { &mut *c_api::ncpalette_new(nc) }
}
pub fn free(&mut self) {
unsafe {
c_api::ncpalette_free(self);
}
}
pub fn r#use(&self, nc: &mut Nc) -> NcResult<()> {
error![unsafe { c_api::ncpalette_use(nc, self) }]
}
pub fn get(&self, index: impl Into<NcPaletteIndex>) -> NcRgb {
c_api::ncpalette_get(self, index.into()).into()
}
pub fn get_rgb(&self, index: impl Into<NcPaletteIndex>) -> NcRgb {
let (mut r, mut g, mut b) = (0, 0, 0);
c_api::ncpalette_get_rgb8(self, index.into(), &mut r, &mut g, &mut b);
(r, g, b).into()
}
pub fn set(&mut self, index: impl Into<NcPaletteIndex>, rgb: impl Into<NcRgb>) {
c_api::ncpalette_set(self, index.into(), rgb.into().into())
}
#[inline]
pub fn set_rgb(
palette: &mut NcPalette,
index: impl Into<NcPaletteIndex>,
rgb: impl Into<NcRgb>,
) {
let (r, g, b) = rgb.into().into();
c_api::ncpalette_set_rgb8(palette, index.into(), r, g, b)
}
}