Skip to content

Commit 4e7b1e1

Browse files
committed
Run cargo fmt
1 parent 19c5ded commit 4e7b1e1

8 files changed

Lines changed: 63 additions & 67 deletions

File tree

src/avx2/fdct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,4 @@ fn avx_store(input: __m256i, output: &mut [i16]) {
481481
assert!(core::mem::size_of::<[i16; 16]>() == core::mem::size_of::<__m256i>());
482482
// SAFETY: we've checked sizes above. The load is unaligned, so no alignment requirements.
483483
unsafe { _mm256_storeu_si256(output.as_mut_ptr() as *mut __m256i, input) }
484-
}
484+
}

src/avx2/ycbcr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#[cfg(target_arch = "x86")]
22
use core::arch::x86::{
3-
__m256i, _mm256_add_epi32, _mm256_mullo_epi32, _mm256_set1_epi32, _mm256_set_epi32,
3+
__m256i, _mm256_add_epi32, _mm256_mullo_epi32, _mm256_set_epi32, _mm256_set1_epi32,
44
_mm256_srli_epi32, _mm256_sub_epi32,
55
};
66

77
#[cfg(target_arch = "x86_64")]
88
use core::arch::x86_64::{
9-
__m256i, _mm256_add_epi32, _mm256_mullo_epi32, _mm256_set1_epi32, _mm256_set_epi32,
9+
__m256i, _mm256_add_epi32, _mm256_mullo_epi32, _mm256_set_epi32, _mm256_set1_epi32,
1010
_mm256_srli_epi32, _mm256_sub_epi32,
1111
};
1212

1313
use alloc::vec::Vec;
1414

15-
use crate::{rgb_to_ycbcr, ImageBuffer, JpegColorType};
15+
use crate::{ImageBuffer, JpegColorType, rgb_to_ycbcr};
1616

