Skip to main content

mozjpeg/
marker.rs

1use std::os::raw::c_int;
2
3/// Marker number identifier (APP0-APP14 and comment markers)
4///
5/// For actual contents of markers, see `MarkerData`
6#[derive(Copy, Clone, Debug, PartialEq)]
7pub enum Marker {
8    COM,
9    APP(u8),
10}
11
12impl From<u8> for Marker {
13    fn from(num: u8) -> Self {
14        if num == crate::ffi::jpeg_marker::COM as u8 {
15            Self::COM
16        } else {
17            Self::APP(num - crate::ffi::jpeg_marker::APP0 as u8)
18        }
19    }
20}
21
22impl From<Marker> for c_int {
23    fn from(val: Marker) -> Self {
24        match val {
25            Marker::APP(n) => c_int::from(n) + crate::ffi::jpeg_marker::APP0 as c_int,
26            Marker::COM => crate::ffi::jpeg_marker::COM as c_int,
27        }
28    }
29}