Skip to content

Commit

Permalink
Merge pull request #23 from birktj/encode
Browse files Browse the repository at this point in the history
Tiff encoding
  • Loading branch information
HeroicKatora authored Feb 26, 2019
2 parents 7714220 + 098b799 commit 3973d01
Show file tree
Hide file tree
Showing 7 changed files with 840 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ byteorder = "1.2"
lzw = "0.10"
num-derive = "0.2"
num-traits = "0.2"

[dev-dependencies]
tempfile = "3.0"
6 changes: 6 additions & 0 deletions src/decoder/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ macro_rules! tags {
Tag::Unknown(n)
}
}
pub fn to_u16(&self) -> u16 {
match self {
$( Tag::$tag => $val, )*
Tag::Unknown(n) => *n,
}
}
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/encoder/colortype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::decoder::PhotometricInterpretation;

/// Trait for different colortypes that can be encoded.
pub trait ColorType {
/// The type of each sample of this colortype
type Inner: super::TiffValue;
/// The value of the tiff tag `PhotometricInterpretation`
const TIFF_VALUE: PhotometricInterpretation;
/// The value of the tiff tag `BitsPerSample`
const BITS_PER_SAMPLE: &'static [u16];
}

pub struct Gray8;
impl ColorType for Gray8 {
type Inner = u8;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
const BITS_PER_SAMPLE: &'static [u16] = &[8];
}

pub struct Gray16;
impl ColorType for Gray16 {
type Inner = u16;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
const BITS_PER_SAMPLE: &'static [u16] = &[16];
}

pub struct RGB8;
impl ColorType for RGB8 {
type Inner = u8;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8];
}

pub struct RGB16;
impl ColorType for RGB16 {
type Inner = u16;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16];
}

pub struct RGBA8;
impl ColorType for RGBA8 {
type Inner = u8;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8, 8];
}

pub struct RGBA16;
impl ColorType for RGBA16 {
type Inner = u16;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16, 16];
}

pub struct CMYK8;
impl ColorType for CMYK8 {
type Inner = u8;
const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8, 8];
}
Loading

0 comments on commit 3973d01

Please sign in to comment.