zune_jpeg/marker.rs
1/*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9#![allow(clippy::upper_case_acronyms)]
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq)]
12pub enum Marker {
13 /// Start Of Frame markers
14 ///
15 /// - SOF(0): Baseline DCT (Huffman coding)
16 /// - SOF(1): Extended sequential DCT (Huffman coding)
17 /// - SOF(2): Progressive DCT (Huffman coding)
18 /// - SOF(3): Lossless (sequential) (Huffman coding)
19 /// - SOF(5): Differential sequential DCT (Huffman coding)
20 /// - SOF(6): Differential progressive DCT (Huffman coding)
21 /// - SOF(7): Differential lossless (sequential) (Huffman coding)
22 /// - SOF(9): Extended sequential DCT (arithmetic coding)
23 /// - SOF(10): Progressive DCT (arithmetic coding)
24 /// - SOF(11): Lossless (sequential) (arithmetic coding)
25 /// - SOF(13): Differential sequential DCT (arithmetic coding)
26 /// - SOF(14): Differential progressive DCT (arithmetic coding)
27 /// - SOF(15): Differential lossless (sequential) (arithmetic coding)
28 SOF(u8),
29 /// Define Huffman table(s)
30 DHT,
31 /// Define arithmetic coding conditioning(s)
32 DAC,
33 /// Restart with modulo 8 count `m`
34 RST(u8),
35 /// Start of image
36 SOI,
37 /// End of image
38 EOI,
39 /// Start of scan
40 SOS,
41 /// Define quantization table(s)
42 DQT,
43 /// Define number of lines
44 DNL,
45 /// Define restart interval
46 DRI,
47 /// Reserved for application segments
48 APP(u8),
49 /// Comment
50 COM
51}
52
53impl Marker {
54 pub fn from_u8(n: u8) -> Option<Marker> {
55 use self::Marker::{APP, COM, DAC, DHT, DNL, DQT, DRI, EOI, RST, SOF, SOI, SOS};
56
57 match n {
58 0xFE => Some(COM),
59 0xC0 => Some(SOF(0)),
60 0xC1 => Some(SOF(1)),
61 0xC2 => Some(SOF(2)),
62 0xC4 => Some(DHT),
63 0xCC => Some(DAC),
64 0xD0 => Some(RST(0)),
65 0xD1 => Some(RST(1)),
66 0xD2 => Some(RST(2)),
67 0xD3 => Some(RST(3)),
68 0xD4 => Some(RST(4)),
69 0xD5 => Some(RST(5)),
70 0xD6 => Some(RST(6)),
71 0xD7 => Some(RST(7)),
72 0xD8 => Some(SOI),
73 0xD9 => Some(EOI),
74 0xDA => Some(SOS),
75 0xDB => Some(DQT),
76 0xDC => Some(DNL),
77 0xDD => Some(DRI),
78 0xE0 => Some(APP(0)),
79 0xE1 => Some(APP(1)),
80 0xE2 => Some(APP(2)),
81 0xEE => Some(APP(14)),
82 _ => None
83 }
84 }
85}