macro_rules! tags {
{
$( #[$enum_attr:meta] )*
$vis:vis enum $name:ident($ty:tt) $(unknown(#[$unknown_meta:meta] $unknown_doc:ident))* {
$($(#[$ident_attr:meta])* $tag:ident = $val:expr,)*
}
} => {
$( #[$enum_attr] )*
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
#[non_exhaustive]
pub enum $name {
$($(#[$ident_attr])* $tag,)*
$(
#[$unknown_meta]
Unknown($ty),
)*
}
impl $name {
#[inline(always)]
fn __from_inner_type(n: $ty) -> Result<Self, $ty> {
match n {
$( $val => Ok($name::$tag), )*
n => Err(n),
}
}
#[inline(always)]
fn __to_inner_type(&self) -> $ty {
match *self {
$( $name::$tag => $val, )*
$( $name::Unknown($unknown_doc) => { $unknown_doc }, )*
}
}
}
tags!($name, $ty, $($unknown_doc)*);
};
($name:tt, u16, $($unknown_doc:ident)*) => {
impl $name {
#[inline(always)]
pub fn from_u16(val: u16) -> Option<Self> {
Self::__from_inner_type(val).ok()
}
$(
#[inline(always)]
pub fn from_u16_exhaustive($unknown_doc: u16) -> Self {
Self::__from_inner_type($unknown_doc).unwrap_or_else(|_| $name::Unknown($unknown_doc))
}
)*
#[inline(always)]
pub fn to_u16(&self) -> u16 {
Self::__to_inner_type(self)
}
}
};
($name:tt, $ty:tt, $($unknown_doc:literal)*) => {};
}
tags! {
pub enum Tag(u16) unknown(
unknown
) {
Artist = 315,
BitsPerSample = 258,
CellLength = 265, CellWidth = 264, ColorMap = 320, Compression = 259, DateTime = 306,
ExtraSamples = 338, FillOrder = 266, FreeByteCounts = 289, FreeOffsets = 288, GrayResponseCurve = 291, GrayResponseUnit = 290, HostComputer = 316,
ImageDescription = 270,
ImageLength = 257,
ImageWidth = 256,
Make = 271,
MaxSampleValue = 281, MinSampleValue = 280, Model = 272,
NewSubfileType = 254, Orientation = 274, PhotometricInterpretation = 262,
PlanarConfiguration = 284,
ResolutionUnit = 296, RowsPerStrip = 278,
SamplesPerPixel = 277,
Software = 305,
StripByteCounts = 279,
StripOffsets = 273,
SubfileType = 255, Threshholding = 263, XResolution = 282,
YResolution = 283,
Predictor = 317,
TileWidth = 322,
TileLength = 323,
TileOffsets = 324,
TileByteCounts = 325,
SubIfd = 330,
SampleFormat = 339,
SMinSampleValue = 340, SMaxSampleValue = 341, JPEGTables = 347,
ModelPixelScaleTag = 33550, ModelTransformationTag = 34264, ModelTiepointTag = 33922, Copyright = 33_432,
ExifDirectory = 0x8769,
GpsDirectory = 0x8825,
IccProfile = 34675,
GeoKeyDirectoryTag = 34735, GeoDoubleParamsTag = 34736, GeoAsciiParamsTag = 34737, ExifVersion = 0x9000,
GdalNodata = 42113, }
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub struct IfdPointer(pub u64);
tags! {
pub enum Type(u16) {
BYTE = 1,
ASCII = 2,
SHORT = 3,
LONG = 4,
RATIONAL = 5,
SBYTE = 6,
UNDEFINED = 7,
SSHORT = 8,
SLONG = 9,
SRATIONAL = 10,
FLOAT = 11,
DOUBLE = 12,
IFD = 13,
LONG8 = 16,
SLONG8 = 17,
IFD8 = 18,
}
}
tags! {
pub enum CompressionMethod(u16) unknown(
unknown
) {
None = 1,
Huffman = 2,
Fax3 = 3,
Fax4 = 4,
LZW = 5,
JPEG = 6,
ModernJPEG = 7,
Deflate = 8,
OldDeflate = 0x80B2,
PackBits = 0x8005,
ZSTD = 0xC350,
}
}
tags! {
pub enum PhotometricInterpretation(u16) {
WhiteIsZero = 0,
BlackIsZero = 1,
RGB = 2,
RGBPalette = 3,
TransparencyMask = 4,
CMYK = 5,
YCbCr = 6,
CIELab = 8,
}
}
tags! {
pub enum PlanarConfiguration(u16) {
Chunky = 1,
Planar = 2,
}
}
tags! {
pub enum Predictor(u16) {
None = 1,
Horizontal = 2,
FloatingPoint = 3,
}
}
tags! {
pub enum ResolutionUnit(u16) {
None = 1,
Inch = 2,
Centimeter = 3,
}
}
tags! {
pub enum SampleFormat(u16) unknown(
unknown
) {
Uint = 1,
Int = 2,
IEEEFP = 3,
Void = 4,
}
}