1 use crate::tags::{PhotometricInterpretation, SampleFormat};
2 
3 /// Trait for different colortypes that can be encoded.
4 pub trait ColorType {
5     /// The type of each sample of this colortype
6     type Inner: super::TiffValue;
7     /// The value of the tiff tag `PhotometricInterpretation`
8     const TIFF_VALUE: PhotometricInterpretation;
9     /// The value of the tiff tag `BitsPerSample`
10     const BITS_PER_SAMPLE: &'static [u16];
11     /// The value of the tiff tag `SampleFormat`
12     const SAMPLE_FORMAT: &'static [SampleFormat];
13 }
14 
15 pub struct Gray8;
16 impl ColorType for Gray8 {
17     type Inner = u8;
18     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
19     const BITS_PER_SAMPLE: &'static [u16] = &[8];
20     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint];
21 }
22 
23 pub struct Gray16;
24 impl ColorType for Gray16 {
25     type Inner = u16;
26     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
27     const BITS_PER_SAMPLE: &'static [u16] = &[16];
28     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint];
29 }
30 
31 pub struct Gray32;
32 impl ColorType for Gray32 {
33     type Inner = u32;
34     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
35     const BITS_PER_SAMPLE: &'static [u16] = &[32];
36     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint];
37 }
38 
39 pub struct Gray32Float;
40 impl ColorType for Gray32Float {
41     type Inner = f32;
42     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
43     const BITS_PER_SAMPLE: &'static [u16] = &[32];
44     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP];
45 }
46 
47 pub struct Gray64;
48 impl ColorType for Gray64 {
49     type Inner = u64;
50     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
51     const BITS_PER_SAMPLE: &'static [u16] = &[64];
52     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint];
53 }
54 
55 pub struct Gray64Float;
56 impl ColorType for Gray64Float {
57     type Inner = f64;
58     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::BlackIsZero;
59     const BITS_PER_SAMPLE: &'static [u16] = &[64];
60     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP];
61 }
62 
63 pub struct RGB8;
64 impl ColorType for RGB8 {
65     type Inner = u8;
66     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
67     const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8];
68     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
69 }
70 
71 pub struct RGB16;
72 impl ColorType for RGB16 {
73     type Inner = u16;
74     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
75     const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16];
76     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
77 }
78 
79 pub struct RGB32;
80 impl ColorType for RGB32 {
81     type Inner = u32;
82     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
83     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32];
84     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
85 }
86 
87 pub struct RGB32Float;
88 impl ColorType for RGB32Float {
89     type Inner = f32;
90     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
91     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32];
92     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 3];
93 }
94 
95 pub struct RGB64;
96 impl ColorType for RGB64 {
97     type Inner = u64;
98     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
99     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64];
100     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
101 }
102 
103 pub struct RGB64Float;
104 impl ColorType for RGB64Float {
105     type Inner = f64;
106     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
107     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64];
108     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 3];
109 }
110 
111 pub struct RGBA8;
112 impl ColorType for RGBA8 {
113     type Inner = u8;
114     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
115     const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8, 8];
116     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
117 }
118 
119 pub struct RGBA16;
120 impl ColorType for RGBA16 {
121     type Inner = u16;
122     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
123     const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16, 16];
124     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
125 }
126 
127 pub struct RGBA32;
128 impl ColorType for RGBA32 {
129     type Inner = u32;
130     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
131     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32];
132     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
133 }
134 
135 pub struct RGBA32Float;
136 impl ColorType for RGBA32Float {
137     type Inner = f32;
138     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
139     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32];
140     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
141 }
142 
143 pub struct RGBA64;
144 impl ColorType for RGBA64 {
145     type Inner = u64;
146     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
147     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
148     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
149 }
150 
151 pub struct RGBA64Float;
152 impl ColorType for RGBA64Float {
153     type Inner = f64;
154     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::RGB;
155     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
156     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
157 }
158 
159 pub struct CMYK8;
160 impl ColorType for CMYK8 {
161     type Inner = u8;
162     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
163     const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8, 8];
164     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
165 }
166 
167 pub struct CMYK16;
168 impl ColorType for CMYK16 {
169     type Inner = u16;
170     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
171     const BITS_PER_SAMPLE: &'static [u16] = &[16, 16, 16, 16];
172     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
173 }
174 
175 pub struct CMYK32;
176 impl ColorType for CMYK32 {
177     type Inner = u32;
178     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
179     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32];
180     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
181 }
182 
183 pub struct CMYK32Float;
184 impl ColorType for CMYK32Float {
185     type Inner = f32;
186     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
187     const BITS_PER_SAMPLE: &'static [u16] = &[32, 32, 32, 32];
188     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
189 }
190 
191 pub struct CMYK64;
192 impl ColorType for CMYK64 {
193     type Inner = u64;
194     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
195     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
196     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 4];
197 }
198 
199 pub struct CMYK64Float;
200 impl ColorType for CMYK64Float {
201     type Inner = f64;
202     const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::CMYK;
203     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
204     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
205 }
206