tiff/
lib.rs

1//! Decoding and Encoding of TIFF Images
2//!
3//! TIFF (Tagged Image File Format) is a versatile image format that supports
4//! lossless and lossy compression.
5//!
6//! # Related Links
7//! * <https://web.archive.org/web/20210108073850/https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
8
9mod bytecast;
10pub mod decoder;
11mod directory;
12pub mod encoder;
13mod error;
14pub mod tags;
15
16pub use self::directory::Directory;
17pub use self::error::{TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError};
18
19/// An enumeration over supported color types and their bit depths
20#[derive(Copy, PartialEq, Eq, Debug, Clone, Hash)]
21#[non_exhaustive]
22pub enum ColorType {
23    /// Pixel is grayscale
24    Gray(u8),
25
26    /// Pixel contains R, G and B channels
27    RGB(u8),
28
29    /// Pixel is an index into a color palette
30    Palette(u8),
31
32    /// Pixel is grayscale with an alpha channel
33    GrayA(u8),
34
35    /// Pixel is RGB with an alpha channel
36    RGBA(u8),
37
38    /// Pixel is CMYK
39    CMYK(u8),
40
41    /// Pixel is CMYK with an alpha channel
42    CMYKA(u8),
43
44    /// Pixel is YCbCr
45    YCbCr(u8),
46
47    /// Pixel is CIE L*a*b* (ICC LAb)
48    Lab(u8),
49
50    /// Pixel has multiple bands/channels
51    Multiband { bit_depth: u8, num_samples: u16 },
52}
53impl ColorType {
54    fn bit_depth(&self) -> u8 {
55        match *self {
56            ColorType::Gray(b)
57            | ColorType::RGB(b)
58            | ColorType::Palette(b)
59            | ColorType::GrayA(b)
60            | ColorType::RGBA(b)
61            | ColorType::CMYK(b)
62            | ColorType::CMYKA(b)
63            | ColorType::YCbCr(b)
64            | ColorType::Lab(b)
65            | ColorType::Multiband { bit_depth: b, .. } => b,
66        }
67    }
68
69    fn num_samples(&self) -> u16 {
70        match *self {
71            ColorType::Gray(_) => 1,
72            ColorType::RGB(_) => 3,
73            ColorType::Palette(_) => 1,
74            ColorType::GrayA(_) => 2,
75            ColorType::RGBA(_) => 4,
76            ColorType::CMYK(_) => 4,
77            ColorType::CMYKA(_) => 5,
78            ColorType::YCbCr(_) => 3,
79            ColorType::Lab(_) => 3,
80            ColorType::Multiband { num_samples, .. } => num_samples,
81        }
82    }
83}