Skip to content

Commit 0a808e0

Browse files
committed
fmt
1 parent 3b58449 commit 0a808e0

15 files changed

+30
-55
lines changed

imagequant-sys/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
fn main() {
32
println!("cargo:include={}", std::env::var("CARGO_MANIFEST_DIR").unwrap());
43
}

imagequant-sys/src/ffi.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use imagequant::capi::*;
1212
use imagequant::Error::LIQ_OK;
1313
use imagequant::*;
1414
use std::ffi::CString;
15-
use std::mem::ManuallyDrop;
16-
use std::mem::MaybeUninit;
17-
use std::os::raw::c_char;
18-
use std::os::raw::{c_int, c_uint, c_void};
15+
use std::mem::{ManuallyDrop, MaybeUninit};
16+
use std::os::raw::{c_char, c_int, c_uint, c_void};
1917
use std::ptr;
2018

2119
pub use imagequant::Error as liq_error;

src/attr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::error::Error;
22
use crate::hist::Histogram;
33
use crate::image::Image;
4-
use crate::pal::PalLen;
5-
use crate::pal::MAX_COLORS;
6-
use crate::pal::RGBA;
4+
use crate::pal::{PalLen, MAX_COLORS, RGBA};
75
use crate::quant::{mse_to_quality, quality_to_mse, QuantizationResult};
86
use crate::remap::DitherMapMode;
97
use std::sync::Arc;

src/capi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
#![allow(clippy::missing_safety_doc)]
55

66
use crate::rows::RowCallback;
7-
use crate::seacow::Pointer;
8-
use crate::seacow::RowBitmapMut;
9-
use crate::seacow::SeaCow;
107
use crate::Attributes;
118
use crate::Error;
129
use crate::Image;
1310
use crate::pal::Palette;
1411
use crate::QuantizationResult;
1512
use crate::RGBA;
13+
use crate::seacow::{Pointer, RowBitmapMut, SeaCow};
1614
use std::mem::MaybeUninit;
1715

1816
pub const LIQ_VERSION: u32 = 40202;

