// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // // Originally written for jxl-oxide.
/// Structure of the decoded bitstream. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pubenum BitstreamKind { /// Decoder can't determine structure of the bitstream.
Unknown, /// Bitstream is a direct JPEG XL codestream without box structure.
BareCodestream, /// Bitstream is a JPEG XL container with box structure.
Container, /// Bitstream is not a valid JPEG XL image.
Invalid,
}
/// Parses input buffer and generates parser events. /// /// The parser might not fully consume the buffer. Use [`previous_consumed_bytes`] to get how /// many bytes are consumed. Bytes not consumed by the parser should be processed again. /// /// [`previous_consumed_bytes`]: ContainerParser::previous_consumed_bytes pubfn process_bytes<'inner, 'buf>(
&'inner mut self,
input: &'buf [u8],
) -> ParseEvents<'inner, 'buf> {
ParseEvents::new(self, input)
}
/// Get how many bytes are consumed by the previous call to [`process_bytes`]. /// /// Bytes not consumed by the parser should be processed again. /// /// [`process_bytes`]: ContainerParser::process_bytes pubfn previous_consumed_bytes(&self) -> usize { self.previous_consumed_bytes
}
}
// Create a list of arbitrary splits. letmut tests = Vec::new();
u.arbitrary_loop(Some(1), Some(10), |u| { let split_at_idx = u.choose_index(container.len())?;
tests.push(container.split_at(split_at_idx));
Ok(std::ops::ControlFlow::Continue(()))
})?;
// Test if split index doesn't affect final codestream. for (first, second) in tests { letmut codestream = Vec::new(); letmut parser = ContainerParser::new();
for event in parser.process_bytes(first) { let event = event.unwrap(); iflet ParseEvent::Codestream(data) = event {
codestream.extend_from_slice(data);
}
}
let consumed = parser.previous_consumed_bytes(); letmut second_chunk = first[consumed..].to_vec();
second_chunk.extend_from_slice(second);
for event in parser.process_bytes(&second_chunk) { let event = event.unwrap(); iflet ParseEvent::Codestream(data) = event {
codestream.extend_from_slice(data);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.