Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Oct 12, 2023
1 parent e509cf6 commit 5a2ef3e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/capi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! These are internal unstable private helper methods for imagequant-sys.
//! For public stable a C FFI interface, see imagequant-sys crate instead.
#![allow(missing_docs)]
#![allow(clippy::missing_safety_doc)]

use crate::rows::RowCallback;
use crate::seacow::Pointer;
Expand Down
2 changes: 1 addition & 1 deletion src/hist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Histogram {
let estimated_colors = (surface_area / (posterize_bits as usize + if surface_area > 512 * 512 { 7 } else { 5 })).min(250_000);
self.reserve(estimated_colors);

self.add_pixel_rows(&mut image.px, image.importance_map.as_deref(), posterize_bits)?;
self.add_pixel_rows(&image.px, image.importance_map.as_deref(), posterize_bits)?;
image.free_histogram_inputs();

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/nearest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn vp_create_node(indexes: &mut [MapIndex], items: &PalF) -> Node {
let num_indexes = indexes.len();

let inner = if num_indexes <= LEAF_MAX_SIZE {
let mut colors = [Default::default(); LEAF_MAX_SIZE];
let mut colors = [f_pixel::default(); LEAF_MAX_SIZE];
let mut idxs = [Default::default(); LEAF_MAX_SIZE];

indexes.iter().zip(colors.iter_mut().zip(idxs.iter_mut())).for_each(|(i, (color, idx))| {
Expand Down
2 changes: 1 addition & 1 deletion src/pal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ fn pal_test() {

let mut int_pal = Palette {
count: 0,
entries: [Default::default(); MAX_COLORS],
entries: [RGBA::default(); MAX_COLORS],
};
p.init_int_palette(&mut int_pal, 0.45455, 0);

Expand Down
19 changes: 8 additions & 11 deletions src/quant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl QuantizationResult {

let mut palette = self.palette.clone();
let mut remapped = Box::new(Remapped {
int_palette: Palette { count: 0, entries: [Default::default(); MAX_COLORS] },
int_palette: Palette { count: 0, entries: [RGBA::default(); MAX_COLORS] },
palette_error: None,
});
if self.dither_level == 0. {
Expand Down Expand Up @@ -201,17 +201,14 @@ impl QuantizationResult {
}

pub(crate) fn int_palette(&mut self) -> &Palette {
match self.remapped.as_ref() {
Some(remap) => {
debug_assert!(remap.int_palette.count > 0);
&remap.int_palette
if let Some(remap) = self.remapped.as_ref() {
debug_assert!(remap.int_palette.count > 0);
&remap.int_palette
} else {
if self.int_palette.count == 0 {
self.palette.init_int_palette(&mut self.int_palette, self.gamma, self.min_posterization_output);
}
None => {
if self.int_palette.count == 0 {
self.palette.init_int_palette(&mut self.int_palette, self.gamma, self.min_posterization_output);
}
&self.int_palette
},
&self.int_palette
}
}

Expand Down
38 changes: 17 additions & 21 deletions src/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,29 @@ impl<'a, 'pixels, 'rows> DynamicRowsIter<'a, 'pixels, 'rows> {
#[must_use]
pub fn row_f<'px>(&'px mut self, temp_row: &mut [MaybeUninit<RGBA>], row: usize) -> &'px [f_pixel] {
debug_assert_eq!(temp_row.len(), self.px.width as usize);
match self.px.f_pixels.as_ref() {
Some(pixels) => {
let start = self.px.width as usize * row;
&pixels[start..start + self.px.width as usize]
},
None => {
let lut = gamma_lut(self.px.gamma);
let row_pixels = self.px.row_rgba(temp_row, row);

match self.temp_f_row.as_mut() {
Some(t) => DynamicRows::convert_row_to_f(t, row_pixels, &lut),
None => &mut [], // this can't happen
}
},
if let Some(pixels) = self.px.f_pixels.as_ref() {
let start = self.px.width as usize * row;
&pixels[start..start + self.px.width as usize]
} else {
let lut = gamma_lut(self.px.gamma);
let row_pixels = self.px.row_rgba(temp_row, row);

match self.temp_f_row.as_mut() {
Some(t) => DynamicRows::convert_row_to_f(t, row_pixels, &lut),
None => &mut [], // this can't happen
}
}
}

#[must_use]
pub fn row_f_shared<'px>(&'px self, temp_row: &mut [MaybeUninit<RGBA>], temp_row_f: &'px mut [MaybeUninit<f_pixel>], row: usize) -> &'px [f_pixel] {
match self.px.f_pixels.as_ref() {
Some(pixels) => &pixels[self.px.width as usize * row..],
None => {
let lut = gamma_lut(self.px.gamma);
let row_pixels = self.px.row_rgba(temp_row, row);
if let Some(pixels) = self.px.f_pixels.as_ref() {
&pixels[self.px.width as usize * row..]
} else {
let lut = gamma_lut(self.px.gamma);
let row_pixels = self.px.row_rgba(temp_row, row);

DynamicRows::convert_row_to_f(temp_row_f, row_pixels, &lut)
},
DynamicRows::convert_row_to_f(temp_row_f, row_pixels, &lut)
}
}

Expand Down

0 comments on commit 5a2ef3e

Please sign in to comment.