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