Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt fixes #271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions benches/decoding_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,28 @@ fn read_metadata(image: &[u8]) -> ImageInfo {

fn main() {
let mut c = Criterion::default().configure_from_args();
c.bench_function("decode a 512x512 JPEG", |b| b.iter(|| {
read_image(include_bytes!("tower.jpg"))
}));

c.bench_function("decode a 512x512 progressive JPEG", |b| b.iter(|| {
read_image(include_bytes!("tower_progressive.jpg"))
}));

c.bench_function("decode a 512x512 grayscale JPEG", |b| b.iter(|| {
read_image(include_bytes!("tower_grayscale.jpg"))
}));

c.bench_function("extract metadata from an image", |b| b.iter(|| {
read_metadata(include_bytes!("tower.jpg"))
}));

c.bench_function("decode a 3072x2048 RGB Lossless JPEG", |b| b.iter(|| {
read_image(include_bytes!("../tests/reftest/images/lossless/jpeg_lossless_sel1-rgb.jpg"))
}));
c.bench_function("decode a 512x512 JPEG", |b| {
b.iter(|| read_image(include_bytes!("tower.jpg")))
});

c.bench_function("decode a 512x512 progressive JPEG", |b| {
b.iter(|| read_image(include_bytes!("tower_progressive.jpg")))
});

c.bench_function("decode a 512x512 grayscale JPEG", |b| {
b.iter(|| read_image(include_bytes!("tower_grayscale.jpg")))
});

c.bench_function("extract metadata from an image", |b| {
b.iter(|| read_metadata(include_bytes!("tower.jpg")))
});

c.bench_function("decode a 3072x2048 RGB Lossless JPEG", |b| {
b.iter(|| {
read_image(include_bytes!(
"../tests/reftest/images/lossless/jpeg_lossless_sel1-rgb.jpg"
))
})
});
c.final_summary();
}
}
21 changes: 11 additions & 10 deletions examples/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ fn main() {
jpeg::PixelFormat::L16 => {
encoder.set_depth(png::BitDepth::Sixteen);
encoder.set_color(png::ColorType::Grayscale);
},
jpeg::PixelFormat::RGB24 => {
}
jpeg::PixelFormat::RGB24 => {
encoder.set_depth(png::BitDepth::Eight);
encoder.set_color(png::ColorType::RGB);
},
}
jpeg::PixelFormat::CMYK32 => {
data = cmyk_to_rgb(&mut data);
encoder.set_depth(png::BitDepth::Eight);
encoder.set_color(png::ColorType::RGB)
},
}
jpeg::PixelFormat::L8 => {
encoder.set_depth(png::BitDepth::Eight);
encoder.set_color(png::ColorType::Grayscale);
},
}
}

encoder.write_header()
.expect("writing png header failed")
.write_image_data(&data)
.expect("png encoding failed");

encoder
.write_header()
.expect("writing png header failed")
.write_image_data(&data)
.expect("png encoding failed");
}

fn cmyk_to_rgb(input: &[u8]) -> Vec<u8> {
Expand Down
23 changes: 15 additions & 8 deletions src/arch/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn idct8(data: &mut [v128; 8]) {

#[cfg(target_arch = "wasm32")]
#[target_feature(enable = "simd128")]
#[rustfmt::skip]
fn transpose8(data: &mut [v128; 8]) {
// Transpose a 8x8 matrix with a sequence of interleaving operations.
// Naming: dABl contains elements from the *l*ower halves of vectors A and B, interleaved, i.e.
Expand Down Expand Up @@ -176,10 +177,7 @@ pub fn dequantize_and_idct_block_8x8(
// `output_linestride * i + 7` < output.len(), so all accesses are in-bounds.
unsafe {
v128_store64_lane::<0>(
u8x16_narrow_i16x8(
i16x8_shr(data_with_offset, SHIFT + 3),
i16x8_splat(0),
),
u8x16_narrow_i16x8(i16x8_shr(data_with_offset, SHIFT + 3), i16x8_splat(0)),
output.as_mut_ptr().wrapping_add(output_linestride * i) as *mut _,
);
}
Expand All @@ -188,8 +186,12 @@ pub fn dequantize_and_idct_block_8x8(

#[cfg(target_arch = "wasm32")]
#[target_feature(enable = "simd128")]
pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8], output: &mut [u8]) -> usize {

pub fn color_convert_line_ycbcr(
y_slice: &[u8],
cb_slice: &[u8],
cr_slice: &[u8],
output: &mut [u8],
) -> usize {
assert!(output.len() % 3 == 0);
let num = output.len() / 3;
assert!(num <= y_slice.len());
Expand Down Expand Up @@ -241,7 +243,7 @@ pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8]
let b = u8x16_narrow_i16x8(i16x8_shr(b, SHIFT), zero);

// Shuffle rrrrrrrrggggggggbbbbbbbb to rgbrgbrgb...

#[rustfmt::skip]
let rg_lanes = i8x16_shuffle::<0, 16,
1, 17,
2, 18,
Expand All @@ -251,13 +253,15 @@ pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8]
6, 22,
7, 23>(r, g);

#[rustfmt::skip]
let rgb_low = i8x16_shuffle::<0, 1, 16, // r0, g0, b0
2, 3, 17, // r1, g1, b1
4, 5, 18, // r2, g2, b2
6, 7, 19, // r3, g3, b3
8, 9, 20, // r4, g4, b4
10>(rg_lanes, b); // r5

#[rustfmt::skip]
let rgb_hi = i8x16_shuffle::<11, 21, 12, // g5, b5, r6
13, 22, 14, // g6, b6, r7
15, 23, 0, // g7, b7, --
Expand All @@ -269,7 +273,10 @@ pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8]
// `output.len() - 1`.
unsafe {
v128_store(output.as_mut_ptr().wrapping_add(24 * i) as *mut _, rgb_low);
v128_store64_lane::<0>(rgb_hi, output.as_mut_ptr().wrapping_add(24 * i + 16) as *mut _);
v128_store64_lane::<0>(
rgb_hi,
output.as_mut_ptr().wrapping_add(24 * i + 16) as *mut _,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ impl<R: Read> Decoder<R> {
}
}

#[allow(clippy::type_complexity)]
#[allow(clippy::type_complexity)]
fn decode_scan(
&mut self,
frame: &FrameInfo,
Expand Down
Loading