Skip to content

Commit

Permalink
Allow non standard scan encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
vstroebel committed Feb 22, 2022
1 parent 21b3e4b commit 0798b14
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,28 @@ impl<R: Read> Reader<R> {
})
}

#[allow(clippy::same_item_push)]
fn read_scan_data(&mut self) -> Result<Vec<u8>, JfifError> {
let mut data = vec![];

loop {
let byte = self.read_u8()?;
if byte == 0xFF {
let byte = self.read_u8()?;
let mut byte = self.read_u8()?;
let mut ff_count = 1;
// Multiple 0xFF are not standard compliant but supported by libjepeg
while byte == 0xFF {
ff_count += 1;
byte = self.read_u8()?;
}

if byte != 0x00 {
self.current_marker = Some(byte);
break;
} else {
data.push(0xFF);
for _ in [0..ff_count] {
data.push(0xFF);
}
data.push(byte);
}
} else {
Expand Down

0 comments on commit 0798b14

Please sign in to comment.