1macro_rules! tags {
2 {
3 $( #[$enum_attr:meta] )*
5 $vis:vis enum $name:ident($ty:tt) $(unknown($unknown_doc:literal))* {
6 $($(#[$ident_attr:meta])* $tag:ident = $val:expr,)*
8 }
9 } => {
10 $( #[$enum_attr] )*
11 #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
12 #[non_exhaustive]
13 pub enum $name {
14 $($(#[$ident_attr])* $tag,)*
15 $(
16 #[doc = $unknown_doc]
17 Unknown($ty),
18 )*
19 }
20
21 impl $name {
22 #[inline(always)]
23 fn __from_inner_type(n: $ty) -> Result<Self, $ty> {
24 match n {
25 $( $val => Ok($name::$tag), )*
26 n => Err(n),
27 }
28 }
29
30 #[inline(always)]
31 fn __to_inner_type(&self) -> $ty {
32 match *self {
33 $( $name::$tag => $val, )*
34 $( $name::Unknown(n) => { $unknown_doc; n }, )*
35 }
36 }
37 }
38
39 tags!($name, $ty, $($unknown_doc)*);
40 };
41 ($name:tt, u16, $($unknown_doc:literal)*) => {
43 impl $name {
44 #[inline(always)]
45 pub fn from_u16(val: u16) -> Option<Self> {
46 Self::__from_inner_type(val).ok()
47 }
48
49 $(
50 #[inline(always)]
51 pub fn from_u16_exhaustive(val: u16) -> Self {
52 $unknown_doc;
53 Self::__from_inner_type(val).unwrap_or_else(|_| $name::Unknown(val))
54 }
55 )*
56
57 #[inline(always)]
58 pub fn to_u16(&self) -> u16 {
59 Self::__to_inner_type(self)
60 }
61 }
62 };
63 ($name:tt, $ty:tt, $($unknown_doc:literal)*) => {};
66}
67
68tags! {
70pub enum Tag(u16) unknown("A private or extension tag") {
72 Artist = 315,
74 BitsPerSample = 258,
76 CellLength = 265, CellWidth = 264, ColorMap = 320, Compression = 259, Copyright = 33_432,
82 DateTime = 306,
83 ExtraSamples = 338, FillOrder = 266, FreeByteCounts = 289, FreeOffsets = 288, GrayResponseCurve = 291, GrayResponseUnit = 290, HostComputer = 316,
90 ImageDescription = 270,
91 ImageLength = 257,
92 ImageWidth = 256,
93 Make = 271,
94 MaxSampleValue = 281, MinSampleValue = 280, Model = 272,
97 NewSubfileType = 254, Orientation = 274, PhotometricInterpretation = 262,
100 PlanarConfiguration = 284,
101 ResolutionUnit = 296, RowsPerStrip = 278,
103 SamplesPerPixel = 277,
104 Software = 305,
105 StripByteCounts = 279,
106 StripOffsets = 273,
107 SubfileType = 255, Threshholding = 263, XResolution = 282,
110 YResolution = 283,
111 Predictor = 317,
113 TileWidth = 322,
114 TileLength = 323,
115 TileOffsets = 324,
116 TileByteCounts = 325,
117 SampleFormat = 339,
119 SMinSampleValue = 340, SMaxSampleValue = 341, JPEGTables = 347,
123 ModelPixelScaleTag = 33550, ModelTransformationTag = 34264, ModelTiepointTag = 33922, GeoKeyDirectoryTag = 34735, GeoDoubleParamsTag = 34736, GeoAsciiParamsTag = 34737, GdalNodata = 42113, }
132}
133
134tags! {
135pub enum Type(u16) {
137 BYTE = 1,
139 ASCII = 2,
141 SHORT = 3,
143 LONG = 4,
145 RATIONAL = 5,
147 SBYTE = 6,
149 UNDEFINED = 7,
151 SSHORT = 8,
153 SLONG = 9,
155 SRATIONAL = 10,
157 FLOAT = 11,
159 DOUBLE = 12,
161 IFD = 13,
163 LONG8 = 16,
165 SLONG8 = 17,
167 IFD8 = 18,
169}
170}
171
172tags! {
173pub enum CompressionMethod(u16) unknown("A custom compression method") {
176 None = 1,
177 Huffman = 2,
178 Fax3 = 3,
179 Fax4 = 4,
180 LZW = 5,
181 JPEG = 6,
182 ModernJPEG = 7,
184 Deflate = 8,
185 OldDeflate = 0x80B2,
186 PackBits = 0x8005,
187}
188}
189
190tags! {
191pub enum PhotometricInterpretation(u16) {
192 WhiteIsZero = 0,
193 BlackIsZero = 1,
194 RGB = 2,
195 RGBPalette = 3,
196 TransparencyMask = 4,
197 CMYK = 5,
198 YCbCr = 6,
199 CIELab = 8,
200}
201}
202
203tags! {
204pub enum PlanarConfiguration(u16) {
205 Chunky = 1,
206 Planar = 2,
207}
208}
209
210tags! {
211pub enum Predictor(u16) {
212 None = 1,
213 Horizontal = 2,
214 FloatingPoint = 3,
215}
216}
217
218tags! {
219pub enum ResolutionUnit(u16) {
221 None = 1,
222 Inch = 2,
223 Centimeter = 3,
224}
225}
226
227tags! {
228pub enum SampleFormat(u16) unknown("An unknown extension sample format") {
229 Uint = 1,
230 Int = 2,
231 IEEEFP = 3,
232 Void = 4,
233}
234}