| 1 | // Table B.1 |
| 2 | #[derive (Clone, Copy, Debug, PartialEq)] |
| 3 | // Note: Established names. |
| 4 | #[allow (clippy::upper_case_acronyms)] |
| 5 | pub enum Marker { |
| 6 | /// Start Of Frame markers |
| 7 | /// |
| 8 | /// - SOF(0): Baseline DCT (Huffman coding) |
| 9 | /// - SOF(1): Extended sequential DCT (Huffman coding) |
| 10 | /// - SOF(2): Progressive DCT (Huffman coding) |
| 11 | /// - SOF(3): Lossless (sequential) (Huffman coding) |
| 12 | /// - SOF(5): Differential sequential DCT (Huffman coding) |
| 13 | /// - SOF(6): Differential progressive DCT (Huffman coding) |
| 14 | /// - SOF(7): Differential lossless (sequential) (Huffman coding) |
| 15 | /// - SOF(9): Extended sequential DCT (arithmetic coding) |
| 16 | /// - SOF(10): Progressive DCT (arithmetic coding) |
| 17 | /// - SOF(11): Lossless (sequential) (arithmetic coding) |
| 18 | /// - SOF(13): Differential sequential DCT (arithmetic coding) |
| 19 | /// - SOF(14): Differential progressive DCT (arithmetic coding) |
| 20 | /// - SOF(15): Differential lossless (sequential) (arithmetic coding) |
| 21 | SOF(u8), |
| 22 | /// Reserved for JPEG extensions |
| 23 | JPG, |
| 24 | /// Define Huffman table(s) |
| 25 | DHT, |
| 26 | /// Define arithmetic coding conditioning(s) |
| 27 | DAC, |
| 28 | /// Restart with modulo 8 count `m` |
| 29 | RST(u8), |
| 30 | /// Start of image |
| 31 | SOI, |
| 32 | /// End of image |
| 33 | EOI, |
| 34 | /// Start of scan |
| 35 | SOS, |
| 36 | /// Define quantization table(s) |
| 37 | DQT, |
| 38 | /// Define number of lines |
| 39 | DNL, |
| 40 | /// Define restart interval |
| 41 | DRI, |
| 42 | /// Define hierarchical progression |
| 43 | DHP, |
| 44 | /// Expand reference component(s) |
| 45 | EXP, |
| 46 | /// Reserved for application segments |
| 47 | APP(u8), |
| 48 | /// Reserved for JPEG extensions |
| 49 | JPGn(u8), |
| 50 | /// Comment |
| 51 | COM, |
| 52 | /// For temporary private use in arithmetic coding |
| 53 | TEM, |
| 54 | /// Reserved |
| 55 | RES, |
| 56 | } |
| 57 | |
| 58 | impl Marker { |
| 59 | pub fn has_length(self) -> bool { |
| 60 | use self::Marker::*; |
| 61 | ! matches!(self, RST(..) | SOI | EOI | TEM) |
| 62 | } |
| 63 | |
| 64 | pub fn from_u8(n: u8) -> Option<Marker> { |
| 65 | use self::Marker::*; |
| 66 | match n { |
| 67 | 0x00 => None, // Byte stuffing |
| 68 | 0x01 => Some(TEM), |
| 69 | 0x02 ..= 0xBF => Some(RES), |
| 70 | 0xC0 => Some(SOF(0)), |
| 71 | 0xC1 => Some(SOF(1)), |
| 72 | 0xC2 => Some(SOF(2)), |
| 73 | 0xC3 => Some(SOF(3)), |
| 74 | 0xC4 => Some(DHT), |
| 75 | 0xC5 => Some(SOF(5)), |
| 76 | 0xC6 => Some(SOF(6)), |
| 77 | 0xC7 => Some(SOF(7)), |
| 78 | 0xC8 => Some(JPG), |
| 79 | 0xC9 => Some(SOF(9)), |
| 80 | 0xCA => Some(SOF(10)), |
| 81 | 0xCB => Some(SOF(11)), |
| 82 | 0xCC => Some(DAC), |
| 83 | 0xCD => Some(SOF(13)), |
| 84 | 0xCE => Some(SOF(14)), |
| 85 | 0xCF => Some(SOF(15)), |
| 86 | 0xD0 => Some(RST(0)), |
| 87 | 0xD1 => Some(RST(1)), |
| 88 | 0xD2 => Some(RST(2)), |
| 89 | 0xD3 => Some(RST(3)), |
| 90 | 0xD4 => Some(RST(4)), |
| 91 | 0xD5 => Some(RST(5)), |
| 92 | 0xD6 => Some(RST(6)), |
| 93 | 0xD7 => Some(RST(7)), |
| 94 | 0xD8 => Some(SOI), |
| 95 | 0xD9 => Some(EOI), |
| 96 | 0xDA => Some(SOS), |
| 97 | 0xDB => Some(DQT), |
| 98 | 0xDC => Some(DNL), |
| 99 | 0xDD => Some(DRI), |
| 100 | 0xDE => Some(DHP), |
| 101 | 0xDF => Some(EXP), |
| 102 | 0xE0 => Some(APP(0)), |
| 103 | 0xE1 => Some(APP(1)), |
| 104 | 0xE2 => Some(APP(2)), |
| 105 | 0xE3 => Some(APP(3)), |
| 106 | 0xE4 => Some(APP(4)), |
| 107 | 0xE5 => Some(APP(5)), |
| 108 | 0xE6 => Some(APP(6)), |
| 109 | 0xE7 => Some(APP(7)), |
| 110 | 0xE8 => Some(APP(8)), |
| 111 | 0xE9 => Some(APP(9)), |
| 112 | 0xEA => Some(APP(10)), |
| 113 | 0xEB => Some(APP(11)), |
| 114 | 0xEC => Some(APP(12)), |
| 115 | 0xED => Some(APP(13)), |
| 116 | 0xEE => Some(APP(14)), |
| 117 | 0xEF => Some(APP(15)), |
| 118 | 0xF0 => Some(JPGn(0)), |
| 119 | 0xF1 => Some(JPGn(1)), |
| 120 | 0xF2 => Some(JPGn(2)), |
| 121 | 0xF3 => Some(JPGn(3)), |
| 122 | 0xF4 => Some(JPGn(4)), |
| 123 | 0xF5 => Some(JPGn(5)), |
| 124 | 0xF6 => Some(JPGn(6)), |
| 125 | 0xF7 => Some(JPGn(7)), |
| 126 | 0xF8 => Some(JPGn(8)), |
| 127 | 0xF9 => Some(JPGn(9)), |
| 128 | 0xFA => Some(JPGn(10)), |
| 129 | 0xFB => Some(JPGn(11)), |
| 130 | 0xFC => Some(JPGn(12)), |
| 131 | 0xFD => Some(JPGn(13)), |
| 132 | 0xFE => Some(COM), |
| 133 | 0xFF => None, // Fill byte |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |