| 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 |
/// JPEG Markers |
| 12 |
/// |
| 13 |
/// **NOTE** This doesn't cover all markers, just the ones zune-jpeg supports. |
| 14 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 15 |
pub enum Marker { |
| 16 |
/// Start Of Frame markers |
| 17 |
/// |
| 18 |
/// - SOF(0): Baseline DCT (Huffman coding) |
| 19 |
/// - SOF(1): Extended sequential DCT (Huffman coding) |
| 20 |
/// - SOF(2): Progressive DCT (Huffman coding) |
| 21 |
/// - SOF(3): Lossless (sequential) (Huffman coding) |
| 22 |
/// - SOF(5): Differential sequential DCT (Huffman coding) |
| 23 |
/// - SOF(6): Differential progressive DCT (Huffman coding) |
| 24 |
/// - SOF(7): Differential lossless (sequential) (Huffman coding) |
| 25 |
/// - SOF(9): Extended sequential DCT (arithmetic coding) |
| 26 |
/// - SOF(10): Progressive DCT (arithmetic coding) |
| 27 |
/// - SOF(11): Lossless (sequential) (arithmetic coding) |
| 28 |
/// - SOF(13): Differential sequential DCT (arithmetic coding) |
| 29 |
/// - SOF(14): Differential progressive DCT (arithmetic coding) |
| 30 |
/// - SOF(15): Differential lossless (sequential) (arithmetic coding) |
| 31 |
SOF(u8), |
| 32 |
/// Define Huffman table(s) |
| 33 |
DHT, |
| 34 |
/// Define arithmetic coding conditioning(s) |
| 35 |
DAC, |
| 36 |
/// Restart with modulo 8 count `m` |
| 37 |
RST(u8), |
| 38 |
/// Start of image |
| 39 |
SOI, |
| 40 |
/// End of image |
| 41 |
EOI, |
| 42 |
/// Start of scan |
| 43 |
SOS, |
| 44 |
/// Define quantization table(s) |
| 45 |
DQT, |
| 46 |
/// Define number of lines |
| 47 |
DNL, |
| 48 |
/// Define restart interval |
| 49 |
DRI, |
| 50 |
/// Reserved for application segments |
| 51 |
APP(u8), |
| 52 |
/// Comment |
| 53 |
COM, |
| 54 |
/// Unknown markers |
| 55 |
UNKNOWN(u8) |
| 56 |
} |
| 57 |
|
| 58 |
impl Marker { |
| 59 |
pub fn from_u8(n: u8) -> Option<Marker> { |
| 60 |
use self::Marker::{APP, COM, DAC, DHT, DNL, DQT, DRI, EOI, RST, SOF, SOI, SOS, UNKNOWN}; |
| 61 |
|
| 62 |
match n { |
| 63 |
0xFE => Some(COM), |
| 64 |
0xC0 => Some(SOF(0)), |
| 65 |
0xC1 => Some(SOF(1)), |
| 66 |
0xC2 => Some(SOF(2)), |
| 67 |
0xC4 => Some(DHT), |
| 68 |
0xCC => Some(DAC), |
| 69 |
0xD0 => Some(RST(0)), |
| 70 |
0xD1 => Some(RST(1)), |
| 71 |
0xD2 => Some(RST(2)), |
| 72 |
0xD3 => Some(RST(3)), |
| 73 |
0xD4 => Some(RST(4)), |
| 74 |
0xD5 => Some(RST(5)), |
| 75 |
0xD6 => Some(RST(6)), |
| 76 |
0xD7 => Some(RST(7)), |
| 77 |
0xD8 => Some(SOI), |
| 78 |
0xD9 => Some(EOI), |
| 79 |
0xDA => Some(SOS), |
| 80 |
0xDB => Some(DQT), |
| 81 |
0xDC => Some(DNL), |
| 82 |
0xDD => Some(DRI), |
| 83 |
0xE0 => Some(APP(0)), |
| 84 |
0xE1 => Some(APP(1)), |
| 85 |
0xE2 => Some(APP(2)), |
| 86 |
0xED => Some(APP(13)), |
| 87 |
0xEE => Some(APP(14)), |
| 88 |
_ => Some(UNKNOWN(n)) |
| 89 |
} |
| 90 |
} |
| 91 |
} |