fn new(src: &[u8]) -> Self {
Self { r: src[0], g: src[1], b: src[2] }
}
- fn to_rgb(&self) -> [u8; 3] {
+ fn to_rgb(self) -> [u8; 3] {
[self.r, self.g, self.b]
}
fn dist(&self, pix: Pixel) -> u32 {
//use mediancut::quantise_median_cut;
//use neuquant::NeuQuantQuantiser;
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
/// Palette quantisation algorithms.
pub enum QuantisationMode {
/// Median cut approach proposed by Paul Heckbert.
///
/// This is moderately fast and moderately good.
+ #[default]
MedianCut,
/// Enhanced LBG algorithm proposed by Giuseppe Patane and Marco Russo.
///
NeuQuant(u8),
}
-impl Default for QuantisationMode {
- fn default() -> Self { QuantisationMode::MedianCut }
-}
-
-#[derive(Clone,Copy,Debug,PartialEq)]
+#[derive(Clone,Copy,Debug,PartialEq,Default)]
/// Algorithms for seaching an appropriate palette entry for a given pixel.
pub enum PaletteSearchMode {
/// Full search (slowest).
Full,
/// Local search (faster but may be not so good).
+ #[default]
Local,
/// k-d tree based one (the fastest but not so accurate).
KDTree,
}
-impl Default for PaletteSearchMode {
- fn default() -> Self { PaletteSearchMode::Local }
-}
-
use crate::scale::palette::elbg::ELBG;
use crate::scale::palette::mediancut::quantise_median_cut;
use crate::scale::palette::neuquant::NeuQuantQuantiser;
let ofmt = dbuf.get_info().get_format();
let dst = dbuf.get_data_mut().unwrap();
- pixels.truncate(0);
+ pixels.clear();
if !ifmt.is_unpacked() {
let esize = ifmt.elem_size as usize;
let coffs = [ifmt.comp_info[0].unwrap().comp_offs as usize, ifmt.comp_info[1].unwrap().comp_offs as usize, ifmt.comp_info[2].unwrap().comp_offs as usize];
};
let esize = ofmt.elem_size as usize;
let coffs = [ofmt.comp_info[0].unwrap().comp_offs as usize, ofmt.comp_info[1].unwrap().comp_offs as usize, ofmt.comp_info[2].unwrap().comp_offs as usize];
- for (dpal, spal) in (&mut dst[paloff..]).chunks_mut(esize).zip(pal.iter()) {
+ for (dpal, spal) in dst[paloff..].chunks_mut(esize).zip(pal.iter()) {
dpal[coffs[0]] = spal[0];
dpal[coffs[1]] = spal[1];
dpal[coffs[2]] = spal[2];
}
impl Kernel for PalettiseKernel {
- fn init(&mut self, in_fmt: &ScaleInfo, _dest_fmt: &ScaleInfo) -> ScaleResult<NABufferType> {
+ fn init(&mut self, in_fmt: &ScaleInfo, _dest_fmt: &ScaleInfo, options: &[(String, String)]) -> ScaleResult<NABufferType> {
+ for (name, value) in options.iter() {
+ match name.as_str() {
+ "pal.quant" => {
+ self.qmode = match value.as_str() {
+ "mediancut" => QuantisationMode::MedianCut,
+ "elbg" => QuantisationMode::ELBG,
+ "neuquant" => QuantisationMode::NeuQuant(3),
+ _ => QuantisationMode::default(),
+ };
+ },
+ "pal.search" => {
+ self.palmode = match value.as_str() {
+ "full" => PaletteSearchMode::Full,
+ "local" => PaletteSearchMode::Local,
+ "kdtree" => PaletteSearchMode::KDTree,
+ _ => PaletteSearchMode::default(),
+ };
+ },
+ _ => {},
+ };
+ }
+
self.pixels = Vec::with_capacity(in_fmt.width * in_fmt.height);
let res = alloc_video_buffer(NAVideoInfo::new(in_fmt.width, in_fmt.height, false, PAL8_FORMAT), 0);
if res.is_err() { return Err(ScaleError::AllocError); }