A bunch of clippy fixes
This commit is contained in:
1 parent
daa0e3eabf
commit
60f866c119
11 files changed
+59
-61
No files matched your search
+1
-1
@@ -537,7 +537,7 @@ impl Entry {
|
||||
Ok(UnsignedBig(u64::from(buf[0])))
|
||||
}),
|
||||
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| {
|
||||
Ok(UnsignedBig(u64::from(reader.read_u16()?)))
|
||||
|
||||
@@ -618,8 +618,8 @@ impl Image {
|
||||
reader.read_exact(tile)?;
|
||||
|
||||
for row in 0..data_dims.1 as usize {
|
||||
let row_start = row as usize * output_width as usize * samples;
|
||||
let row_end = (row + 1) * output_width as usize * samples;
|
||||
let row_start = row * output_width * samples;
|
||||
let row_end = (row + 1) * output_width * samples;
|
||||
let row = buffer.subrange(row_start..row_end);
|
||||
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];
|
||||
|
||||
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;
|
||||
|
||||
reader.read_exact(&mut encoded)?;
|
||||
@@ -647,7 +647,7 @@ impl Image {
|
||||
}
|
||||
} else {
|
||||
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 = &mut buffer.as_bytes_mut()[(row_start * byte_len)..(row_end * byte_len)];
|
||||
|
||||
+6
-6
@@ -221,7 +221,7 @@ impl<'a> DecodingBuffer<'a> {
|
||||
|
||||
fn as_bytes_mut(&mut self) -> &mut [u8] {
|
||||
match self {
|
||||
DecodingBuffer::U8(buf) => &mut *buf,
|
||||
DecodingBuffer::U8(ref mut buf) => buf,
|
||||
DecodingBuffer::I8(buf) => bytecast::i8_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),
|
||||
@@ -371,8 +371,8 @@ pub fn fp_predict_f32(input: &mut [u8], output: &mut [f32], samples: usize) {
|
||||
for i in 0..output.len() {
|
||||
// TODO: use f32::from_be_bytes() when we can (version 1.40)
|
||||
output[i] = f32::from_bits(u32::from_be_bytes([
|
||||
input[input.len() / 4 * 0 + i],
|
||||
input[input.len() / 4 * 1 + i],
|
||||
input[i],
|
||||
input[input.len() / 4 + i],
|
||||
input[input.len() / 4 * 2 + 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() {
|
||||
// TODO: use f64::from_be_bytes() when we can (version 1.40)
|
||||
output[i] = f64::from_bits(u64::from_be_bytes([
|
||||
input[input.len() / 8 * 0 + i],
|
||||
input[input.len() / 8 * 1 + i],
|
||||
input[i],
|
||||
input[input.len() / 8 + i],
|
||||
input[input.len() / 8 * 2 + i],
|
||||
input[input.len() / 8 * 3 + i],
|
||||
input[input.len() / 8 * 4 + i],
|
||||
@@ -1103,7 +1103,7 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
)),
|
||||
},
|
||||
format => {
|
||||
Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.clone()]).into())
|
||||
Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![*format]).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ impl<R: Read> Read for PackBitsReader<R> {
|
||||
let mut header: [u8; 1] = [0];
|
||||
self.reader.read_exact(&mut header)?;
|
||||
let h = header[0] as i8;
|
||||
if h >= -127 && h <= -1 {
|
||||
if (-127..=-1).contains(&h) {
|
||||
let mut data: [u8; 1] = [0];
|
||||
self.reader.read_exact(&mut data)?;
|
||||
self.state = PackBitsReaderState::Repeat { value: data[0] };
|
||||
@@ -249,7 +249,7 @@ impl<R: Read> Read for PackBitsReader<R> {
|
||||
if self.count == 0 {
|
||||
self.state = PackBitsReaderState::Header;
|
||||
}
|
||||
return Ok(actual);
|
||||
Ok(actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Compression for Deflate {
|
||||
const COMPRESSION_METHOD: CompressionMethod = CompressionMethod::Deflate;
|
||||
|
||||
fn get_algorithm(&self) -> Compressor {
|
||||
Compressor::Deflate(self.clone())
|
||||
Compressor::Deflate(*self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ mod tests {
|
||||
|
||||
let mut compressed_data = Vec::<u8>::new();
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ pub enum Compressor {
|
||||
impl Default for Compressor {
|
||||
/// The default compression strategy does not apply any compression.
|
||||
fn default() -> Self {
|
||||
Compressor::Uncompressed(Uncompressed::default())
|
||||
Compressor::Uncompressed(Uncompressed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,6 @@ impl CompressionAlgorithm for Compressor {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub const TEST_DATA: &'static [u8] =
|
||||
pub const TEST_DATA: &[u8] =
|
||||
b"This is a string for checking various compression algorithms.";
|
||||
}
|
||||
@@ -80,33 +80,31 @@ impl CompressionAlgorithm for Packbits {
|
||||
run_index = 0;
|
||||
in_run = false;
|
||||
}
|
||||
} else {
|
||||
if bytes_pending > MAX_BYTES {
|
||||
// We have as much differing data as we can output in one chunk.
|
||||
// Output MAX_BYTES leaving one byte.
|
||||
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(MAX_BYTES))?);
|
||||
bufwriter.write(&bytes[pending_index..pending_index + MAX_BYTES as usize])?;
|
||||
bytes_written += 1 + MAX_BYTES as u64;
|
||||
} else if bytes_pending > MAX_BYTES {
|
||||
// We have as much differing data as we can output in one chunk.
|
||||
// Output MAX_BYTES leaving one byte.
|
||||
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(MAX_BYTES))?);
|
||||
bufwriter.write_all(&bytes[pending_index..pending_index + MAX_BYTES as usize])?;
|
||||
bytes_written += 1 + MAX_BYTES as u64;
|
||||
|
||||
pending_index += MAX_BYTES as usize;
|
||||
bytes_pending -= MAX_BYTES;
|
||||
run_index = bytes_pending - 1; // A run could start here
|
||||
} else if curr_byte == last_byte {
|
||||
if (bytes_pending - run_index >= MIN_REPT) || (run_index == 0) {
|
||||
// This is a worthwhile run
|
||||
if run_index != 0 {
|
||||
// Flush differing data out of input buffer
|
||||
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(run_index))?);
|
||||
bufwriter
|
||||
.write(&bytes[pending_index..pending_index + run_index as usize])?;
|
||||
bytes_written += 1 + run_index as u64;
|
||||
}
|
||||
bytes_pending -= run_index; // Length of run
|
||||
in_run = true;
|
||||
pending_index += MAX_BYTES as usize;
|
||||
bytes_pending -= MAX_BYTES;
|
||||
run_index = bytes_pending - 1; // A run could start here
|
||||
} else if curr_byte == last_byte {
|
||||
if (bytes_pending - run_index >= MIN_REPT) || (run_index == 0) {
|
||||
// This is a worthwhile run
|
||||
if run_index != 0 {
|
||||
// Flush differing data out of input buffer
|
||||
offset.get_or_insert(write_u8(&mut bufwriter, encode_diff(run_index))?);
|
||||
bufwriter
|
||||
.write_all(&bytes[pending_index..pending_index + run_index as usize])?;
|
||||
bytes_written += 1 + run_index as u64;
|
||||
}
|
||||
} else {
|
||||
run_index = bytes_pending - 1; // A run could start here
|
||||
bytes_pending -= run_index; // Length of run
|
||||
in_run = true;
|
||||
}
|
||||
} else {
|
||||
run_index = bytes_pending - 1; // A run could start here
|
||||
}
|
||||
last_byte = curr_byte;
|
||||
}
|
||||
@@ -119,7 +117,7 @@ impl CompressionAlgorithm for Packbits {
|
||||
} else {
|
||||
bytes_written += 1 + bytes_pending as u64;
|
||||
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()?;
|
||||
@@ -141,7 +139,7 @@ mod tests {
|
||||
|
||||
let mut compressed_data = Vec::<u8>::new();
|
||||
let mut writer = Cursor::new(&mut compressed_data);
|
||||
Packbits::default()
|
||||
Packbits
|
||||
.write_to(&mut writer, &UNCOMPRESSED_DATA)
|
||||
.unwrap();
|
||||
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
|
||||
@@ -150,13 +148,13 @@ mod tests {
|
||||
#[test]
|
||||
fn test_packbits_rept() {
|
||||
// compress buffer with repetitive sequence
|
||||
const UNCOMPRESSED_DATA: &'static [u8] =
|
||||
const UNCOMPRESSED_DATA: &[u8] =
|
||||
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 writer = Cursor::new(&mut compressed_data);
|
||||
Packbits::default()
|
||||
Packbits
|
||||
.write_to(&mut writer, UNCOMPRESSED_DATA)
|
||||
.unwrap();
|
||||
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
|
||||
@@ -192,7 +190,7 @@ mod tests {
|
||||
|
||||
let mut compressed_data = Vec::<u8>::new();
|
||||
let mut writer = Cursor::new(&mut compressed_data);
|
||||
Packbits::default()
|
||||
Packbits
|
||||
.write_to(&mut writer, data.as_slice())
|
||||
.unwrap();
|
||||
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
|
||||
@@ -201,12 +199,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_packbits() {
|
||||
// compress teststring
|
||||
const EXPECTED_COMPRESSED_DATA: &'static [u8] =
|
||||
const EXPECTED_COMPRESSED_DATA: &[u8] =
|
||||
b"\x3CThis is a string for checking various compression algorithms.";
|
||||
|
||||
let mut compressed_data = Vec::<u8>::new();
|
||||
let mut writer = Cursor::new(&mut compressed_data);
|
||||
Packbits::default()
|
||||
Packbits
|
||||
.write_to(&mut writer, TEST_DATA)
|
||||
.unwrap();
|
||||
assert_eq!(compressed_data, EXPECTED_COMPRESSED_DATA);
|
||||
|
||||
@@ -29,7 +29,7 @@ mod tests {
|
||||
fn test_no_compression() {
|
||||
let mut compressed_data = Vec::<u8>::new();
|
||||
let mut writer = Cursor::new(&mut compressed_data);
|
||||
Uncompressed::default()
|
||||
Uncompressed
|
||||
.write_to(&mut writer, TEST_DATA)
|
||||
.unwrap();
|
||||
assert_eq!(TEST_DATA, compressed_data);
|
||||
|
||||
+10
-10
@@ -219,19 +219,19 @@ impl<'a, W: 'a + Write + Seek, K: TiffKind> DirectoryEncoder<'a, W, K> {
|
||||
|
||||
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 (
|
||||
tag,
|
||||
&DirectoryEntry {
|
||||
data_type: ref field_type,
|
||||
ref count,
|
||||
data: ref offset,
|
||||
DirectoryEntry {
|
||||
data_type: field_type,
|
||||
count,
|
||||
data: offset,
|
||||
},
|
||||
) in self.ifd.iter()
|
||||
{
|
||||
self.writer.write_u16(*tag)?;
|
||||
self.writer.write_u16(*field_type)?;
|
||||
(*count).write(&mut self.writer)?;
|
||||
(*count).write(self.writer)?;
|
||||
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.
|
||||
pub fn write_data<T: TiffValue>(&mut self, value: T) -> TiffResult<u64> {
|
||||
let offset = self.writer.offset();
|
||||
value.write(&mut self.writer)?;
|
||||
value.write(self.writer)?;
|
||||
Ok(offset)
|
||||
}
|
||||
|
||||
@@ -257,9 +257,9 @@ impl<'a, W: 'a + Write + Seek, K: TiffKind> DirectoryEncoder<'a, W, K> {
|
||||
let curr_pos = self.writer.offset();
|
||||
|
||||
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)?;
|
||||
K::write_offset(&mut self.writer, 0)?;
|
||||
K::write_offset(self.writer, 0)?;
|
||||
|
||||
self.dropped = true;
|
||||
|
||||
@@ -400,7 +400,7 @@ impl<'a, W: 'a + Write + Seek, T: ColorType, K: TiffKind, D: Compression>
|
||||
strip_offsets: Vec::new(),
|
||||
strip_byte_count: Vec::new(),
|
||||
dropped: false,
|
||||
compression: compression,
|
||||
compression,
|
||||
_phantom: ::std::marker::PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ impl<W: Write> TiffWriter<W> {
|
||||
impl<W: Seek> TiffWriter<W> {
|
||||
pub fn goto_offset(&mut self, offset: u64) -> Result<(), io::Error> {
|
||||
self.offset = offset;
|
||||
self.writer.seek(SeekFrom::Start(offset as u64))?;
|
||||
self.writer.seek(SeekFrom::Start(offset))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user