1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
use std::fmt;
#[derive(Debug, PartialEq, Eq)]
pub struct Tag(pub Context, pub u16);
impl Tag {
#[inline]
pub fn context(&self) -> Context {
self.0
}
#[inline]
pub fn value(&self) -> u16 {
self.1
}
#[inline]
pub fn description(&self) -> Option<&str> {
get_tag_info(self).map(|ti| ti.desc)
}
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match get_tag_info(self) {
Some(ti) => f.pad(ti.name),
None => f.pad(&format!("{:?}", self)),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Context {
Tiff,
Exif,
Gps,
Interop,
}
macro_rules! generate_well_known_tag_constants {
(
$( |$ctx:path| $(
$( #[$attr:meta] )*
($name:ident, $num:expr, $desc:expr)
),+, )+
) => (
$($(
$( #[$attr] )*
#[allow(non_upper_case_globals)]
pub const $name: Tag = Tag($ctx, $num);
)+)+
mod tag_info {
pub struct TagInfo {
pub name: &'static str,
pub desc: &'static str,
}
$($(
#[allow(non_upper_case_globals)]
pub static $name: TagInfo = TagInfo {
name: stringify!($name), desc: $desc };
)+)+
}
fn get_tag_info(tag: &Tag) -> Option<&tag_info::TagInfo> {
match *tag {
$($(
self::$name => Some(&tag_info::$name),
)+)+
_ => None,
}
}
)
}
generate_well_known_tag_constants!(
|Context::Tiff|
(ExifIFDPointer, 0x8769, "Exif IFD pointer"),
(GPSInfoIFDPointer, 0x8825, "GPS Info IFD pointer"),
|Context::Exif|
(InteropIFDPointer, 0xa005, "Interoperability IFD pointer"),
|Context::Tiff|
(ImageWidth, 0x100, "Image width"),
(ImageLength, 0x101, "Image height"),
(BitsPerSample, 0x102, "Number of bits per component"),
(Compression, 0x103, "Compression scheme"),
(PhotometricInterpretation, 0x106, "Pixel composition"),
(ImageDescription, 0x10e, "Image title"),
(Make, 0x10f, "Manufacturer of image input equipment"),
(Model, 0x110, "Model of image input equipment"),
(StripOffsets, 0x111, "Image data location"),
(Orientation, 0x112, "Orientation of image"),
(SamplesPerPixel, 0x115, "Number of components"),
(RowsPerStrip, 0x116, "Number of rows per strip"),
(StripByteCounts, 0x117, "Bytes per compressed strip"),
(XResolution, 0x11a, "Image resolution in width direction"),
(YResolution, 0x11b, "Image resolution in height direction"),
(PlanarConfiguration, 0x11c, "Image data arrangement"),
(ResolutionUnit, 0x128, "Unit of X and Y resolution"),
(TransferFunction, 0x12d, "Transfer function"),
(Software, 0x131, "Software used"),
(DateTime, 0x132, "File change date and time"),
(Artist, 0x13b, "Person who created the image"),
(WhitePoint, 0x13e, "White point chromaticity"),
(PrimaryChromaticities, 0x13f, "Chromaticities of primaries"),
(JPEGInterchangeFormat, 0x201, "Offset to JPEG SOI"),
(JPEGInterchangeFormatLength, 0x202, "Bytes of JPEG data"),
(YCbCrCoefficients, 0x211, "Color space transformation matrix coefficients"),
(YCbCrSubSampling, 0x212, "Subsampling ratio of Y to C"),
(YCbCrPositioning, 0x213, "Y and C positioning"),
(ReferenceBlackWhite, 0x214, "Pair of black and white reference values"),
(Copyright, 0x8298, "Copyright holder"),
|Context::Exif|
(ExposureTime, 0x829a, "Exposure time"),
(FNumber, 0x829d, "F number"),
(ExposureProgram, 0x8822, "Exposure program"),
(SpectralSensitivity, 0x8824, "Spectral sensitivity"),
(PhotographicSensitivity, 0x8827, "Photographic sensitivity"),
(OECF, 0x8828, "Optoelectric conversion factor"),
(SensitivityType, 0x8830, "Sensitivity type"),
(StandardOutputSensitivity, 0x8831, "Standard output sensitivity"),
(RecommendedExposureIndex, 0x8832, "Recommended exposure index"),
(ISOSpeed, 0x8833, "ISO speed"),
(ISOSpeedLatitudeyyy, 0x8834, "ISO speed latitude yyy"),
(ISOSpeedLatitudezzz, 0x8835, "ISO speed latitude zzz"),
(ExifVersion, 0x9000, "Exif version"),
(DateTimeOriginal, 0x9003, "Date and time of original data generation"),
(DateTimeDigitized, 0x9004, "Date and time of digital data generation"),
(ComponentsConfiguration, 0x9101, "Meaning of each component"),
(CompressedBitsPerPixel, 0x9102, "Image compression mode"),
(ShutterSpeedValue, 0x9201, "Shutter speed"),
(ApertureValue, 0x9202, "Aperture"),
(BrightnessValue, 0x9203, "Brightness"),
(ExposureBiasValue, 0x9204, "Exposure bias"),
(MaxApertureValue, 0x9205, "Maximum lens aperture"),
(SubjectDistance, 0x9206, "Subject distance"),
(MeteringMode, 0x9207, "Metering mode"),
(LightSource, 0x9208, "Light source"),
(Flash, 0x9209, "Flash"),
(FocalLength, 0x920a, "Lens focal length"),
(SubjectArea, 0x9214, "Subject area"),
(MakerNote, 0x927c, "Manufacturer notes"),
(UserComment, 0x9286, "User comments"),
(SubSecTime, 0x9290, "DateTime subseconds"),
(SubSecTimeOriginal, 0x9291, "DateTimeOriginal subseconds"),
(SubSecTimeDigitized, 0x9292, "DateTimeDigitized subseconds"),
(FlashpixVersion, 0xa000, "Supported Flashpix version"),
(ColorSpace, 0xa001, "Color space information"),
(PixelXDimension, 0xa002, "Valid image width"),
(PixelYDimension, 0xa003, "Valid image height"),
(RelatedSoundFile, 0xa004, "Related audio file"),
(FlashEnergy, 0xa20b, "Flash energy"),
(SpatialFrequencyResponse, 0xa20c, "Spatial frequency response"),
(FocalPlaneXResolution, 0xa20e, "Focal plane X resolution"),
(FocalPlaneYResolution, 0xa20f, "Focal plane Y resolution"),
(FocalPlaneResolutionUnit, 0xa210, "Focal plane resolution unit"),
(SubjectLocation, 0xa214, "Subject location"),
(ExposureIndex, 0xa215, "Exposure index"),
(SensingMethod, 0xa217, "Sensing method"),
(FileSource, 0xa300, "File source"),
(SceneType, 0xa301, "Scene type"),
(CFAPattern, 0xa302, "CFA pattern"),
(CustomRendered, 0xa401, "Custom image processing"),
(ExposureMode, 0xa402, "Exposure mode"),
(WhiteBalance, 0xa403, "White balance"),
(DigitalZoomRatio, 0xa404, "Digital zoom ratio"),
(FocalLengthIn35mmFilm, 0xa405, "Focal length in 35 mm film"),
(SceneCaptureType, 0xa406, "Scene capture type"),
(GainControl, 0xa407, "Gain control"),
(Contrast, 0xa408, "Contrast"),
(Saturation, 0xa409, "Saturation"),
(Sharpness, 0xa40a, "Sharpness"),
(DeviceSettingDescription, 0xa40b, "Device settings description"),
(SubjectDistanceRange, 0xa40c, "Subject distance range"),
(ImageUniqueID, 0xa420, "Unique image ID"),
(CameraOwnerName, 0xa430, "Camera owner name"),
(BodySerialNumber, 0xa431, "Body serial number"),
(LensSpecification, 0xa432, "Lens specification"),
(LensMake, 0xa433, "Lens make"),
(LensModel, 0xa434, "Lens model"),
(LensSerialNumber, 0xa435, "Lens serial number"),
(Gamma, 0xa500, "Gamma"),
|Context::Gps|
(GPSVersionID, 0x0, "GPS tag version"),
(GPSLatitudeRef, 0x1, "North or south latitude"),
(GPSLatitude, 0x2, "Latitude"),
(GPSLongitudeRef, 0x3, "East or West Longitude"),
(GPSLongitude, 0x4, "Longitude"),
(GPSAltitudeRef, 0x5, "Altitude reference"),
(GPSAltitude, 0x6, "Altitude"),
(GPSTimeStamp, 0x7, "GPS time (atomic clock)"),
(GPSSatellites, 0x8, "GPS satellites used for measurement"),
(GPSStatus, 0x9, "GPS receiver status"),
(GPSMeasureMode, 0xa, "GPS measurement mode"),
(GPSDOP, 0xb, "Measurement precision"),
(GPSSpeedRef, 0xc, "Speed unit"),
(GPSSpeed, 0xd, "Speed of GPS receiver"),
(GPSTrackRef, 0xe, "Reference for direction of movement"),
(GPSTrack, 0xf, "Direction of movement"),
(GPSImgDirectionRef, 0x10, "Reference for direction of image"),
(GPSImgDirection, 0x11, "Direction of image"),
(GPSMapDatum, 0x12, "Geodetic survey data used"),
(GPSDestLatitudeRef, 0x13, "Reference for latitude of destination"),
(GPSDestLatitude, 0x14, "Latitude of destination"),
(GPSDestLongitudeRef, 0x15, "Reference for longitude of destination"),
(GPSDestLongitude, 0x16, "Longitude of destination"),
(GPSDestBearingRef, 0x17, "Reference for bearing of destination"),
(GPSDestBearing, 0x18, "Bearing of destination"),
(GPSDestDistanceRef, 0x19, "Reference for distance to destination"),
(GPSDestDistance, 0x1a, "Distance to destination"),
(GPSProcessingMethod, 0x1b, "Name of GPS processing method"),
(GPSAreaInformation, 0x1c, "Name of GPS area"),
(GPSDateStamp, 0x1d, "GPS date"),
(GPSDifferential, 0x1e, "GPS differential correction"),
(GPSHPositioningError, 0x1f, "Horizontal positioning error"),
|Context::Interop|
(InteroperabilityIndex, 0x1, "Interoperability identification"),
);
#[cfg(test)]
mod tests {
use tag;
use super::*;
#[test]
fn tag_constant_in_pattern() {
match Tag(Context::Tiff, 0x132) {
Tag(Context::Tiff, 0x132) => {},
_ => panic!("failed to match Tag"),
}
match Tag(Context::Tiff, 0x132) {
tag::DateTime => {},
_ => panic!("failed to match Tag"),
}
}
}