jxl_bitstream/
container.rs1mod box_header;
4mod parse;
5
6pub use box_header::*;
7pub use parse::*;
8
9#[derive(Debug, Default)]
11pub struct ContainerParser {
12 state: DetectState,
13 jxlp_index_state: JxlpIndexState,
14 previous_consumed_bytes: usize,
15}
16
17#[derive(Debug, Default)]
18enum DetectState {
19 #[default]
20 WaitingSignature,
21 WaitingBoxHeader,
22 WaitingJxlpIndex(ContainerBoxHeader),
23 InAuxBox {
24 header: ContainerBoxHeader,
25 brotli_box_type: Option<ContainerBoxType>,
26 bytes_left: Option<usize>,
27 },
28 InCodestream {
29 kind: BitstreamKind,
30 bytes_left: Option<usize>,
31 pending_no_more_aux_box: bool,
32 },
33}
34
35#[derive(Debug, Copy, Clone, Eq, PartialEq)]
37pub enum BitstreamKind {
38 Unknown,
40 BareCodestream,
42 Container,
44 Invalid,
46}
47
48#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
49enum JxlpIndexState {
50 #[default]
51 Initial,
52 SingleJxlc,
53 Jxlp(u32),
54 JxlpFinished,
55}
56
57impl ContainerParser {
58 pub fn new() -> Self {
60 Self::default()
61 }
62
63 pub fn kind(&self) -> BitstreamKind {
65 match self.state {
66 DetectState::WaitingSignature => BitstreamKind::Unknown,
67 DetectState::WaitingBoxHeader
68 | DetectState::WaitingJxlpIndex(..)
69 | DetectState::InAuxBox { .. } => BitstreamKind::Container,
70 DetectState::InCodestream { kind, .. } => kind,
71 }
72 }
73
74 pub fn feed_bytes<'inner, 'buf>(
82 &'inner mut self,
83 input: &'buf [u8],
84 ) -> ParseEvents<'inner, 'buf> {
85 ParseEvents::new(self, input)
86 }
87
88 pub fn previous_consumed_bytes(&self) -> usize {
94 self.previous_consumed_bytes
95 }
96}