Skip to content

Commit 1f73ba3

Browse files
committed
fmt/clippy
1 parent 16b6cb7 commit 1f73ba3

File tree

10 files changed

+39
-31
lines changed

10 files changed

+39
-31
lines changed

examples/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ fn main() {
2626
// You can reuse the result to generate several images with the same palette
2727
let (palette, pixels) = res.remapped(&mut img).unwrap();
2828

29-
println!("Done! Got palette {palette:?} and {} pixels with {}% quality", pixels.len(), res.quantization_quality().unwrap());
29+
println!(
30+
"Done! Got palette {palette:?} and {} pixels with {}% quality",
31+
pixels.len(),
32+
res.quantization_quality().unwrap()
33+
);
3034
}

imagequant-sys/src/ffi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,17 +612,17 @@ pub unsafe extern "C" fn liq_histogram_add_colors(input_hist: &mut liq_histogram
612612
if bad_object!(attr, LIQ_ATTR_MAGIC) ||
613613
bad_object!(input_hist, LIQ_HISTOGRAM_MAGIC) { return Error::InvalidPointer; }
614614
let input_hist = &mut input_hist.inner;
615-
616-
if num_entries < 0 {
617-
return Error::ValueOutOfRange;
618-
}
619615
if num_entries == 0 {
620616
return LIQ_OK;
621617
}
622618

619+
let Ok(num_entries) = num_entries.try_into() else {
620+
return Error::ValueOutOfRange;
621+
};
622+
623623
if liq_received_invalid_pointer(entries.cast()) { return Error::InvalidPointer; }
624624

625-
let entries = std::slice::from_raw_parts(entries, num_entries as usize);
625+
let entries = std::slice::from_raw_parts(entries, num_entries);
626626

627627
input_hist.add_colors(entries, gamma).err().unwrap_or(LIQ_OK)
628628
}

src/capi.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
#![allow(missing_docs)]
44
#![allow(clippy::missing_safety_doc)]
55

6-
use crate::rows::RowCallback;
7-
use crate::Attributes;
8-
use crate::Error;
9-
use crate::Image;
106
use crate::pal::Palette;
11-
use crate::QuantizationResult;
12-
use crate::RGBA;
7+
use crate::rows::RowCallback;
138
use crate::seacow::{Pointer, RowBitmapMut, SeaCow};
9+
use crate::{Attributes, Error, Image, QuantizationResult, RGBA};
1410
use std::mem::MaybeUninit;
1511

1612
pub const LIQ_VERSION: u32 = 40202;

