bit-addressable output (doesn't work yet)
This commit is contained in:
1 parent
c1087f6f08
commit
c75aa98ce2
2 files changed
+25
-15
No files matched your search
@@ -25,6 +25,7 @@ flate2 = { version = "1.0.20", optional = true }
|
|||||||
weezl = { version = "0.1.10", optional = true }
|
weezl = { version = "0.1.10", optional = true }
|
||||||
zstd = { version = "0.13", optional = true }
|
zstd = { version = "0.13", optional = true }
|
||||||
zune-jpeg = { version = "0.4.17", optional = true }
|
zune-jpeg = { version = "0.4.17", optional = true }
|
||||||
|
bitvec = "1.0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3.1"
|
criterion = "0.3.1"
|
||||||
|
|||||||
+24
-15
@@ -12,7 +12,6 @@ use crate::{
|
|||||||
|
|
||||||
#[cfg(feature = "fax")]
|
#[cfg(feature = "fax")]
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use std::io::{self, Cursor, Read, Seek};
|
use std::io::{self, Cursor, Read, Seek};
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -465,7 +464,8 @@ impl Image {
|
|||||||
|
|
||||||
struct Group4Reader<R2> {
|
struct Group4Reader<R2> {
|
||||||
decoder: fax::decoder::Group4Decoder<std::io::Bytes<R2>>,
|
decoder: fax::decoder::Group4Decoder<std::io::Bytes<R2>>,
|
||||||
line_buf: VecDeque<u8>,
|
bits: bitvec::vec::BitVec<u8, bitvec::prelude::Msb0>,
|
||||||
|
byte_buf: VecDeque<u8>,
|
||||||
y: u16,
|
y: u16,
|
||||||
height: u16,
|
height: u16,
|
||||||
width: u16,
|
width: u16,
|
||||||
@@ -473,30 +473,38 @@ impl Image {
|
|||||||
|
|
||||||
impl<R2: Read> Read for Group4Reader<R2> {
|
impl<R2: Read> Read for Group4Reader<R2> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
if self.line_buf.is_empty() && self.y < self.height {
|
if self.byte_buf.is_empty() && self.y < self.height {
|
||||||
let next = self
|
let next = self
|
||||||
.decoder
|
.decoder
|
||||||
.advance()
|
.advance()
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
||||||
|
|
||||||
match next {
|
match next {
|
||||||
fax::decoder::DecodeStatus::End => (),
|
fax::decoder::DecodeStatus::End => {
|
||||||
|
// eprintln!("DONE!");
|
||||||
|
self.byte_buf.extend(self.bits.as_raw_slice())
|
||||||
|
}
|
||||||
fax::decoder::DecodeStatus::Incomplete => {
|
fax::decoder::DecodeStatus::Incomplete => {
|
||||||
self.y += 1;
|
self.y += 1;
|
||||||
self.line_buf.extend(
|
// eprintln!("{:?}", self.y);
|
||||||
// all extant tiff/fax4 decoders I've found always assume that the photometric interpretation
|
for c in
|
||||||
// is `WhiteIsZero`, ignoring the tag. ImageMagick appears to generate fax4-encoded tiffs
|
|
||||||
// with the tag incorrectly set to `BlackIsZero`.
|
|
||||||
fax::decoder::pels(self.decoder.transition(), self.width)
|
fax::decoder::pels(self.decoder.transition(), self.width)
|
||||||
.map(|c| match c {
|
{
|
||||||
fax::Color::Black => 255,
|
self.bits.push(match c {
|
||||||
fax::Color::White => 0,
|
fax::Color::Black => true,
|
||||||
}),
|
fax::Color::White => false,
|
||||||
);
|
});
|
||||||
|
if self.bits.len() == 8 {
|
||||||
|
self.byte_buf.extend(self.bits.as_raw_slice());
|
||||||
|
self.bits.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.line_buf.read(buf)
|
// eprintln!("{:?}: {:?} / {:?}", self.y, self.byte_buf.len(), self.bits.len());
|
||||||
|
|
||||||
|
self.byte_buf.read(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +513,8 @@ impl Image {
|
|||||||
reader.take(compressed_length).bytes(),
|
reader.take(compressed_length).bytes(),
|
||||||
width,
|
width,
|
||||||
)?,
|
)?,
|
||||||
line_buf: VecDeque::with_capacity(usize::from(width)),
|
bits: bitvec::vec::BitVec::new(),
|
||||||
|
byte_buf: VecDeque::new(),
|
||||||
y: 0,
|
y: 0,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
|
|||||||
Reference in new issue
Block a user