#![allow(dead_code)]
#[allow(non_upper_case_globals, dead_code, missing_docs)]
pub mod tag {
pub const NewSubFileType: u16 = 254;
pub const SubFileType: u16 = 255;
pub const ImageWidth: u16 = 256;
pub const ImageLength: u16 = 257;
pub const BitsPerSample: u16 = 258;
pub const Compression: u16 = 259;
pub const PhotometricInterpretation: u16 = 262;
pub const StripOffsets: u16 = 273;
pub const SamplesPerPixel: u16 = 277;
pub const RowsPerStrip: u16 = 278;
pub const StripByteCounts: u16 = 279;
pub const XResolution: u16 = 282;
pub const YResolution: u16 = 283;
pub const PlanarConfiguration: u16 = 284;
pub const ResolutionUnit: u16 = 296;
pub const Software: u16 = 305;
pub const DateTime: u16 = 306;
pub const SampleFormat: u16 = 339;
pub const ExtraSamples: u16 = 338;
pub const TileWidth: u16 = 322;
pub const TileLength: u16 = 323;
pub const TileOffsets: u16 = 324;
pub const TileByteCounts: u16 = 325;
pub const ModelPixelScaleTag: u16 = 33550;
pub const ModelTiepointTag: u16 = 33922;
pub const ModelTransformationTag: u16 = 34264;
pub const GeoKeyDirectoryTag: u16 = 34735;
pub const GeoDoubleParamsTag: u16 = 34736;
pub const GeoAsciiParamsTag: u16 = 34737;
pub const GdalMetadata: u16 = 42112;
pub const GdalNodata: u16 = 42113;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)]
pub enum DataType {
Byte = 1,
Ascii = 2,
Short = 3,
Long = 4,
Rational = 5,
SByte = 6,
Undefined = 7,
SShort = 8,
SLong = 9,
SRational = 10,
Float = 11,
Double = 12,
Long8 = 16,
SLong8 = 17,
}
impl DataType {
pub fn byte_size(self) -> usize {
match self {
Self::Byte | Self::SByte | Self::Ascii | Self::Undefined => 1,
Self::Short | Self::SShort => 2,
Self::Long | Self::SLong | Self::Float => 4,
Self::Rational | Self::SRational | Self::Double | Self::Long8 | Self::SLong8 => 8,
}
}
pub fn from_u16(v: u16) -> Option<Self> {
Some(match v {
1 => Self::Byte,
2 => Self::Ascii,
3 => Self::Short,
4 => Self::Long,
5 => Self::Rational,
6 => Self::SByte,
7 => Self::Undefined,
8 => Self::SShort,
9 => Self::SLong,
10 => Self::SRational,
11 => Self::Float,
12 => Self::Double,
16 => Self::Long8,
17 => Self::SLong8,
_ => return None,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Compression {
#[default]
None,
Huffman,
Lzw,
OldJpeg,
Jpeg,
Deflate,
WebP,
JpegXl,
PackBits,
Other(u16),
}
impl Compression {
pub fn tag_value(self) -> u16 {
match self {
Self::None => 1,
Self::Huffman => 2,
Self::Lzw => 5,
Self::OldJpeg => 6,
Self::Jpeg => 7,
Self::Deflate => 8,
Self::WebP => 50001,
Self::JpegXl => 50002,
Self::PackBits => 32773,
Self::Other(v) => v,
}
}
pub fn from_tag(v: u16) -> Self {
match v {
1 => Self::None,
2 => Self::Huffman,
5 => Self::Lzw,
6 => Self::OldJpeg,
7 => Self::Jpeg,
8 | 32946 => Self::Deflate, 50001 => Self::WebP,
50002 => Self::JpegXl,
32773 => Self::PackBits,
other => Self::Other(other),
}
}
pub fn name(self) -> &'static str {
match self {
Self::None => "None",
Self::Huffman => "Huffman",
Self::Lzw => "LZW",
Self::OldJpeg => "OldJPEG",
Self::Jpeg => "JPEG",
Self::Deflate => "Deflate",
Self::WebP => "WebP",
Self::JpegXl => "JPEG-XL",
Self::PackBits => "PackBits",
Self::Other(_) => "Unknown",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SampleFormat {
#[default]
Uint,
Int,
IeeeFloat,
Undefined,
}
impl SampleFormat {
pub fn tag_value(self) -> u16 {
match self {
Self::Uint => 1,
Self::Int => 2,
Self::IeeeFloat => 3,
Self::Undefined => 4,
}
}
pub fn from_tag(v: u16) -> Self {
match v {
1 => Self::Uint,
2 => Self::Int,
3 => Self::IeeeFloat,
_ => Self::Undefined,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PixelType {
Uint8,
Uint16,
Uint32,
Uint64,
Int8,
Int16,
Int32,
Int64,
Float32,
Float64,
}
impl PixelType {
pub fn byte_size(self) -> usize {
match self {
Self::Uint8 | Self::Int8 => 1,
Self::Uint16 | Self::Int16 => 2,
Self::Uint32 | Self::Int32 | Self::Float32 => 4,
Self::Uint64 | Self::Int64 | Self::Float64 => 8,
}
}
pub fn bits_per_sample(self) -> u16 {
(self.byte_size() * 8) as u16
}
pub fn sample_format(self) -> SampleFormat {
match self {
Self::Uint8 | Self::Uint16 | Self::Uint32 | Self::Uint64 => SampleFormat::Uint,
Self::Int8 | Self::Int16 | Self::Int32 | Self::Int64 => SampleFormat::Int,
Self::Float32 | Self::Float64 => SampleFormat::IeeeFloat,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PhotometricInterpretation {
MinIsWhite = 0,
#[default]
MinIsBlack = 1,
Rgb = 2,
Palette = 3,
Mask = 4,
Separated = 5,
YCbCr = 6,
CieLab = 8,
}
impl PhotometricInterpretation {
pub fn tag_value(self) -> u16 {
self as u16
}
pub fn from_tag(v: u16) -> Self {
match v {
0 => Self::MinIsWhite,
1 => Self::MinIsBlack,
2 => Self::Rgb,
3 => Self::Palette,
4 => Self::Mask,
5 => Self::Separated,
6 => Self::YCbCr,
8 => Self::CieLab,
_ => Self::MinIsBlack,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PlanarConfig {
#[default]
Chunky = 1,
Planar = 2,
}
impl PlanarConfig {
pub fn tag_value(self) -> u16 {
self as u16
}
pub fn from_tag(v: u16) -> Self {
if v == 2 { Self::Planar } else { Self::Chunky }
}
}