pub struct Encoder<W> { /* private fields */ }
Implementations§
source§impl<W: BitWriter> Encoder<W>
impl<W: BitWriter> Encoder<W>
sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Examples found in repository?
examples/pbm2fax.rs (line 17)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let writer = VecWriter::new();
let mut encoder = Encoder::new(writer);
for line in parts.next().unwrap().chunks((width as usize + 7) / 8).take(height as _) {
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::White,
true => Color::Black
});
encoder.encode_line(line, width as u16).unwrap();
}
let data = encoder.finish().unwrap().finish();
fs::write(&output, &tiff::wrap(&data, width, height)).unwrap();
}
More examples
examples/validate.rs (line 19)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let reference_data = fs::read(&output).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
//let writer = VecWriter::new();
let writer = Validator { reader: slice_reader(&reference_data) };
let mut encoder = Encoder::new(writer);
for (y, line) in parts.next().unwrap().chunks((width as usize + 7) / 8).enumerate().take(height as _) {
println!("\nline {}", y);
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::Black,
true => Color::White
});
encoder.encode_line(line, width).unwrap();
}
let mut writer = encoder.finish().unwrap();
writer.reader.print_remaining();
//let (data, _) = encoder.into_writer().finish();
//fs::write(&output, &data).unwrap();
}
sourcepub fn encode_line(
&mut self,
pels: impl Iterator<Item = Color>,
width: u16
) -> Result<(), W::Error>
pub fn encode_line( &mut self, pels: impl Iterator<Item = Color>, width: u16 ) -> Result<(), W::Error>
Examples found in repository?
examples/pbm2fax.rs (line 25)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let writer = VecWriter::new();
let mut encoder = Encoder::new(writer);
for line in parts.next().unwrap().chunks((width as usize + 7) / 8).take(height as _) {
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::White,
true => Color::Black
});
encoder.encode_line(line, width as u16).unwrap();
}
let data = encoder.finish().unwrap().finish();
fs::write(&output, &tiff::wrap(&data, width, height)).unwrap();
}
More examples
examples/validate.rs (line 28)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let reference_data = fs::read(&output).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
//let writer = VecWriter::new();
let writer = Validator { reader: slice_reader(&reference_data) };
let mut encoder = Encoder::new(writer);
for (y, line) in parts.next().unwrap().chunks((width as usize + 7) / 8).enumerate().take(height as _) {
println!("\nline {}", y);
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::Black,
true => Color::White
});
encoder.encode_line(line, width).unwrap();
}
let mut writer = encoder.finish().unwrap();
writer.reader.print_remaining();
//let (data, _) = encoder.into_writer().finish();
//fs::write(&output, &data).unwrap();
}
sourcepub fn finish(self) -> Result<W, W::Error>
pub fn finish(self) -> Result<W, W::Error>
Examples found in repository?
examples/pbm2fax.rs (line 27)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u32 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let writer = VecWriter::new();
let mut encoder = Encoder::new(writer);
for line in parts.next().unwrap().chunks((width as usize + 7) / 8).take(height as _) {
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::White,
true => Color::Black
});
encoder.encode_line(line, width as u16).unwrap();
}
let data = encoder.finish().unwrap().finish();
fs::write(&output, &tiff::wrap(&data, width, height)).unwrap();
}
More examples
examples/validate.rs (line 30)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let mut args = std::env::args().skip(1);
let input: String = args.next().unwrap();
let output = args.next().unwrap();
let data = fs::read(&input).unwrap();
let reference_data = fs::read(&output).unwrap();
let mut parts = data.splitn(3, |&b| b == b'\n');
assert_eq!(parts.next().unwrap(), b"P4");
let mut size = parts.next().unwrap().splitn(2, |&b| b == b' ');
let width: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
let height: u16 = std::str::from_utf8(size.next().unwrap()).unwrap().parse().unwrap();
//let writer = VecWriter::new();
let writer = Validator { reader: slice_reader(&reference_data) };
let mut encoder = Encoder::new(writer);
for (y, line) in parts.next().unwrap().chunks((width as usize + 7) / 8).enumerate().take(height as _) {
println!("\nline {}", y);
let line = slice_bits(line).take(width as usize)
.map(|b| match b {
false => Color::Black,
true => Color::White
});
encoder.encode_line(line, width).unwrap();
}
let mut writer = encoder.finish().unwrap();
writer.reader.print_remaining();
//let (data, _) = encoder.into_writer().finish();
//fs::write(&output, &data).unwrap();
}
Auto Trait Implementations§
impl<W> Freeze for Encoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for Encoder<W>where
W: RefUnwindSafe,
impl<W> Send for Encoder<W>where
W: Send,
impl<W> Sync for Encoder<W>where
W: Sync,
impl<W> Unpin for Encoder<W>where
W: Unpin,
impl<W> UnwindSafe for Encoder<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more