review changes: pass in width/height, unwrap reader bytes
This commit is contained in:
1 parent
666f871d30
commit
9fcc2a3b65
1 file changed
+18
-13
+18
-13
@@ -381,7 +381,8 @@ impl Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_reader<'r, R: 'r + Read>(
|
fn create_reader<'r, R: 'r + Read>(
|
||||||
&self,
|
width: u32,
|
||||||
|
height: u32,
|
||||||
reader: R,
|
reader: R,
|
||||||
compression_method: CompressionMethod,
|
compression_method: CompressionMethod,
|
||||||
compressed_length: u64,
|
compressed_length: u64,
|
||||||
@@ -454,22 +455,24 @@ impl Image {
|
|||||||
Box::new(Cursor::new(data))
|
Box::new(Cursor::new(data))
|
||||||
}
|
}
|
||||||
CompressionMethod::Fax4 => {
|
CompressionMethod::Fax4 => {
|
||||||
let width = u16::try_from(self.width)?;
|
let width = u16::try_from(width)?;
|
||||||
let height = u16::try_from(self.height)?;
|
let height = u16::try_from(height)?;
|
||||||
let mut out: Vec<u8> = Vec::with_capacity(usize::from(width) * usize::from(height));
|
let mut out: Vec<u8> = Vec::with_capacity(usize::from(width) * usize::from(height));
|
||||||
|
|
||||||
let mut buffer = Vec::with_capacity(usize::try_from(compressed_length)?);
|
|
||||||
reader.take(compressed_length).read_to_end(&mut buffer)?;
|
|
||||||
|
|
||||||
// all extant tiff/fax4 decoders I've found always assume that the photometric interpretation
|
// all extant tiff/fax4 decoders I've found always assume that the photometric interpretation
|
||||||
// is `WhiteIsZero`, ignoring the tag. ImageMagick appears to generate fax4-encoded tiffs
|
// is `WhiteIsZero`, ignoring the tag. ImageMagick appears to generate fax4-encoded tiffs
|
||||||
// with the tag incorrectly set to `BlackIsZero`.
|
// with the tag incorrectly set to `BlackIsZero`.
|
||||||
fax::decoder::decode_g4(buffer.into_iter(), width, Some(height), |transitions| {
|
fax::decoder::decode_g4(
|
||||||
out.extend(fax::decoder::pels(transitions, width).map(|c| match c {
|
reader.bytes().map(|b| b.unwrap()),
|
||||||
fax::Color::Black => 255,
|
width,
|
||||||
fax::Color::White => 0,
|
Some(height),
|
||||||
}))
|
|transitions| {
|
||||||
});
|
out.extend(fax::decoder::pels(transitions, width).map(|c| match c {
|
||||||
|
fax::Color::Black => 255,
|
||||||
|
fax::Color::White => 0,
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
);
|
||||||
Box::new(Cursor::new(out))
|
Box::new(Cursor::new(out))
|
||||||
}
|
}
|
||||||
method => {
|
method => {
|
||||||
@@ -673,7 +676,9 @@ impl Image {
|
|||||||
assert!(output_row_stride >= data_row_bytes);
|
assert!(output_row_stride >= data_row_bytes);
|
||||||
assert!(buf.len() >= output_row_stride * (data_dims.1 as usize - 1) + data_row_bytes);
|
assert!(buf.len() >= output_row_stride * (data_dims.1 as usize - 1) + data_row_bytes);
|
||||||
|
|
||||||
let mut reader = self.create_reader(
|
let mut reader = Self::create_reader(
|
||||||
|
self.width,
|
||||||
|
self.height,
|
||||||
reader,
|
reader,
|
||||||
compression_method,
|
compression_method,
|
||||||
*compressed_bytes,
|
*compressed_bytes,
|
||||||
|
|||||||
Reference in new issue
Block a user