Coverage Report

Created: 2025-10-12 08:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/fax-0.2.6/src/decoder.rs
Line
Count
Source
1
use std::convert::Infallible;
2
use std::io::{self, Bytes, Read};
3
4
use crate::{BitReader, ByteReader, Color, Transitions};
5
use crate::maps::{Mode, black, white, mode, EDFB_HALF, EOL};
6
7
8
339k
fn with_markup<D, R>(decoder: D, reader: &mut R) -> Option<u16>
9
339k
    where D: Fn(&mut R) -> Option<u16>
10
{
11
339k
    let mut sum = 0;
12
340k
    while let Some(n) = decoder(reader) {
13
        //print!("{} ", n);
14
340k
        sum += n;
15
340k
        if n < 64 {
16
            //debug!("= {}", sum);
17
339k
            return Some(sum)
18
1.20k
        }
19
    }
20
7
    None
21
339k
}
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<_, _>
fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Line
Count
Source
8
169k
fn with_markup<D, R>(decoder: D, reader: &mut R) -> Option<u16>
9
169k
    where D: Fn(&mut R) -> Option<u16>
10
{
11
169k
    let mut sum = 0;
12
169k
    while let Some(n) = decoder(reader) {
13
        //print!("{} ", n);
14
169k
        sum += n;
15
169k
        if n < 64 {
16
            //debug!("= {}", sum);
17
169k
            return Some(sum)
18
44
        }
19
    }
20
4
    None
21
169k
}
fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Line
Count
Source
8
169k
fn with_markup<D, R>(decoder: D, reader: &mut R) -> Option<u16>
9
169k
    where D: Fn(&mut R) -> Option<u16>
10
{
11
169k
    let mut sum = 0;
12
170k
    while let Some(n) = decoder(reader) {
13
        //print!("{} ", n);
14
170k
        sum += n;
15
170k
        if n < 64 {
16
            //debug!("= {}", sum);
17
169k
            return Some(sum)
18
1.16k
        }
19
    }
20
3
    None
21
169k
}
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::black::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::with_markup::<fax::maps::white::decode<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>, fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
22
23
339k
fn colored(current: Color, reader: &mut impl BitReader) -> Option<u16> {
24
    //debug!("{:?}", current);
25
339k
    match current {
26
169k
        Color::Black => with_markup(black::decode, reader),
27
169k
        Color::White => with_markup(white::decode, reader),
28
    }
29
339k
}
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<_>
fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Line
Count
Source
23
339k
fn colored(current: Color, reader: &mut impl BitReader) -> Option<u16> {
24
    //debug!("{:?}", current);
25
339k
    match current {
26
169k
        Color::Black => with_markup(black::decode, reader),
27
169k
        Color::White => with_markup(white::decode, reader),
28
    }
29
339k
}
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
Unexecuted instantiation: fax::decoder::colored::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>
30
31
/// Turn a list of color changing position into an iterator of pixel colors
32
///
33
/// The width of the line/image has to be given in `width`.
34
/// The iterator will produce exactly that many items.
35
349k
pub fn pels(line: &[u16], width: u16) -> impl Iterator<Item=Color> + '_ {
36
    use std::iter::repeat;
37
349k
    let mut color = Color::White;
38
349k
    let mut last = 0;
39
349k
    let pad_color = if line.len() & 1 == 1 {
40
169k
        !color
41
    } else { 
42
180k
        color
43
    };
