Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taavit committed Apr 29, 2023
1 parent 0538735 commit bc736a6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::is_x86_feature_detected;

/// Arch-specific implementation of YCbCr conversion. Returns the number of pixels that were
/// converted.
#[allow(clippy::type_complexity)]
pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &mut [u8]) -> usize>
{
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand All @@ -32,6 +33,7 @@ pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &
}

/// Arch-specific implementation of 8x8 IDCT.
#[allow(clippy::type_complexity)]
pub fn get_dequantize_and_idct_block_8x8(
) -> Option<unsafe fn(&[i16; 64], &[u16; 64], usize, &mut [u8])> {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Expand Down
27 changes: 15 additions & 12 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,13 @@ impl<R: Read> Decoder<R> {

let frame = self.frame.as_ref().unwrap();

if {
let required_mem = frame
.components
.len()
.checked_mul(frame.output_size.width.into())
.and_then(|m| m.checked_mul(frame.output_size.height.into()));
required_mem.map_or(true, |m| self.decoding_buffer_size_limit < m)
} {
if frame
.components
.len()
.checked_mul(frame.output_size.width.into())
.and_then(|m| m.checked_mul(frame.output_size.height.into()))
.map_or(true, |m| self.decoding_buffer_size_limit < m)
{
return Err(Error::Format(
"size of decoded image exceeds maximum allowed size".to_owned(),
));
Expand Down Expand Up @@ -779,6 +778,7 @@ impl<R: Read> Decoder<R> {
}
}

#[allow(clippy::type_complexity)]
fn decode_scan(
&mut self,
frame: &FrameInfo,
Expand Down Expand Up @@ -1009,10 +1009,11 @@ impl<R: Read> Decoder<R> {
// In the event of non-interleaved streams, if we're still building the buffer out,
// keep going; don't send it yet. We also need to ensure we don't skip over the last
// row(s) of the image.
if !is_interleaved && (mcu_y + 1) * 8 < frame.image_size.height {
if (mcu_y + 1) % component.vertical_sampling_factor as u16 > 0 {
continue;
}
if !is_interleaved
&& (mcu_y + 1) * 8 < frame.image_size.height
&& (mcu_y + 1) % component.vertical_sampling_factor as u16 > 0
{
continue;
}

let coefficients_per_mcu_row = component.block_size.width as usize
Expand Down Expand Up @@ -1069,6 +1070,7 @@ impl<R: Read> Decoder<R> {
}
}

#[allow(clippy::too_many_arguments)]
fn decode_block<R: Read>(
reader: &mut R,
coefficients: &mut [i16; 64],
Expand Down Expand Up @@ -1321,6 +1323,7 @@ fn compute_image(
}
}

#[allow(clippy::type_complexity)]
pub(crate) fn choose_color_convert_func(
component_count: usize,
color_transform: ColorTransform,
Expand Down
3 changes: 2 additions & 1 deletion src/decoder/lossless.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::io::Read;
use crate::decoder::{Decoder, MAX_COMPONENTS};
use crate::error::{Error, Result};
use crate::huffman::HuffmanDecoder;
use crate::marker::Marker;
use crate::parser::Predictor;
use crate::parser::{Component, FrameInfo, ScanInfo};
use std::io::Read;

impl<R: Read> Decoder<R> {
/// decode_scan_lossless
Expand Down Expand Up @@ -185,6 +185,7 @@ impl<R: Read> Decoder<R> {
}

/// H.1.2.1
#[allow(clippy::too_many_arguments)]
fn predict(
ra: i32,
rb: i32,
Expand Down
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub enum AppData {
}

// http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe
#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum AdobeColorTransform {
// RGB or CMYK
Expand Down Expand Up @@ -523,6 +524,7 @@ pub fn parse_dqt<R: Read>(reader: &mut R) -> Result<[Option<[u16; 64]>; 4]> {
}

// Section B.2.4.2
#[allow(clippy::type_complexity)]
pub fn parse_dht<R: Read>(reader: &mut R, is_baseline: Option<bool>) -> Result<(Vec<Option<HuffmanTable>>, Vec<Option<HuffmanTable>>)> {
let mut length = read_length(reader, DHT)?;
let mut dc_tables = vec![None, None, None, None];
Expand Down
32 changes: 15 additions & 17 deletions src/upsampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,27 @@ fn choose_upsampler(sampling_factors: (u8, u8),

if h1 && v1 {
Ok(Box::new(UpsamplerH1V1))
}
else if h2 && v1 {
} else if h2 && v1 {
Ok(Box::new(UpsamplerH2V1))
}
else if h1 && v2 {
} else if h1 && v2 {
Ok(Box::new(UpsamplerH1V2))
}
else if h2 && v2 {
} else if h2 && v2 {
Ok(Box::new(UpsamplerH2V2))
}
else {
if max_sampling_factors.0 % sampling_factors.0 != 0 || max_sampling_factors.1 % sampling_factors.1 != 0 {
Err(Error::Unsupported(UnsupportedFeature::NonIntegerSubsamplingRatio))
}
else {
Ok(Box::new(UpsamplerGeneric {
horizontal_scaling_factor: max_sampling_factors.0 / sampling_factors.0,
vertical_scaling_factor: max_sampling_factors.1 / sampling_factors.1
}))
}
} else if max_sampling_factors.0 % sampling_factors.0 != 0
|| max_sampling_factors.1 % sampling_factors.1 != 0
{
Err(Error::Unsupported(
UnsupportedFeature::NonIntegerSubsamplingRatio,
))
} else {
Ok(Box::new(UpsamplerGeneric {
horizontal_scaling_factor: max_sampling_factors.0 / sampling_factors.0,
vertical_scaling_factor: max_sampling_factors.1 / sampling_factors.1,
}))
}
}

#[allow(clippy::too_many_arguments)]
trait Upsample {
fn upsample_row(&self,
input: &[u8],
Expand Down
4 changes: 2 additions & 2 deletions src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum WorkerScopeInner {
not(any(target_arch = "asmjs", target_arch = "wasm32")),
feature = "rayon"
))]
Rayon(rayon::Scoped),
Rayon(Box<rayon::Scoped>),
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
Multithreaded(multithreaded::MpscWorker),
Immediate(immediate::ImmediateWorker),
Expand Down Expand Up @@ -86,7 +86,7 @@ impl WorkerScope {
not(any(target_arch = "asmjs", target_arch = "wasm32")),
feature = "rayon"
))]
WorkerScopeInner::Rayon(worker) => worker,
WorkerScopeInner::Rayon(worker) => worker.as_mut(),
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
WorkerScopeInner::Multithreaded(worker) => worker,
WorkerScopeInner::Immediate(worker) => worker,
Expand Down

0 comments on commit bc736a6

Please sign in to comment.