A bunch of clippy fixes

This commit is contained in:
Jonathan Behrens committed 2023-08-20 13:32:08 -07:00
1 parent daa0e3eabf
commit 60f866c119
11 files changed
+40 -42

No files matched your search

+1 -1
View File
@@ -537,7 +537,7 @@ impl Entry {
Ok(UnsignedBig(u64::from(buf[0]))) Ok(UnsignedBig(u64::from(buf[0])))
}), }),
Type::SBYTE => self.decode_offset(self.count, bo, bigtiff, limits, reader, |reader| { Type::SBYTE => self.decode_offset(self.count, bo, bigtiff, limits, reader, |reader| {
Ok(SignedBig(i64::from(reader.read_i8()? as i8))) Ok(SignedBig(i64::from(reader.read_i8()?)))
}), }),
Type::SHORT => self.decode_offset(self.count, bo, bigtiff, limits, reader, |reader| { Type::SHORT => self.decode_offset(self.count, bo, bigtiff, limits, reader, |reader| {
Ok(UnsignedBig(u64::from(reader.read_u16()?))) Ok(UnsignedBig(u64::from(reader.read_u16()?)))
+4 -4
View File
@@ -618,8 +618,8 @@ impl Image {
reader.read_exact(tile)?; reader.read_exact(tile)?;
for row in 0..data_dims.1 as usize { for row in 0..data_dims.1 as usize {
let row_start = row as usize * output_width as usize * samples; let row_start = row * output_width * samples;
let row_end = (row + 1) * output_width as usize * samples; let row_end = (row + 1) * output_width * samples;
let row = buffer.subrange(row_start..row_end); let row = buffer.subrange(row_start..row_end);
super::fix_endianness_and_predict(row, samples, byte_order, predictor); super::fix_endianness_and_predict(row, samples, byte_order, predictor);
} }
@@ -632,7 +632,7 @@ impl Image {
let mut encoded = vec![0u8; chunk_dims.0 as usize * samples * byte_len]; let mut encoded = vec![0u8; chunk_dims.0 as usize * samples * byte_len];
for row in 0..data_dims.1 as usize { for row in 0..data_dims.1 as usize {
let row_start = row * output_width as usize * samples; let row_start = row * output_width * samples;
let row_end = row_start + data_dims.0 as usize * samples; let row_end = row_start + data_dims.0 as usize * samples;
reader.read_exact(&mut encoded)?; reader.read_exact(&mut encoded)?;
@@ -647,7 +647,7 @@ impl Image {
} }
} else { } else {
for row in 0..data_dims.1 as usize { for row in 0..data_dims.1 as usize {
let row_start = row * output_width as usize * samples; let row_start = row * output_width * samples;
let row_end = row_start + data_dims.0 as usize * samples; let row_end = row_start + data_dims.0 as usize * samples;
let row = &mut buffer.as_bytes_mut()[(row_start * byte_len)..(row_end * byte_len)]; let row = &mut buffer.as_bytes_mut()[(row_start * byte_len)..(row_end * byte_len)];
+6 -6
View File
@@ -221,7 +221,7 @@ impl<'a> DecodingBuffer<'a> {
fn as_bytes_mut(&mut self) -> &mut [u8] { fn as_bytes_mut(&mut self) -> &mut [u8] {
match self { match self {
DecodingBuffer::U8(buf) => &mut *buf, DecodingBuffer::U8(ref mut buf) => buf,
DecodingBuffer::I8(buf) => bytecast::i8_as_ne_mut_bytes(buf), DecodingBuffer::I8(buf) => bytecast::i8_as_ne_mut_bytes(buf),
DecodingBuffer::U16(buf) => bytecast::u16_as_ne_mut_bytes(buf), DecodingBuffer::U16(buf) => bytecast::u16_as_ne_mut_bytes(buf),
DecodingBuffer::I16(buf) => bytecast::i16_as_ne_mut_bytes(buf), DecodingBuffer::I16(buf) => bytecast::i16_as_ne_mut_bytes(buf),
@@ -371,8 +371,8 @@ pub fn fp_predict_f32(input: &mut [u8], output: &mut [f32], samples: usize) {
for i in 0..output.len() { for i in 0..output.len() {
// TODO: use f32::from_be_bytes() when we can (version 1.40) // TODO: use f32::from_be_bytes() when we can (version 1.40)
output[i] = f32::from_bits(u32::from_be_bytes([ output[i] = f32::from_bits(u32::from_be_bytes([
input[input.len() / 4 * 0 + i], input[i],
input[input.len() / 4 * 1 + i], input[input.len() / 4 + i],
input[input.len() / 4 * 2 + i], input[input.len() / 4 * 2 + i],
input[input.len() / 4 * 3 + i], input[input.len() / 4 * 3 + i],
])); ]));
@@ -384,8 +384,8 @@ pub fn fp_predict_f64(input: &mut [u8], output: &mut [f64], samples: usize) {
for i in 0..output.len() { for i in 0..output.len() {
// TODO: use f64::from_be_bytes() when we can (version 1.40) // TODO: use f64::from_be_bytes() when we can (version 1.40)
output[i] = f64::from_bits(u64::from_be_bytes([ output[i] = f64::from_bits(u64::from_be_bytes([
input[input.len() / 8 * 0 + i], input[i],
input[input.len() / 8 * 1 + i], input[input.len() / 8 + i],
input[input.len() / 8 * 2 + i], input[input.len() / 8 * 2 + i],
input[input.len() / 8 * 3 + i], input[input.len() / 8 * 3 + i],
input[input.len() / 8 * 4 + i], input[input.len() / 8 * 4 + i],
@@ -1103,7 +1103,7 @@ impl<R: Read + Seek> Decoder<R> {
)), )),
}, },
format => { format => {
Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.clone()]).into()) Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![*format]).into())
} }
} }
} }
+2 -2
View File
@@ -219,7 +219,7 @@ impl<R: Read> Read for PackBitsReader<R> {
let mut header: [u8; 1] = [0]; let mut header: [u8; 1] = [0];
self.reader.read_exact(&mut header)?; self.reader.read_exact(&mut header)?;
let h = header[0] as i8; let h = header[0] as i8;
if h >= -127 && h <= -1 { if (-127..=-1).contains(&h) {
let mut data: [u8; 1] = [0]; let mut data: [u8; 1] = [0];
self.reader.read_exact(&mut data)?; self.reader.read_exact(&mut data)?;
self.state = PackBitsReaderState::Repeat { value: data[0] }; self.state = PackBitsReaderState::Repeat { value: data[0] };
@@ -249,7 +249,7 @@ impl<R: Read> Read for PackBitsReader<R> {
if self.count == 0 { if self.count == 0 {
self.state = PackBitsReaderState::Header; self.state = PackBitsReaderState::Header;
} }
return Ok(actual); Ok(actual)
} }
} }
+1 -1
View File
@@ -46,7 +46,7 @@ impl Compression for Deflate {
const COMPRESSION_METHOD: CompressionMethod = CompressionMethod::Deflate; const COMPRESSION_METHOD: CompressionMethod = CompressionMethod::Deflate;
fn get_algorithm(&self) -> Compressor { fn get_algorithm(&self) -> Compressor {
Compressor::Deflate(self.clone()) Compressor::Deflate(*self)
} }
} }
+1 -1
View File
@@ -41,7 +41,7 @@ mod tests {
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Lzw::default().write_to(&mut writer, TEST_DATA).unwrap(); Lzw.write_to(&mut writer, TEST_DATA).unwrap();
assert_eq!(EXPECTED_COMPRESSED_DATA, compressed_data.as_slice()); assert_eq!(EXPECTED_COMPRESSED_DATA, compressed_data.as_slice());
} }
} }
+2 -2
View File
@@ -38,7 +38,7 @@ pub enum Compressor {
impl Default for Compressor { impl Default for Compressor {
/// The default compression strategy does not apply any compression. /// The default compression strategy does not apply any compression.
fn default() -> Self { fn default() -> Self {
Compressor::Uncompressed(Uncompressed::default()) Compressor::Uncompressed(Uncompressed)
} }
} }
@@ -55,6 +55,6 @@ impl CompressionAlgorithm for Compressor {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
pub const TEST_DATA: &'static [u8] = pub const TEST_DATA: &[u8] =
b"This is a string for checking various compression algorithms."; b"This is a string for checking various compression algorithms.";
} }
+11 -13
View File
@@ -80,12 +80,11 @@ impl CompressionAlgorithm for Packbits {
run_index = 0; run_index = 0;
in_run = false; in_run = false;
} }
} else { } else if bytes_pending > MAX_BYTES {
if bytes_pending > MAX_BYTES {
// We have as much differing data as we can output in one chunk. // We have as much differing data as we can output in one chunk.
// Output MAX_BYTES leaving one byte. // Output MAX_BYTES leaving one byte.
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(MAX_BYTES))?); offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(MAX_BYTES))?);
bufwriter.write(&bytes[pending_index..pending_index + MAX_BYTES as usize])?; bufwriter.write_all(&bytes[pending_index..pending_index + MAX_BYTES as usize])?;
bytes_written += 1 + MAX_BYTES as u64; bytes_written += 1 + MAX_BYTES as u64;
pending_index += MAX_BYTES as usize; pending_index += MAX_BYTES as usize;
@@ -98,7 +97,7 @@ impl CompressionAlgorithm for Packbits {
// Flush differing data out of input buffer // Flush differing data out of input buffer
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(run_index))?); offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(run_index))?);
bufwriter bufwriter
.write(&bytes[pending_index..pending_index + run_index as usize])?; .write_all(&bytes[pending_index..pending_index + run_index as usize])?;
bytes_written += 1 + run_index as u64; bytes_written += 1 + run_index as u64;
} }
bytes_pending -= run_index; // Length of run bytes_pending -= run_index; // Length of run
@@ -107,7 +106,6 @@ impl CompressionAlgorithm for Packbits {
} else { } else {
run_index = bytes_pending - 1; // A run could start here run_index = bytes_pending - 1; // A run could start here
} }
}
last_byte = curr_byte; last_byte = curr_byte;
} }
@@ -119,7 +117,7 @@ impl CompressionAlgorithm for Packbits {
} else { } else {
bytes_written += 1 + bytes_pending as u64; bytes_written += 1 + bytes_pending as u64;
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(bytes_pending))?); offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(bytes_pending))?);
bufwriter.write(&bytes[pending_index..pending_index + bytes_pending as usize])?; bufwriter.write_all(&bytes[pending_index..pending_index + bytes_pending as usize])?;
} }
bufwriter.flush()?; bufwriter.flush()?;
@@ -141,7 +139,7 @@ mod tests {
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Packbits::default() Packbits
.write_to(&mut writer, &UNCOMPRESSED_DATA) .write_to(&mut writer, &UNCOMPRESSED_DATA)
.unwrap(); .unwrap();
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA); assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
@@ -150,13 +148,13 @@ mod tests {
#[test] #[test]
fn test_packbits_rept() { fn test_packbits_rept() {
// compress buffer with repetitive sequence // compress buffer with repetitive sequence
const UNCOMPRESSED_DATA: &'static [u8] = const UNCOMPRESSED_DATA: &[u8] =
b"This strrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrring hangs."; b"This strrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrring hangs.";
const EXPECTED_COMPRESSED_DATA: &'static [u8] = b"\x06This st\xD1r\x09ing hangs."; const EXPECTED_COMPRESSED_DATA: &[u8] = b"\x06This st\xD1r\x09ing hangs.";
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Packbits::default() Packbits
.write_to(&mut writer, UNCOMPRESSED_DATA) .write_to(&mut writer, UNCOMPRESSED_DATA)
.unwrap(); .unwrap();
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA); assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
@@ -192,7 +190,7 @@ mod tests {
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Packbits::default() Packbits
.write_to(&mut writer, data.as_slice()) .write_to(&mut writer, data.as_slice())
.unwrap(); .unwrap();
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA); assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
@@ -201,12 +199,12 @@ mod tests {
#[test] #[test]
fn test_packbits() { fn test_packbits() {
// compress teststring // compress teststring
const EXPECTED_COMPRESSED_DATA: &'static [u8] = const EXPECTED_COMPRESSED_DATA: &[u8] =
b"\x3CThis is a string for checking various compression algorithms."; b"\x3CThis is a string for checking various compression algorithms.";
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Packbits::default() Packbits
.write_to(&mut writer, TEST_DATA) .write_to(&mut writer, TEST_DATA)
.unwrap(); .unwrap();
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA); assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
+1 -1
View File
@@ -29,7 +29,7 @@ mod tests {
fn test_no_compression() { fn test_no_compression() {
let mut compressed_data = Vec::<u8>::new(); let mut compressed_data = Vec::<u8>::new();
let mut writer = Cursor::new(&mut compressed_data); let mut writer = Cursor::new(&mut compressed_data);
Uncompressed::default() Uncompressed
.write_to(&mut writer, TEST_DATA) .write_to(&mut writer, TEST_DATA)
.unwrap(); .unwrap();
assert_eq!(TEST_DATA, compressed_data); assert_eq!(TEST_DATA, compressed_data);
+10 -10
View File
@@ -219,19 +219,19 @@ impl<'a, W: 'a + Write + Seek, K: TiffKind> DirectoryEncoder<'a, W, K> {
let offset = self.writer.offset(); let offset = self.writer.offset();
K::write_entry_count(&mut self.writer, self.ifd.len())?; K::write_entry_count(self.writer, self.ifd.len())?;
for ( for (
tag, tag,
&DirectoryEntry { DirectoryEntry {
data_type: ref field_type, data_type: field_type,
ref count, count,
data: ref offset, data: offset,
}, },
) in self.ifd.iter() ) in self.ifd.iter()
{ {
self.writer.write_u16(*tag)?; self.writer.write_u16(*tag)?;
self.writer.write_u16(*field_type)?; self.writer.write_u16(*field_type)?;
(*count).write(&mut self.writer)?; (*count).write(self.writer)?;
self.writer.write_bytes(offset)?; self.writer.write_bytes(offset)?;
} }
@@ -243,7 +243,7 @@ impl<'a, W: 'a + Write + Seek, K: TiffKind> DirectoryEncoder<'a, W, K> {
/// This could be used to write tiff strips. /// This could be used to write tiff strips.
pub fn write_data<T: TiffValue>(&mut self, value: T) -> TiffResult<u64> { pub fn write_data<T: TiffValue>(&mut self, value: T) -> TiffResult<u64> {
let offset = self.writer.offset(); let offset = self.writer.offset();
value.write(&mut self.writer)?; value.write(self.writer)?;
Ok(offset) Ok(offset)
} }
@@ -257,9 +257,9 @@ impl<'a, W: 'a + Write + Seek, K: TiffKind> DirectoryEncoder<'a, W, K> {
let curr_pos = self.writer.offset(); let curr_pos = self.writer.offset();
self.writer.goto_offset(self.ifd_pointer_pos)?; self.writer.goto_offset(self.ifd_pointer_pos)?;
K::write_offset(&mut self.writer, ifd_pointer)?; K::write_offset(self.writer, ifd_pointer)?;
self.writer.goto_offset(curr_pos)?; self.writer.goto_offset(curr_pos)?;
K::write_offset(&mut self.writer, 0)?; K::write_offset(self.writer, 0)?;
self.dropped = true; self.dropped = true;
@@ -400,7 +400,7 @@ impl<'a, W: 'a + Write + Seek, T: ColorType, K: TiffKind, D: Compression>
strip_offsets: Vec::new(), strip_offsets: Vec::new(),
strip_byte_count: Vec::new(), strip_byte_count: Vec::new(),
dropped: false, dropped: false,
compression: compression, compression,
_phantom: ::std::marker::PhantomData, _phantom: ::std::marker::PhantomData,
}) })
} }
+1 -1
View File
@@ -182,7 +182,7 @@ impl<W: Write> TiffWriter<W> {
impl<W: Seek> TiffWriter<W> { impl<W: Seek> TiffWriter<W> {
pub fn goto_offset(&mut self, offset: u64) -> Result<(), io::Error> { pub fn goto_offset(&mut self, offset: u64) -> Result<(), io::Error> {
self.offset = offset; self.offset = offset;
self.writer.seek(SeekFrom::Start(offset as u64))?; self.writer.seek(SeekFrom::Start(offset))?;
Ok(()) Ok(())
} }
} }