44
354k
    line.iter().flat_map(move |&p| {
45
354k
        let c = color;
46
354k
        color = !color;
47
354k
        let n = p.saturating_sub(last);
48
354k
        last = p;
49
354k
        repeat(c).take(n as usize)
50
354k
    }).chain(repeat(pad_color)).take(width as usize)
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
fax::decoder::pels::{closure#0}
Line
Count
Source
44
354k
    line.iter().flat_map(move |&p| {
45
354k
        let c = color;
46
354k
        color = !color;
47
354k
        let n = p.saturating_sub(last);
48
354k
        last = p;
49
354k
        repeat(c).take(n as usize)
50
354k
    }).chain(repeat(pad_color)).take(width as usize)
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
Unexecuted instantiation: fax::decoder::pels::{closure#0}
51
349k
}
52
53
/// Decode a Group 3 encoded image.
54
/// 
55
/// The callback `line_cb` is called for each decoded line.
56
/// The argument is the list of positions of color change, starting with white.
57
/// 
58
/// To obtain an iterator over the pixel colors, the `pels` function is provided.
59
0
pub fn decode_g3(input: impl Iterator<Item=u8>, mut line_cb: impl FnMut(&[u16])) -> Option<()> {
60
0
    let reader = input.map(Result::<u8, Infallible>::Ok);
61
0
    let mut decoder = Group3Decoder::new(reader).ok()?;
62
63
0
    while let Ok(status) = decoder.advance() {
64
0
        if status == DecodeStatus::End {
65
0
            return Some(());
66
0
        }
67
0
        line_cb(decoder.transitions());
68
    }
69
0
    None
70
0
}
71
72
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
73
pub enum DecodeStatus {
74
    Incomplete,
75
    End,
76
}
77
78
pub struct Group3Decoder<R> {
79
    reader: ByteReader<R>,
80
    current: Vec<u16>
81
}
82
impl<E: std::fmt::Debug, R: Iterator<Item=Result<u8, E>>> Group3Decoder<R> {
83
0
    pub fn new(reader: R) -> Result<Self, DecodeError<E>> {
84
0
        let mut reader = ByteReader::new(reader).map_err(DecodeError::Reader)?;
85
0
        reader.expect(EOL).map_err(|_| DecodeError::Invalid)?;
86
87
0
        Ok(Group3Decoder { reader, current: vec![] })
88
0
    }
89
0
    pub fn advance(&mut self) -> Result<DecodeStatus, DecodeError<E>> {
90
0
        self.current.clear();
91
0
        let mut a0 = 0;
92
0
        let mut color = Color::White;
93
0
        while let Some(p) = colored(color, &mut self.reader) {
94
0
            a0 += p;
95
0
            self.current.push(a0);
96
0
            color = !color;
97
0
        }
98
0
        self.reader.expect(EOL).map_err(|_| DecodeError::Invalid)?;
99
100
0
        for _ in 0 .. 6 {
101
0
            if self.reader.peek(EOL.len) == Some(EOL.data) {
102
0
                self.reader.consume(EOL.len).map_err(DecodeError::Reader)?;
103
            } else {
104
0
                return Ok(DecodeStatus::Incomplete)
105
            }
106
        }
107
108
0
        Ok(DecodeStatus::End)
109
0
    }
110
0
    pub fn transitions(&self) -> &[u16] {
111
0
        &self.current
112
0
    }
113
}
114
115
/// Decode a Group 4 Image
116
/// 
117
/// - `width` is the width of the image.
118
/// - The callback `line_cb` is called for each decoded line.
119
///   The argument is the list of positions of color change, starting with white.
120
/// 
121
///   If `height` is specified, at most that many lines will be decoded,
122
///   otherwise data is decoded until the end-of-block marker (or end of data).
123
/// 
124
/// To obtain an iterator over the pixel colors, the `pels` function is provided.
125
0
pub fn decode_g4(input: impl Iterator<Item=u8>, width: u16, height: Option<u16>, mut line_cb: impl FnMut(&[u16])) -> Option<()> {
126
0
    let reader = input.map(Result::<u8, Infallible>::Ok);
127
0
    let mut decoder = Group4Decoder::new(reader, width).ok()?;
128
129
0
    for y in 0 .. height.unwrap_or(u16::MAX) {
130
0
        let status = decoder.advance().ok()?;
131
0
        if status == DecodeStatus::End {
132
0
            return Some(());
133
0
        }
134
0
        line_cb(decoder.transition());
135
    }
136
0
    Some(())
137
0
}
138
139
#[derive(Debug)]
140
pub enum DecodeError<E> {
141
    Reader(E),
142
    Invalid,
143
    Unsupported,
144
}
145
impl<E> std::fmt::Display for DecodeError<E> {
146
0
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
147
0
        write!(f, "Decode Error")
148
0
    }
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<_> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
Unexecuted instantiation: <fax::decoder::DecodeError<std::io::error::Error> as core::fmt::Display>::fmt
149
}
150
impl<E: std::error::Error> std::error::Error for DecodeError<E> {
151
}
152
153
pub struct Group4Decoder<R> {
154
    reader: ByteReader<R>,
155
    reference: Vec<u16>,
156
    current: Vec<u16>,
157
    width: u16
158
}
159
impl<E, R: Iterator<Item=Result<u8, E>>> Group4Decoder<R> {
160
69
    pub fn new(reader: R, width: u16) -> Result<Self, E> {
161
        Ok(Group4Decoder {
162
69
            reader: ByteReader::new(reader)?,
163
69
            reference: Vec::new(),
164
69
            current: Vec::new(),
165
69
            width
166
        })
167
69
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<_>>::new
<fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Line
Count
Source
160
69
    pub fn new(reader: R, width: u16) -> Result<Self, E> {
161
        Ok(Group4Decoder {
162
69
            reader: ByteReader::new(reader)?,
163
69
            reference: Vec::new(),
164
69
            current: Vec::new(),
165
69
            width
166
        })
167
69
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::new
168
    // when Complete::Complete is returned, there is no useful data in .transitions() or .line()
169
349k
    pub fn advance(&mut self) -> Result<DecodeStatus, DecodeError<E>> {
170
349k
        let mut transitions = Transitions::new(&self.reference);
171
349k
        let mut a0 = 0;
172
349k
        let mut color = Color::White;
173
349k
        let mut start_of_row = true;
174
        //debug!("\n\nline {}", y);
175
        
176
        loop {
177
            //reader.print_peek();
178
535k
            let mode = match mode::decode(&mut self.reader) {
179
535k
                Some(mode) => mode,
180
22
                None => return Err(DecodeError::Invalid),
181
            };
182
            //debug!("  {:?}, color={:?}, a0={}", mode, color, a0);
183
            
184
535k
            match mode {
185
                Mode::Pass => {
186
643
                    if start_of_row && color == Color::White {
187
285
                        transitions.pos += 1;
188
285
                    } else {
189
358
                        transitions.next_color(a0, !color, false).ok_or(DecodeError::Invalid)?;
190
                    }
191
                    //debug!("b1={}", b1);
192
638
                    if let Some(b2) = transitions.next() {
193
411
                        //debug!("b2={}", b2);
194
411
                        a0 = b2;
195
411
                    }
196
                }
197
365k
                Mode::Vertical(delta) => {
198
365k
                    let b1 = transitions.next_color(a0, !color, start_of_row).unwrap_or(self.width);
199
365k
                    let a1 = (b1 as i16 + delta as i16) as u16;
200
365k
                    if a1 >= self.width {
201
183k
                        break;
202
181k
                    }
203
                    //debug!("transition to {:?} at {}", !color, a1);
204
181k
                    self.current.push(a1);
205
181k
                    color = !color;
206
181k
                    a0 = a1;
207
181k
                    if delta < 0 {
208
4.41k
                        transitions.seek_back(a0);
209
176k
                    }
210
                }
211
                Mode::Horizontal => {
212
169k
                    let a0a1 = colored(color, &mut self.reader).ok_or(DecodeError::Invalid)?;
213
169k
                    let a1a2 = colored(!color, &mut self.reader).ok_or(DecodeError::Invalid)?;
214
169k
                    let a1 = a0 + a0a1;
215
169k
                    let a2 = a1 + a1a2;
216
                    //debug!("a0a1={}, a1a2={}, a1={}, a2={}", a0a1, a1a2, a1, a2);
217
                    
218
169k
                    self.current.push(a1);
219
169k
                    if a2 >= self.width {
220
165k
                        break;
221
3.74k
                    }
222
3.74k
                    self.current.push(a2);
223
3.74k
                    a0 = a2;
224
                }
225
                Mode::Extension => {
226
4
                    let xxx = self.reader.peek(3).ok_or(DecodeError::Invalid)?;
227
                    // debug!("extension: {:03b}", xxx);
228
4
                    self.reader.consume(3);
229
                    // debug!("{:?}", current);
230
4
                    return Err(DecodeError::Unsupported);
231
                }
232
29
                Mode::EOF => return Ok(DecodeStatus::End),
233
            }
234
185k
            start_of_row = false;
235
236
185k
            if a0 >= self.width {
237
15
                break;
238
185k
            }
239
        }
240
        //debug!("{:?}", current);
241
242
349k
        std::mem::swap(&mut self.reference, &mut self.current);
243
349k
        self.current.clear();
244
245
349k
        Ok(DecodeStatus::Incomplete)
246
349k
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<_>>::advance
<fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Line
Count
Source
169
349k
    pub fn advance(&mut self) -> Result<DecodeStatus, DecodeError<E>> {
170
349k
        let mut transitions = Transitions::new(&self.reference);
171
349k
        let mut a0 = 0;
172
349k
        let mut color = Color::White;
173
349k
        let mut start_of_row = true;
174
        //debug!("\n\nline {}", y);
175
        
176
        loop {
177
            //reader.print_peek();
178
535k
            let mode = match mode::decode(&mut self.reader) {
179
535k
                Some(mode) => mode,
180
22
                None => return Err(DecodeError::Invalid),
181
            };
182
            //debug!("  {:?}, color={:?}, a0={}", mode, color, a0);
183
            
184
535k
            match mode {
185
                Mode::Pass => {
186
643
                    if start_of_row && color == Color::White {
187
285
                        transitions.pos += 1;
188
285
                    } else {
189
358
                        transitions.next_color(a0, !color, false).ok_or(DecodeError::Invalid)?;
190
                    }
191
                    //debug!("b1={}", b1);
192
638
                    if let Some(b2) = transitions.next() {
193
411
                        //debug!("b2={}", b2);
194
411
                        a0 = b2;
195
411
                    }
196
                }
197
365k
                Mode::Vertical(delta) => {
198
365k
                    let b1 = transitions.next_color(a0, !color, start_of_row).unwrap_or(self.width);
199
365k
                    let a1 = (b1 as i16 + delta as i16) as u16;
200
365k
                    if a1 >= self.width {
201
183k
                        break;
202
181k
                    }
203
                    //debug!("transition to {:?} at {}", !color, a1);
204
181k
                    self.current.push(a1);
205
181k
                    color = !color;
206
181k
                    a0 = a1;
207
181k
                    if delta < 0 {
208
4.41k
                        transitions.seek_back(a0);
209
176k
                    }
210
                }
211
                Mode::Horizontal => {
212
169k
                    let a0a1 = colored(color, &mut self.reader).ok_or(DecodeError::Invalid)?;
213
169k
                    let a1a2 = colored(!color, &mut self.reader).ok_or(DecodeError::Invalid)?;
214
169k
                    let a1 = a0 + a0a1;
215
169k
                    let a2 = a1 + a1a2;
216
                    //debug!("a0a1={}, a1a2={}, a1={}, a2={}", a0a1, a1a2, a1, a2);
217
                    
218
169k
                    self.current.push(a1);
219
169k
                    if a2 >= self.width {
220
165k
                        break;
221
3.74k
                    }
222
3.74k
                    self.current.push(a2);
223
3.74k
                    a0 = a2;
224
                }
225
                Mode::Extension => {
226
4
                    let xxx = self.reader.peek(3).ok_or(DecodeError::Invalid)?;
227
                    // debug!("extension: {:03b}", xxx);
228
4
                    self.reader.consume(3);
229
                    // debug!("{:?}", current);
230
4
                    return Err(DecodeError::Unsupported);
231
                }
232
29
                Mode::EOF => return Ok(DecodeStatus::End),
233
            }
234
185k
            start_of_row = false;
235
236
185k
            if a0 >= self.width {
237
15
                break;
238
185k
            }
239
        }
240
        //debug!("{:?}", current);
241
242
349k
        std::mem::swap(&mut self.reference, &mut self.current);
243
349k
        self.current.clear();
244
245
349k
        Ok(DecodeStatus::Incomplete)
246
349k
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::advance
247
248
349k
    pub fn transition(&self) -> &[u16] {
249
349k
        &self.reference
250
349k
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<_>>::transition
<fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Line
Count
Source
248
349k
    pub fn transition(&self) -> &[u16] {
249
349k
        &self.reference
250
349k
    }
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
Unexecuted instantiation: <fax::decoder::Group4Decoder<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>>::transition
251
252
0
    pub fn line(&self) -> Line {
253
0
        Line { transitions: &self.reference, width: self.width }
254
0
    }
255
}
256
257
pub struct Line<'a> {
258
    pub transitions: &'a [u16],
259
    pub width: u16
260
}
261
impl<'a> Line<'a> {
262
0
    pub fn pels(&self) -> impl Iterator<Item = Color> + 'a {
263
0
        pels(&self.transitions, self.width)
264
0
    }
265
}