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