From 7cd2a30e985cf7c2949638bb4f487b89fb13125a Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Tue, 17 Sep 2024 12:42:57 +0200 Subject: [PATCH 1/5] automatic clippy fix cargo clippy --fix --lib -p jxl --- jxl/src/entropy_coding/huffman.rs | 8 ++++---- jxl/src/headers/encodings.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jxl/src/entropy_coding/huffman.rs b/jxl/src/entropy_coding/huffman.rs index cae6436..d497e90 100644 --- a/jxl/src/entropy_coding/huffman.rs +++ b/jxl/src/entropy_coding/huffman.rs @@ -223,8 +223,8 @@ impl Table { } } else { let extra_bits = code_len - 14; - let old_repeat; - let repeat_delta; + + let new_len = if code_len == CODE_LENGTH_REPEAT_CODE { prev_code_len } else { @@ -234,13 +234,13 @@ impl Table { repeat = 0; repeat_code_len = new_len; } - old_repeat = repeat; + let old_repeat = repeat; if repeat > 0 { repeat -= 2; repeat <<= extra_bits; } repeat += br.read(extra_bits as usize)? as u8 + 3; - repeat_delta = repeat - old_repeat; + let repeat_delta = repeat - old_repeat; if symbol + repeat_delta as usize > al_size { return Err(Error::InvalidHuffman); } diff --git a/jxl/src/headers/encodings.rs b/jxl/src/headers/encodings.rs index 28058f4..aaf86b4 100644 --- a/jxl/src/headers/encodings.rs +++ b/jxl/src/headers/encodings.rs @@ -117,14 +117,14 @@ impl UnconditionalCoder<()> for u64 { 1 => Ok(1 + br.read(4)?), 2 => Ok(17 + br.read(8)?), _ => { - let mut result: u64 = br.read(12)? as u64; + let mut result: u64 = br.read(12)?; let mut shift = 12; while br.read(1)? == 1 { if shift >= 60 { assert_eq!(shift, 60); - return Ok(result | ((br.read(4)? as u64) << shift)); + return Ok(result | (br.read(4)? << shift)); } - result |= (br.read(8)? as u64) << shift; + result |= br.read(8)? << shift; shift += 8; } Ok(result) From 156305b044c9265c7555c2d06104389be079f867 Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Tue, 17 Sep 2024 12:43:32 +0200 Subject: [PATCH 2/5] fix item `TryFrom` is imported redundantly --- jxl/src/headers/encodings.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/jxl/src/headers/encodings.rs b/jxl/src/headers/encodings.rs index aaf86b4..ceba84a 100644 --- a/jxl/src/headers/encodings.rs +++ b/jxl/src/headers/encodings.rs @@ -373,7 +373,6 @@ impl UnconditionalCoder<()> for Extensions { br: &mut BitReader, _: &Self::Nonserialized, ) -> Result { - use std::convert::TryFrom; let selector = u64::read_unconditional(&(), br, &Empty {})?; let mut total_size: u64 = 0; for i in 0..64 { From 42cd726298fce937e1961c8fa182b5721ebaf086 Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Tue, 17 Sep 2024 12:48:17 +0200 Subject: [PATCH 3/5] add some allow(dead_code) --- jxl/src/entropy_coding/decode.rs | 8 ++++++++ jxl/src/headers/color_encoding.rs | 6 ++++++ jxl/src/headers/extra_channels.rs | 2 ++ jxl/src/headers/image_metadata.rs | 2 ++ jxl/src/headers/transform_data.rs | 4 ++++ 5 files changed, 22 insertions(+) diff --git a/jxl/src/entropy_coding/decode.rs b/jxl/src/entropy_coding/decode.rs index fddb9b7..e8c2ee1 100644 --- a/jxl/src/entropy_coding/decode.rs +++ b/jxl/src/entropy_coding/decode.rs @@ -32,9 +32,13 @@ pub fn decode_varint16(br: &mut BitReader) -> Result { #[derive(UnconditionalCoder, Debug)] struct LZ77Params { pub enabled: bool, + // TODO(firsching): remove once we use this! + #[allow(dead_code)] #[condition(enabled)] #[coder(u2S(224, 512, 4096, Bits(15) + 8))] pub min_symbol: Option, + // TODO(firsching): remove once we use this! + #[allow(dead_code)] #[condition(enabled)] #[coder(u2S(3, 4, Bits(2) + 5, Bits(8) + 9))] pub min_length: Option, @@ -48,8 +52,12 @@ enum Codes { #[derive(Debug)] pub struct Histograms { lz77_params: LZ77Params, + // TODO(firsching): remove once we use this! + #[allow(dead_code)] lz77_length_uint: Option, context_map: Vec, + // TODO(firsching): remove once we use this! + #[allow(dead_code)] log_alpha_size: usize, uint_configs: Vec, codes: Codes, diff --git a/jxl/src/headers/color_encoding.rs b/jxl/src/headers/color_encoding.rs index 2f5be57..240b050 100644 --- a/jxl/src/headers/color_encoding.rs +++ b/jxl/src/headers/color_encoding.rs @@ -63,9 +63,13 @@ pub enum RenderingIntent { pub struct CustomXY { #[default(0)] #[coder(u2S(Bits(19), Bits(19) + 524288, Bits(20) + 1048576, Bits(21) + 2097152))] + // TODO(firsching): remove once we use this! + #[allow(dead_code)] x: i32, #[default(0)] #[coder(u2S(Bits(19), Bits(19) + 524288, Bits(20) + 1048576, Bits(21) + 2097152))] + // TODO(firsching): remove once we use this! + #[allow(dead_code)] y: i32, } @@ -114,6 +118,8 @@ impl CustomTransferFunction { pub struct ColorEncoding { #[all_default] #[default(true)] + // TODO(firsching): remove once we use this! + #[allow(dead_code)] all_default: bool, #[default(false)] pub want_icc: bool, diff --git a/jxl/src/headers/extra_channels.rs b/jxl/src/headers/extra_channels.rs index 8cd3c8e..d6bf009 100644 --- a/jxl/src/headers/extra_channels.rs +++ b/jxl/src/headers/extra_channels.rs @@ -36,6 +36,8 @@ enum ExtraChannel { Optional, } +// TODO(firsching): remove once we use this! +#[allow(dead_code)] #[derive(UnconditionalCoder, Debug)] #[validate] pub struct ExtraChannelInfo { diff --git a/jxl/src/headers/image_metadata.rs b/jxl/src/headers/image_metadata.rs index 4e8d41c..e72aeff 100644 --- a/jxl/src/headers/image_metadata.rs +++ b/jxl/src/headers/image_metadata.rs @@ -96,6 +96,8 @@ impl ToneMapping { } } +// TODO(firsching): remove once we use this! +#[allow(dead_code)] #[derive(UnconditionalCoder, Debug)] pub struct ImageMetadata { #[all_default] diff --git a/jxl/src/headers/transform_data.rs b/jxl/src/headers/transform_data.rs index 65a111a..93b8bab 100644 --- a/jxl/src/headers/transform_data.rs +++ b/jxl/src/headers/transform_data.rs @@ -18,6 +18,8 @@ pub struct CustomTransformDataNonserialized { pub xyb_encoded: bool, } +// TODO(firsching): remove once we use this! +#[allow(dead_code)] #[derive(UnconditionalCoder, Debug)] pub struct OpsinInverseMatrix { #[all_default] @@ -322,6 +324,8 @@ const DEFAULT_KERN_8: [f32; 210] = [ -0.00458223, ]; +// TODO(firsching): remove once we use this! +#[allow(dead_code)] #[derive(UnconditionalCoder, Debug)] #[nonserialized(CustomTransformDataNonserialized)] pub struct CustomTransformData { From d090c2979e4bc3176b61e1518c8adca063feee2d Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Tue, 17 Sep 2024 12:48:47 +0200 Subject: [PATCH 4/5] fmt --- jxl/src/entropy_coding/huffman.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jxl/src/entropy_coding/huffman.rs b/jxl/src/entropy_coding/huffman.rs index d497e90..2e84ab8 100644 --- a/jxl/src/entropy_coding/huffman.rs +++ b/jxl/src/entropy_coding/huffman.rs @@ -223,8 +223,7 @@ impl Table { } } else { let extra_bits = code_len - 14; - - + let new_len = if code_len == CODE_LENGTH_REPEAT_CODE { prev_code_len } else { From baf751df04033df40eb1d2504f7b5063038acf64 Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Tue, 17 Sep 2024 12:50:36 +0200 Subject: [PATCH 5/5] remove unnecessary cast --- jxl/src/entropy_coding/huffman.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jxl/src/entropy_coding/huffman.rs b/jxl/src/entropy_coding/huffman.rs index 2e84ab8..3cc6444 100644 --- a/jxl/src/entropy_coding/huffman.rs +++ b/jxl/src/entropy_coding/huffman.rs @@ -365,7 +365,7 @@ impl Table { } counts[len] -= 1; let bits = (len - root_bits) as u8; - let value = sorted[symbol] as u16; + let value = sorted[symbol]; symbol += 1; let pos = table_pos + (key as usize >> root_bits); replicate_value(&mut table[pos..], step, TableEntry { bits, value });