Skip to content

Commit d6514e8

Browse files
committed
Clippy
1 parent 0a808e0 commit d6514e8

File tree

10 files changed

+17
-24
lines changed

10 files changed

+17
-24
lines changed

imagequant-sys/c_test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ release = false
1414
imagequant-sys = { version = "4.0.3", path = ".." }
1515

1616
[build-dependencies]
17-
cc = "1.0.95"
17+
cc = "1.1.7"

imagequant-sys/src/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ pub extern "C" fn liq_image_quantize(img: &mut liq_image, attr: &mut liq_attr, w
526526

527527
#[no_mangle]
528528
#[inline(never)]
529-
pub fn liq_histogram_quantize(hist: &mut liq_histogram, attr: &liq_attr, write_only_output: &mut MaybeUninit<Option<Box<liq_result>>>) -> liq_error {
529+
pub extern "C" fn liq_histogram_quantize(hist: &mut liq_histogram, attr: &liq_attr, write_only_output: &mut MaybeUninit<Option<Box<liq_result>>>) -> liq_error {
530530
if bad_object!(attr, LIQ_ATTR_MAGIC) ||
531531
bad_object!(hist, LIQ_HISTOGRAM_MAGIC) { return Error::InvalidPointer; }
532532
let attr = &attr.inner;

src/image.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ impl<'pixels> Image<'pixels> {
128128
if self.edges.is_none() {
129129
self.contrast_maps()?;
130130
}
131-
let mut edges = match self.edges.take() {
132-
Some(e) => e,
133-
None => return Ok(()),
134-
};
131+
let Some(mut edges) = self.edges.take() else { return Ok(()) };
135132
let colors = palette.as_slice();
136133

137134
let width = self.width();

src/kmeans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn replace_unused_colors(palette: &mut PalF, hist: &HistogramInternal) -> Result
133133
let colors = palette.as_slice();
134134
// the search is just for diff, ignoring adjusted_weight,
135135
// because the palette already optimizes for the max weight, so it'd likely find another redundant entry.
136-
for item in hist.items.iter() {
136+
for item in &hist.items {
137137
// the early reject avoids running full palette search for every entry
138138
let may_be_worst = colors.get(item.likely_palette_index() as usize)
139139
.map_or(true, |pal| pal.diff(&item.color) > worst_diff);

src/mediancut.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ impl<'hist> MBox<'hist> {
4040
let mut avg_color = weighed_average_color(hist);
4141
// It's possible that an average color will end up being bad for every entry,
4242
// so prefer picking actual colors so that at least one histogram entry will be satisfied.
43-
if (hist.len() < 500 && hist.len() > 2) || Self::is_useless_color(&avg_color, hist, other_boxes) {
43+
if (hist.len() < 500 && hist.len() > 2) || Self::is_useless_color(avg_color, hist, other_boxes) {
4444
avg_color = hist.iter().min_by_key(|a| OrdFloat::new(avg_color.diff(&a.color))).map(|a| a.color).unwrap_or_default();
4545
}
4646
Self::new_c(hist, adjusted_weight_sum, avg_color)
4747
}
4848

4949
fn new_c(hist: &'hist mut [HistItem], adjusted_weight_sum: f64, avg_color: f_pixel) -> Self {
50-
let (variance, max_error) = Self::box_stats(hist, &avg_color);
50+
let (variance, max_error) = Self::box_stats(hist, avg_color);
5151
Self {
5252
variance,
5353
max_error,
@@ -59,7 +59,7 @@ impl<'hist> MBox<'hist> {
5959
}
6060

6161
/// It's possible that the average color is useless
62-
fn is_useless_color(new_avg_color: &f_pixel, colors: &[HistItem], other_boxes: &[MBox<'_>]) -> bool {
62+
fn is_useless_color(new_avg_color: f_pixel, colors: &[HistItem], other_boxes: &[MBox<'_>]) -> bool {
6363
colors.iter().all(move |c| {
6464
let own_box_diff = new_avg_color.diff(&c.color);
6565
let other_box_is_better = other_boxes.iter()
@@ -69,7 +69,7 @@ impl<'hist> MBox<'hist> {
6969
})
7070
}
7171

72-
fn box_stats(hist: &[HistItem], avg_color: &f_pixel) -> (ARGBF, f32) {
72+
fn box_stats(hist: &[HistItem], avg_color: f_pixel) -> (ARGBF, f32) {
7373
let mut variance = ARGBF::default();
7474
let mut max_error = 0.;
7575
for a in hist {
@@ -278,9 +278,8 @@ impl<'hist> MedianCutter<'hist> {
278278
// later raises the limit to allow large smooth areas/gradients get colors.
279279
let fraction_done = self.boxes.len() as f64 / f64::from(self.target_colors);
280280
let current_max_mse = (fraction_done * 16.).mul_add(max_mse, max_mse);
281-
let bi = match self.take_best_splittable_box(current_max_mse) {
282-
Some(bi) => bi,
283-
None => break,
281+
let Some(bi) = self.take_best_splittable_box(current_max_mse) else {
282+
break
284283
};
285284

286285
self.boxes.extend(bi.split(&self.boxes));

src/pal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ impl PalF {
228228
debug_assert!(PalIndex::MAX as usize + 1 >= MAX_COLORS);
229229
debug_assert!(PalLen::MAX as usize >= MAX_COLORS);
230230
Self {
231-
colors: Default::default(),
232-
pops: Default::default(),
231+
colors: ArrayVec::default(),
232+
pops: ArrayVec::default(),
233233
}
234234
}
235235

src/quant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl QuantizationResult {
6464
progress_callback: None,
6565
int_palette: Palette {
6666
count: 0,
67-
entries: [Default::default(); MAX_COLORS],
67+
entries: [RGBA::default(); MAX_COLORS],
6868
},
6969
dither_level: 1.,
7070
single_threaded_dithering: attr.single_threaded_dithering,
@@ -441,7 +441,7 @@ fn refine_palette(palette: &mut PalF, attr: &Attributes, hist: &mut HistogramInt
441441
#[cold]
442442
fn palette_from_histogram(hist: &HistogramInternal, max_colors: PalLen) -> (PalF, Option<f64>) {
443443
let mut hist_pal = PalF::new();
444-
for item in hist.items.iter() {
444+
for item in &hist.items {
445445
hist_pal.push(item.color, PalPop::new(item.perceptual_weight));
446446
}
447447

src/remap.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ pub(crate) fn remap_to_palette<'x, 'b: 'x>(px: &mut DynamicRows, background: Opt
5757

5858
let remapping_error = output_pixels.rows_mut().enumerate().par_bridge().map(|(row, output_pixels_row)| {
5959
let mut remapping_error = 0.;
60-
let tls_res = match tls.get_or_try(per_thread_buffers) {
61-
Ok(res) => res,
62-
Err(_) => return f64::NAN,
63-
};
60+
let Ok(tls_res) = tls.get_or_try(per_thread_buffers) else { return f64::NAN };
6461
let (kmeans, temp_row, temp_row_f, temp_row_f_bg) = &mut *tls_res.0.borrow_mut();
6562

6663
let output_pixels_row = &mut output_pixels_row[..width];

src/rows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'pixels, 'rows> DynamicRows<'pixels, 'rows> {
231231
PixelsSource::Pixels { pixels, rows } => {
232232
// the row with the lowest address is assumed to be at the start of the bitmap
233233
let ptr = rows.as_slice().iter().map(|p| p.0).min().ok_or(Error::Unsupported)?;
234-
*pixels = Some(SeaCow::c_owned(ptr as *mut _, len, free_fn));
234+
*pixels = Some(SeaCow::c_owned(ptr.cast_mut(), len, free_fn));
235235
},
236236
PixelsSource::Callback(_) => return Err(Error::ValueOutOfRange),
237237
}

src/seacow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a, T> SeaCow<'a, T> {
5757
#[cfg(feature = "_internal_c_ffi")]
5858
pub(crate) fn make_owned(&mut self, free_fn: unsafe extern fn(*mut c_void)) {
5959
if let SeaCowInner::Borrowed(slice) = self.inner {
60-
self.inner = SeaCowInner::Owned { ptr: slice.as_ptr() as *mut _, len: slice.len(), free_fn };
60+
self.inner = SeaCowInner::Owned { ptr: slice.as_ptr().cast_mut(), len: slice.len(), free_fn };
6161
}
6262
}
6363
}

0 commit comments

Comments
 (0)