src/hist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Histogram {
240240
self.posterize_bits = posterize_bits;
241241
let new_posterize_mask = self.posterize_mask();
242242

243-
let new_size = (self.hashmap.len()/3).max(self.hashmap.capacity()/5);
243+
let new_size = (self.hashmap.len() / 3).max(self.hashmap.capacity() / 5);
244244
let old_hashmap = std::mem::replace(&mut self.hashmap, HashMap::with_capacity_and_hasher(new_size, U32Hasher(0)));
245245
self.hashmap.extend(old_hashmap.into_iter().map(move |(k, v)| {
246246
(k & new_posterize_mask, v)

src/image.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use crate::error::*;
44
use crate::pal::{f_pixel, PalF, PalIndexRemap, MAX_COLORS, MIN_OPAQUE_A, RGBA};
55
use crate::remap::DitherMapMode;
66
use crate::rows::{DynamicRows, PixelsSource};
7-
use crate::PushInCapacity;
8-
use crate::LIQ_HIGH_MEMORY_LIMIT;
97
use crate::seacow::{RowBitmap, SeaCow};
8+
use crate::{PushInCapacity, LIQ_HIGH_MEMORY_LIMIT};
109
use rgb::prelude::*;
1110
use std::mem::MaybeUninit;
1211

@@ -148,11 +147,11 @@ impl<'pixels> Image<'pixels> {
148147
while i < col {
149148
if let Some(prev_row) = prev_row {
150149
let pixelabove = prev_row[i];
151-
if pixelabove == lastpixel { neighbor_count += 15; };
150+
if pixelabove == lastpixel { neighbor_count += 15; }
152151
}
153152
if let Some((next_row, _)) = rows.peek() {
154153
let pixelbelow = next_row[i];
155-
if pixelbelow == lastpixel { neighbor_count += 15; };
154+
if pixelbelow == lastpixel { neighbor_count += 15; }
156155
}
157156
i += 1;
158157
}

src/kmeans.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::CacheLineAlign;
21
use crate::hist::{HistItem, HistogramInternal};
32
use crate::nearest::Nearest;
43
use crate::pal::{f_pixel, PalF, PalIndex, PalPop};
54
use crate::rayoff::*;
6-
use crate::Error;
7-
use rgb::Argb;
5+
use crate::{CacheLineAlign, Error};
86
use rgb::prelude::*;
7+
use rgb::Argb;
98
use std::cell::RefCell;
109

1110
/// K-Means iteration: new palette color is computed from weighted average of colors that map best to that palette entry.

src/mediancut.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'hist> MBox<'hist> {
116116

117117
fn median_color(&mut self) -> f_pixel {
118118
let len = self.colors.len();
119-
let (_, mid_item, _) = self.colors.select_nth_unstable_by_key(len/2, |a| a.mc_sort_value());
119+
let (_, mid_item, _) = self.colors.select_nth_unstable_by_key(len / 2, |a| a.mc_sort_value());
120120
mid_item.color
121121
}
122122

@@ -172,7 +172,9 @@ fn qsort_partition(base: &mut [HistItem]) -> usize {
172172
l += 1;
173173
} else {
174174
r -= 1;
175-
while l < r && base[r].mc_sort_value() <= pivot_value { r -= 1; }
175+
while l < r && base[r].mc_sort_value() <= pivot_value {
176+
r -= 1;
177+
}
176178
base.swap(l, r);
177179
}
178180
}
@@ -186,7 +188,9 @@ fn qsort_partition(base: &mut [HistItem]) -> usize {
186188
#[inline(never)]
187189
fn hist_item_sort_half(mut base: &mut [HistItem], mut weight_half_sum: f64) -> usize {
188190
let mut base_index = 0;
189-
if base.is_empty() { return 0; }
191+
if base.is_empty() {
192+
return 0;
193+
}
190194
loop {
191195
let partition = qsort_partition(base);
192196
let (left, right) = base.split_at_mut(partition + 1); // +1, because pivot stays on the left side
@@ -248,7 +252,7 @@ impl<'hist> MedianCutter<'hist> {
248252
}
249253
} else {
250254
boxes.push_in_cap(MBox::new(hist_items));
251-
};
255+
}
252256

253257
Ok(Self {
254258
boxes,

src/nearest.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ impl<'pal> Nearest<'pal> {
2020
};
2121
for (i, color) in palette.as_slice().iter().enumerate() {
2222
let mut best = Visitor {
23-
idx: 0, distance: f32::MAX, distance_squared: f32::MAX,
23+
idx: 0,
24+
distance: f32::MAX,
25+
distance_squared: f32::MAX,
2426
exclude: Some(i as PalIndex),
2527
};
2628
vp_search_node(&handle.root, color, &mut best);
@@ -46,7 +48,12 @@ impl Nearest<'_> {
4648
exclude: None,
4749
}
4850
} else {
49-
Visitor { distance: f32::INFINITY, distance_squared: f32::INFINITY, idx: 0, exclude: None, }
51+
Visitor {
52+
distance: f32::INFINITY,
53+
distance_squared: f32::INFINITY,
54+
idx: 0,
55+
exclude: None,
56+
}
5057
};
5158

5259
vp_search_node(&self.root, px, &mut best_candidate);

src/quant.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use crate::hist::HistogramInternal;
44
use crate::image::Image;
55
use crate::kmeans::Kmeans;
66
use crate::mediancut::mediancut;
7-
use crate::pal::{PalIndexRemap, PalF, PalLen, PalPop, Palette, LIQ_WEIGHT_MSE, MAX_COLORS, MAX_TRANSP_A, RGBA};
8-
use crate::remap::{mse_to_standard_mse, DitherMapMode, Remapped};
9-
use crate::remap::{remap_to_palette, remap_to_palette_floyd};
7+
use crate::pal::{PalF, PalIndexRemap, PalLen, PalPop, Palette, LIQ_WEIGHT_MSE, MAX_COLORS, MAX_TRANSP_A, RGBA};
8+
use crate::remap::{mse_to_standard_mse, remap_to_palette, remap_to_palette_floyd, DitherMapMode, Remapped};
109
use crate::seacow::RowBitmapMut;
1110
use crate::OrdFloat;
1211
use arrayvec::ArrayVec;
@@ -455,7 +454,7 @@ pub(crate) fn quality_to_mse(quality: u8) -> f64 {
455454

456455
pub(crate) fn mse_to_quality(mse: f64) -> u8 {
457456
for i in (1..101).rev() {
458-
if mse <= quality_to_mse(i) + 0.000001 { return i; };
457+
if mse <= quality_to_mse(i) + 0.000001 { return i; }
459458
}
460459
0
461460
}

src/seacow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use std::mem::MaybeUninit;
12
#[cfg(feature = "_internal_c_ffi")]
23
use std::os::raw::c_void;
3-
use std::mem::MaybeUninit;
44

55
#[derive(Clone)]
66
pub struct SeaCow<'a, T> {

0 commit comments

Comments
 (0)