src/hist.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use crate::error::*;
22
use crate::image::Image;
3-
use crate::pal::PalIndex;
4-
use crate::pal::ARGBF;
5-
use crate::pal::MAX_COLORS;
6-
use crate::pal::{f_pixel, gamma_lut, RGBA};
3+
use crate::pal::{f_pixel, gamma_lut, PalIndex, ARGBF, MAX_COLORS, RGBA};
74
use crate::quant::QuantizationResult;
8-
use crate::rows::temp_buf;
9-
use crate::rows::DynamicRows;
5+
use crate::rows::{temp_buf, DynamicRows};
106
use crate::Attributes;
117
use std::collections::{HashMap, HashSet};
128
use std::fmt;
@@ -387,6 +383,7 @@ pub(crate) struct Cluster {
387383
// Simple deterministic hasher for the color hashmap
388384
impl std::hash::BuildHasher for U32Hasher {
389385
type Hasher = Self;
386+
390387
#[inline(always)]
391388
fn build_hasher(&self) -> Self {
392389
Self(0)

src/image.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ 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::seacow::RowBitmap;
8-
use crate::seacow::SeaCow;
97
use crate::PushInCapacity;
108
use crate::LIQ_HIGH_MEMORY_LIMIT;
9+
use crate::seacow::{RowBitmap, SeaCow};
1110
use rgb::prelude::*;
1211
use std::mem::MaybeUninit;
1312

@@ -336,7 +335,7 @@ impl<'pixels> Image<'pixels> {
336335
Ok(p) => p,
337336
Err(e) => {
338337
attr.verbose_print(format!("Buffer length is {} bytes, which is not enough for {}×{}×4 RGBA bytes", pixels_len*4, stride, height));
339-
return Err(e)
338+
return Err(e);
340339
},
341340
};
342341
Image::new_internal(attr, pixels_rows, width, height, gamma)

src/lib.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ pub(crate) struct CacheLineAlign<T>(pub T);
5151
#[cfg(feature = "_internal_c_ffi")]
5252
pub mod capi;
5353

54-
pub use attr::Attributes;
55-
pub use attr::ControlFlow;
54+
pub use attr::{Attributes, ControlFlow};
5655
pub use error::Error;
57-
pub use hist::Histogram;
58-
pub use hist::HistogramEntry;
56+
pub use hist::{Histogram, HistogramEntry};
5957
pub use image::Image;
6058
#[doc(hidden)]
6159
pub use pal::Palette;
@@ -88,8 +86,7 @@ fn copy_img() {
8886
fn takes_rgba() {
8987
let liq = Attributes::new();
9088

91-
let img = vec![RGBA {r:0, g:0, b:0, a:0}; 8];
92-
89+
let img = vec![RGBA { r: 0, g: 0, b: 0, a: 0 }; 8];
9390

9491
liq.new_image_borrowed(&img, 1, 1, 0.0).unwrap();
9592
liq.new_image_borrowed(&img, 4, 2, 0.0).unwrap();
@@ -103,11 +100,11 @@ fn histogram() {
103100
let attr = Attributes::new();
104101
let mut hist = Histogram::new(&attr);
105102

106-
let bitmap1 = [RGBA {r:0, g:0, b:0, a:0}; 1];
103+
let bitmap1 = [RGBA { r: 0, g: 0, b: 0, a: 0 }; 1];
107104
let mut image1 = attr.new_image(&bitmap1[..], 1, 1, 0.0).unwrap();
108105
hist.add_image(&attr, &mut image1).unwrap();
109106

110-
let bitmap2 = [RGBA {r:255, g:255, b:255, a:255}; 1];
107+
let bitmap2 = [RGBA { r: 255, g: 255, b: 255, a: 255 }; 1];
111108
let mut image2 = attr.new_image(&bitmap2[..], 1, 1, 0.0).unwrap();
112109
hist.add_image(&attr, &mut image2).unwrap();
113110

src/mediancut.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::hist::{HistItem, HistogramInternal};
2-
use crate::pal::{f_pixel, PalF, PalPop};
3-
use crate::pal::{PalLen, ARGBF};
2+
use crate::pal::{f_pixel, PalF, PalLen, PalPop, ARGBF};
43
use crate::quant::quality_to_mse;
54
use crate::PushInCapacity;
65
use crate::{Error, OrdFloat};

src/nearest.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use crate::pal::PalIndex;
2-
use crate::pal::MAX_COLORS;
3-
use crate::pal::{f_pixel, PalF};
1+
use crate::pal::{f_pixel, PalF, PalIndex, MAX_COLORS};
42
use crate::{Error, OrdFloat};
53

64
impl<'pal> Nearest<'pal> {

src/pal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl f_pixel {
7878
vst1q_f32(max_gb.as_mut_ptr(), vpaddq_f32(max, max));
7979

8080
// add rgb, not a
81-
81+
8282
max_r[1] + max_gb[1]
8383
}
8484
}

src/quant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl Clone for QuantizationResult {
316316
fn sort_palette(attr: &Attributes, palette: &mut PalF) {
317317
let last_index_transparent = attr.last_index_transparent;
318318

319-
let mut tmp: ArrayVec<_, {MAX_COLORS}> = palette.iter_mut().map(|(c,p)| (*c, *p)).collect();
319+
let mut tmp: ArrayVec<_, { MAX_COLORS }> = palette.iter_mut().map(|(c, p)| (*c, *p)).collect();
320320
tmp.sort_by_key(|(color, pop)| {
321321
let is_transparent = color.a <= MAX_TRANSP_A;
322322
(is_transparent == last_index_transparent, Reverse(OrdFloat::new(pop.popularity())))

src/rayoff.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ impl<T> ThreadLocal<T> {
2121
}
2222

2323
impl<T> IntoIterator for ThreadLocal<T> {
24-
type Item = T;
25-
2624
type IntoIter = std::option::IntoIter<T>;
25+
type Item = T;
2726

2827
#[inline(always)]
2928
fn into_iter(mut self) -> Self::IntoIter {

src/remap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::CacheLineAlign;
21
use crate::error::Error;
32
use crate::image::Image;
43
use crate::kmeans::Kmeans;
@@ -8,6 +7,7 @@ use crate::quant::QuantizationResult;
87
use crate::rayoff::*;
98
use crate::rows::{temp_buf, DynamicRows};
109
use crate::seacow::{RowBitmap, RowBitmapMut};
10+
use crate::CacheLineAlign;
1111
use std::cell::RefCell;
1212
use std::mem::MaybeUninit;
1313

@@ -268,7 +268,7 @@ fn dither_row(row_pixels: &[f_pixel], output_pixels_row: &mut [MaybeUninit<PalIn
268268
last_match
269269
};
270270
let (matched, dither_diff) = n.search(&spx, guessed_match as _);
271-
let mut matched = matched as PalIndexRemap;
271+
let mut matched = matched as PalIndexRemap;
272272
last_match = matched as PalIndexRemap;
273273
let mut output_px = palette[last_match as usize];
274274
if let Some(bg_pixel) = bg_pixels.get(col) {

src/rows.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::error::Error;
22
use crate::pal::{f_pixel, gamma_lut, RGBA};
3-
use crate::seacow::Pointer;
4-
use crate::seacow::SeaCow;
3+
use crate::seacow::{Pointer, SeaCow};
54
use crate::LIQ_HIGH_MEMORY_LIMIT;
65
use std::mem::MaybeUninit;
76

@@ -52,11 +51,9 @@ impl Clone for DynamicRows<'_, '_> {
5251
height: self.height,
5352
f_pixels: self.f_pixels.clone(),
5453
pixels: match &self.pixels {
55-
PixelsSource::Pixels { rows, pixels } => {
56-
PixelsSource::Pixels {
57-
rows: rows.clone(),
58-
pixels: pixels.clone(),
59-
}
54+
PixelsSource::Pixels { rows, pixels } => PixelsSource::Pixels {
55+
rows: rows.clone(),
56+
pixels: pixels.clone(),
6057
},
6158
PixelsSource::Callback(_) => {
6259
let area = self.width as usize * self.height as usize;
@@ -118,7 +115,7 @@ impl<'a, 'pixels, 'rows> DynamicRowsIter<'a, 'pixels, 'rows> {
118115
}
119116
}
120117

121-
impl<'pixels,'rows> DynamicRows<'pixels,'rows> {
118+
impl<'pixels, 'rows> DynamicRows<'pixels, 'rows> {
122119
#[inline]
123120
pub(crate) fn new(width: u32, height: u32, pixels: PixelsSource<'pixels, 'rows>, gamma: f64) -> Self {
124121
debug_assert!(gamma > 0.);
@@ -134,7 +131,7 @@ impl<'pixels,'rows> DynamicRows<'pixels,'rows> {
134131
cb(temp_row, row);
135132
// cb needs to be marked as unsafe, since it's responsible for initialization :(
136133
unsafe { slice_assume_init_mut(temp_row) }
137-
}
134+
},
138135
}
139136
}
140137

src/seacow.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,15 @@ impl<T> SeaCow<'static, T> {
2929
#[inline]
3030
#[must_use]
3131
pub fn boxed(data: Box<[T]>) -> Self {
32-
Self {
33-
inner: SeaCowInner::Boxed(data),
34-
}
32+
Self { inner: SeaCowInner::Boxed(data) }
3533
}
3634
}
3735

3836
impl<'a, T> SeaCow<'a, T> {
3937
#[inline]
4038
#[must_use]
4139
pub fn borrowed(data: &'a [T]) -> Self {
42-
Self {
43-
inner: SeaCowInner::Borrowed(data),
44-
}
40+
Self { inner: SeaCowInner::Borrowed(data) }
4541
}
4642

4743
/// The pointer must be `malloc`-allocated
@@ -187,7 +183,7 @@ impl<'a, T: Sync + Send + Copy + 'static> RowBitmapMut<'a, T> {
187183
})
188184
}
189185

190-
pub(crate) fn chunks(&mut self, chunk_size: usize) -> impl Iterator<Item=RowBitmapMut<'_, T>> {
186+
pub(crate) fn chunks(&mut self, chunk_size: usize) -> impl Iterator<Item = RowBitmapMut<'_, T>> {
191187
self.rows.borrow_mut().chunks_mut(chunk_size).map(|chunk| RowBitmapMut {
192188
width: self.width,
193189
rows: MutCow::Borrowed(chunk),

0 commit comments

Comments
 (0)