| 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 | |
| 9 | mod bytecast; |
| 10 | pub mod decoder; |
| 11 | mod directory; |
| 12 | pub mod encoder; |
| 13 | mod error; |
| 14 | pub mod tags; |
| 15 | |
| 16 | pub use self::directory::Directory; |
| 17 | pub 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] |
| 22 | pub 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 | } |
| 53 | impl ColorType { |
| 54 | /// The number of bits used to store each sample. |
| 55 | pub fn bit_depth(&self) -> u8 { |
| 56 | match *self { |
| 57 | ColorType::Gray(b) |
| 58 | | ColorType::RGB(b) |
| 59 | | ColorType::Palette(b) |
| 60 | | ColorType::GrayA(b) |
| 61 | | ColorType::RGBA(b) |
| 62 | | ColorType::CMYK(b) |
| 63 | | ColorType::CMYKA(b) |
| 64 | | ColorType::YCbCr(b) |
| 65 | | ColorType::Lab(b) |
| 66 | | ColorType::Multiband { bit_depth: b, .. } => b, |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /// The number of samples in each representation of a single color. |
| 71 | pub fn num_samples(&self) -> u16 { |
| 72 | match *self { |
| 73 | ColorType::Gray(_) => 1, |
| 74 | ColorType::RGB(_) => 3, |
| 75 | ColorType::Palette(_) => 1, |
| 76 | ColorType::GrayA(_) => 2, |
| 77 | ColorType::RGBA(_) => 4, |
| 78 | ColorType::CMYK(_) => 4, |
| 79 | ColorType::CMYKA(_) => 5, |
| 80 | ColorType::YCbCr(_) => 3, |
| 81 | ColorType::Lab(_) => 3, |
| 82 | ColorType::Multiband { num_samples, .. } => num_samples, |
| 83 | } |
| 84 | } |
| 85 | } |