Some slight manual touch up where style was bad
This commit is contained in:
1 parent
bf24b3f935
commit
7b41c823e9
3 files changed
+26
-43
No files matched your search
+9
-23
@@ -38,21 +38,16 @@ fn main() {
|
||||
let mut c = Criterion::default().configure_from_args();
|
||||
let mut group = c.benchmark_group("tiff-lzw");
|
||||
|
||||
/*
|
||||
run_bench_def(&mut group, BenchDef {
|
||||
data: include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/images/quad-lzw-compat.tiff")),
|
||||
id: "quad-lzw.tif",
|
||||
sample_size: 500,
|
||||
});
|
||||
*/
|
||||
macro_rules! data_file {
|
||||
($name:literal) => {
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), $name))
|
||||
};
|
||||
}
|
||||
|
||||
run_bench_def(
|
||||
&mut group,
|
||||
BenchDef {
|
||||
data: include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/images/issue_69_lzw.tiff"
|
||||
)),
|
||||
data: data_file!("/tests/images/issue_69_lzw.tiff"),
|
||||
id: "issue-69-lzw.tif",
|
||||
sample_size: 500,
|
||||
},
|
||||
@@ -61,10 +56,7 @@ fn main() {
|
||||
run_bench_def(
|
||||
&mut group,
|
||||
BenchDef {
|
||||
data: include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/benches/kodim02-lzw.tif"
|
||||
)),
|
||||
data: data_file!("/tests/benches/kodim02-lzw.tif"),
|
||||
id: "kodim02-lzw.tif",
|
||||
sample_size: 20,
|
||||
},
|
||||
@@ -73,10 +65,7 @@ fn main() {
|
||||
run_bench_def(
|
||||
&mut group,
|
||||
BenchDef {
|
||||
data: include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/benches/kodim07-lzw.tif"
|
||||
)),
|
||||
data: data_file!("/tests/benches/kodim07-lzw.tif"),
|
||||
id: "kodim07-lzw.tif",
|
||||
sample_size: 20,
|
||||
},
|
||||
@@ -85,10 +74,7 @@ fn main() {
|
||||
run_bench_def(
|
||||
&mut group,
|
||||
BenchDef {
|
||||
data: include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/benches/Transparency-lzw.tif"
|
||||
)),
|
||||
data: data_file!("/tests/benches/Transparency-lzw.tif"),
|
||||
id: "Transparency-lzw.tif",
|
||||
sample_size: 20,
|
||||
},
|
||||
|
||||
+7
-7
@@ -946,15 +946,15 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
TiffFormatError::InconsistentSizesEncountered,
|
||||
))?;
|
||||
|
||||
let rows_per_strip =
|
||||
usize::try_from(self.get_tag_u32(Tag::RowsPerStrip).unwrap_or(self.height))?;
|
||||
let tag_rows = self.get_tag_u32(Tag::RowsPerStrip).unwrap_or(self.height);
|
||||
let rows_per_strip = usize::try_from(tag_rows)?;
|
||||
|
||||
let strip_height = cmp::min(
|
||||
rows_per_strip,
|
||||
usize::try_from(self.height)? - index * rows_per_strip,
|
||||
);
|
||||
let sized_width = usize::try_from(self.width)?;
|
||||
let sized_height = usize::try_from(self.height)?;
|
||||
|
||||
let buffer_size = usize::try_from(self.width)? * strip_height * self.bits_per_sample.len();
|
||||
let strip_height = cmp::min(rows_per_strip, sized_height - index * rows_per_strip);
|
||||
|
||||
let buffer_size = sized_width * strip_height * self.bits_per_sample.len();
|
||||
|
||||
if buffer.len() < buffer_size {
|
||||
return Err(TiffError::FormatError(
|
||||
|
||||
+10
-13
@@ -1,7 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::io::{Seek, Write};
|
||||
use std::mem;
|
||||
use std::{cmp, io, mem};
|
||||
|
||||
use bytecast;
|
||||
use error::{TiffError, TiffFormatError, TiffResult};
|
||||
@@ -667,12 +667,9 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let start_row =
|
||||
::std::cmp::min(u64::from(self.height), self.strip_idx * self.rows_per_strip);
|
||||
let end_row = ::std::cmp::min(
|
||||
u64::from(self.height),
|
||||
(self.strip_idx + 1) * self.rows_per_strip,
|
||||
);
|
||||
let raw_start_row = self.strip_idx * self.rows_per_strip;
|
||||
let start_row = cmp::min(u64::from(self.height), raw_start_row);
|
||||
let end_row = cmp::min(u64::from(self.height), raw_start_row + self.rows_per_strip);
|
||||
|
||||
(end_row - start_row) * self.row_samples
|
||||
}
|
||||
@@ -685,8 +682,8 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> {
|
||||
// TODO: Compression
|
||||
let samples = self.next_strip_sample_count();
|
||||
if u64::try_from(value.len())? != samples {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::InvalidData,
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Slice is wrong size for strip",
|
||||
)
|
||||
.into());
|
||||
@@ -708,14 +705,14 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> {
|
||||
let num_pix = usize::try_from(self.width)?
|
||||
.checked_mul(usize::try_from(self.height)?)
|
||||
.ok_or_else(|| {
|
||||
::std::io::Error::new(
|
||||
::std::io::ErrorKind::InvalidInput,
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
"Image width * height exceeds usize",
|
||||
)
|
||||
})?;
|
||||
if data.len() < num_pix {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::InvalidData,
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"Input data slice is undersized for provided dimensions",
|
||||
)
|
||||
.into());
|
||||
|
||||
Reference in new issue
Block a user