X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fscale%2Fpalette%2Fmod.rs;h=f70300fb8666f810ff68e23a911d51cc15345270;hb=6f2630992fe340ad1a122ec10c649f756e478185;hp=2005cd8c0fc12c6158511fc937ee5a55b69b496c;hpb=4b459d0b9b76cb51c1029e6d1ffb17cf5f2d44d9;p=nihav.git diff --git a/nihav-core/src/scale/palette/mod.rs b/nihav-core/src/scale/palette/mod.rs index 2005cd8..f70300f 100644 --- a/nihav-core/src/scale/palette/mod.rs +++ b/nihav-core/src/scale/palette/mod.rs @@ -14,7 +14,7 @@ impl Pixel { 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 { @@ -102,7 +102,7 @@ fn palettise_frame_internal(pic_in: &NABufferType, pic_out: &mut NABufferType, q 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]; @@ -220,7 +220,29 @@ impl PalettiseKernel { } impl Kernel for PalettiseKernel { - fn init(&mut self, in_fmt: &ScaleInfo, _dest_fmt: &ScaleInfo) -> ScaleResult { + fn init(&mut self, in_fmt: &ScaleInfo, _dest_fmt: &ScaleInfo, options: &[(String, String)]) -> ScaleResult { + 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); }