1717
macro_rules! ycbcr_image_avx2 {
1818
($name:ident, $num_colors:expr, $o1:expr, $o2:expr, $o3:expr) => {
@@ -229,7 +229,9 @@ mod tests {
229229
for (i, pixel) in scalar_result.iter().copied().enumerate() {
230230
let avx_pixel: [u8; 3] = [buffers[0][i], buffers[1][i], buffers[2][i]];
231231
if pixel != avx_pixel {
232-
panic!("Mismatch at index {i}: scalar result is {pixel:?}, avx result is {avx_pixel:?}");
232+
panic!(
233+
"Mismatch at index {i}: scalar result is {pixel:?}, avx result is {avx_pixel:?}"
234+
);
233235
}
234236
}
235237
}

src/encoder.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::image_buffer::*;
44
use crate::marker::Marker;
55
use crate::quantization::{QuantizationTable, QuantizationTableType};
66
use crate::writer::{JfifWrite, JfifWriter, ZIGZAG};
7-
use crate::{PixelDensity, EncodingError};
7+
use crate::{EncodingError, PixelDensity};
88

99
use alloc::vec;
1010
use alloc::vec::Vec;
@@ -353,11 +353,7 @@ impl<W: JfifWrite> Encoder<W> {
353353
/// # Errors
354354
///
355355
/// Returns an error if the segment number is invalid or data exceeds the allowed size
356-
pub fn add_app_segment(
357-
&mut self,
358-
segment_nr: u8,
359-
data: Vec<u8>,
360-
) -> Result<(), EncodingError> {
356+
pub fn add_app_segment(&mut self, segment_nr: u8, data: Vec<u8>) -> Result<(), EncodingError> {
361357
if segment_nr == 0 || segment_nr > 15 {
362358
Err(EncodingError::InvalidAppSegment(segment_nr))
363359
} else if data.len() > 65533 {
@@ -749,10 +745,8 @@ impl<W: JfifWrite> Encoder<W> {
749745
&row[i],
750746
block_x * 8 * max_h_sampling + (h_offset * 8),
751747
v_offset * 8,
752-
max_h_sampling
753-
/ component.horizontal_sampling_factor as usize,
754-
max_v_sampling
755-
/ component.vertical_sampling_factor as usize,
748+
max_h_sampling / component.horizontal_sampling_factor as usize,
749+
max_v_sampling / component.vertical_sampling_factor as usize,
756750
buffer_width,
757751
);
758752

src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ impl Display for EncodingError {
6565
}
6666

6767
impl Error for EncodingError {
68-
6968
#[cfg(feature = "std")]
7069
fn source(&self) -> Option<&(dyn Error + 'static)> {
7170
match self {
@@ -74,4 +73,3 @@ impl Error for EncodingError {
7473
}
7574
}
7675
}
77-

src/fdct.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,8 @@ pub fn fdct(data: &mut [i16; 64]) {
134134
data2[offset + 4] = (tmp10 - tmp11) << PASS1_BITS;
135135

136136
let z1 = (tmp12 + tmp13) * FIX_0_541196100;
137-
data2[offset + 2] = descale(
138-
z1 + (tmp13 * FIX_0_765366865),
139-
CONST_BITS - PASS1_BITS,
140-
);
141-
data2[offset + 6] = descale(
142-
z1 + (tmp12 * -FIX_1_847759065),
143-
CONST_BITS - PASS1_BITS,
144-
);
137+
data2[offset + 2] = descale(z1 + (tmp13 * FIX_0_765366865), CONST_BITS - PASS1_BITS);
138+
data2[offset + 6] = descale(z1 + (tmp12 * -FIX_1_847759065), CONST_BITS - PASS1_BITS);
145139

146140
/* Odd part per figure 8 --- note paper omits factor of sqrt(2).
147141
* cK represents cos(K*pi/16).

src/image_buffer.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ impl<'a> ImageBuffer for GrayImage<'a> {
122122
}
123123

124124
#[inline(always)]
125-
fn get_line(data: &[u8], y: u16, width:u16, num_colors: usize) -> &[u8] {
126-
let width= usize::from(width);
125+
fn get_line(data: &[u8], y: u16, width: u16, num_colors: usize) -> &[u8] {
126+
let width = usize::from(width);
127127
let y = usize::from(y);
128128

129-
let start = y *width * num_colors;
129+
let start = y * width * num_colors;
130130
let end = start + width * num_colors;
131131

132132
&data[start..end]
@@ -155,13 +155,13 @@ macro_rules! ycbcr_image {
155155

156156
// Doing the convertion in chunks allows the compiler to vectorize the code
157157
// A size of 16 seems optimal for SSE and AVX capable hardware
158-
const CHUNK_SIZE:usize = 16;
158+
const CHUNK_SIZE: usize = 16;
159159

160-
let mut y_buffer = [0;CHUNK_SIZE];
161-
let mut cb_buffer = [0;CHUNK_SIZE];
162-
let mut cr_buffer = [0;CHUNK_SIZE];
160+
let mut y_buffer = [0; CHUNK_SIZE];
161+
let mut cb_buffer = [0; CHUNK_SIZE];
162+
let mut cr_buffer = [0; CHUNK_SIZE];
163163

164-
for chuck in line.chunks_exact($num_colors*CHUNK_SIZE) {
164+
for chuck in line.chunks_exact($num_colors * CHUNK_SIZE) {
165165
for i in (0..CHUNK_SIZE) {
166166
let (y, cb, cr) = rgb_to_ycbcr(
167167
chuck[i * $num_colors + $o1],
@@ -182,11 +182,11 @@ macro_rules! ycbcr_image {
182182
// Add the remaining pixels in case the number of
183183
// pixels is not a multiple of CHUNK_SIZE
184184
let pixel = line.len() / $num_colors;
185-
for i in pixel/CHUNK_SIZE*CHUNK_SIZE..pixel {
185+
for i in pixel / CHUNK_SIZE * CHUNK_SIZE..pixel {
186186
let (y, cb, cr) = rgb_to_ycbcr(
187-
line[i*$num_colors + $o1],
188-
line[i*$num_colors + $o2],
189-
line[i*$num_colors + $o3],
187+
line[i * $num_colors + $o1],
188+
line[i * $num_colors + $o2],
189+
line[i * $num_colors + $o3],
190190
);
191191

192192
buffers[0].push(y);
@@ -275,13 +275,7 @@ impl<'a> ImageBuffer for CmykAsYcckImage<'a> {
275275
let line = get_line(self.0, y, self.width(), 4);
276276

277277
for pixel in line.chunks_exact(4) {
278-
279-
let (y, cb, cr, k) = cmyk_to_ycck(
280-
pixel[0],
281-
pixel[1],
282-
pixel[2],
283-
pixel[3],
284-
);
278+
let (y, cb, cr, k) = cmyk_to_ycck(pixel[0], pixel[1], pixel[2], pixel[3]);
285279

286280
buffers[0].push(y);
287281
buffers[1].push(cb);
@@ -310,7 +304,6 @@ impl<'a> ImageBuffer for YcckImage<'a> {
310304
let line = get_line(self.0, y, self.width(), 4);
311305

312306
for pixel in line.chunks_exact(4) {
313-
314307
buffers[0].push(pixel[0]);
315308
buffers[1].push(pixel[1]);
316309
buffers[2].push(pixel[2]);
@@ -330,7 +323,6 @@ mod tests {
330323

331324
#[test]
332325
fn test_rgb_to_ycbcr() {
333-
334326
assert_rgb_to_ycbcr([0, 0, 0], [0, 128, 128]);
335327
assert_rgb_to_ycbcr([255, 255, 255], [255, 128, 128]);
336328
assert_rgb_to_ycbcr([255, 0, 0], [76, 85, 255]);

src/lib.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,28 @@ mod writer;
4444

4545
pub use encoder::{ColorType, Encoder, JpegColorType, SamplingFactor};
4646
pub use error::EncodingError;
47-
pub use image_buffer::{cmyk_to_ycck, rgb_to_ycbcr, ImageBuffer};
47+
pub use image_buffer::{ImageBuffer, cmyk_to_ycck, rgb_to_ycbcr};
4848
pub use quantization::QuantizationTableType;
49-
pub use writer::{PixelDensity, PixelDensityUnit, JfifWrite};
49+
pub use writer::{JfifWrite, PixelDensity, PixelDensityUnit};
5050

5151
#[cfg(feature = "benchmark")]
5252
pub use fdct::fdct;
5353

5454
#[cfg(feature = "benchmark")]
5555
pub use image_buffer::RgbImage;
5656

57-
#[cfg(all(feature = "benchmark", feature = "simd", any(target_arch = "x86", target_arch = "x86_64")))]
57+
#[cfg(all(
58+
feature = "benchmark",
59+
feature = "simd",
60+
any(target_arch = "x86", target_arch = "x86_64")
61+
))]
5862
pub use avx2::fdct_avx2;
5963

60-
#[cfg(all(feature = "benchmark", feature = "simd", any(target_arch = "x86", target_arch = "x86_64")))]
64+
#[cfg(all(
65+
feature = "benchmark",
66+
feature = "simd",
67+
any(target_arch = "x86", target_arch = "x86_64")
68+
))]
6169
pub use avx2::RgbImageAVX2;
6270

6371
#[cfg(test)]
@@ -412,10 +420,12 @@ mod tests {
412420
.encode(&data, width, height, ColorType::Rgb)
413421
.unwrap();
414422

415-
assert!(result
416-
.as_slice()
417-
.windows(DRI_DATA.len())
418-
.any(|w| w == DRI_DATA));
423+
assert!(
424+
result
425+
.as_slice()
426+
.windows(DRI_DATA.len())
427+
.any(|w| w == DRI_DATA)
428+
);
419429

420430
check_result(data, width, height, &mut result, PixelFormat::RGB24);
421431
}
@@ -435,10 +445,12 @@ mod tests {
435445
.encode(&data, width, height, ColorType::Rgb)
436446
.unwrap();
437447

438-
assert!(result
439-
.as_slice()
440-
.windows(DRI_DATA.len())
441-
.any(|w| w == DRI_DATA));
448+
assert!(
449+
result
450+
.as_slice()
451+
.windows(DRI_DATA.len())
452+
.any(|w| w == DRI_DATA)
453+
);
442454

443455
check_result(data, width, height, &mut result, PixelFormat::RGB24);
444456
}
@@ -458,10 +470,12 @@ mod tests {
458470
.encode(&data, width, height, ColorType::Rgb)
459471
.unwrap();
460472

461-
assert!(result
462-
.as_slice()
463-
.windows(DRI_DATA.len())
464-
.any(|w| w == DRI_DATA));
473+
assert!(
474+
result
475+
.as_slice()
476+
.windows(DRI_DATA.len())
477+
.any(|w| w == DRI_DATA)
478+
);
465479

466480
check_result(data, width, height, &mut result, PixelFormat::RGB24);
467481
}
@@ -481,10 +495,12 @@ mod tests {
481495

482496
let segment_data = b"\xEF\0\x09HOHOHO\0";
483497

484-
assert!(result
485-
.as_slice()
486-
.windows(segment_data.len())
487-
.any(|w| w == segment_data));
498+
assert!(
499+
result
500+
.as_slice()
501+
.windows(segment_data.len())
502+
.any(|w| w == segment_data)
503+
);
488504
}
489505

490506
#[test]

src/writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crate::EncodingError;
12
use crate::encoder::Component;
23
use crate::huffman::{CodingClass, HuffmanTable};
34
use crate::marker::{Marker, SOFType};
45
use crate::quantization::QuantizationTable;
5-
use crate::EncodingError;
66

77
/// Represents the pixel density of an image
88
///

0 commit comments

Comments
 (0)