Add Tag.default_value().

This commit is contained in:
KAMADA Ken'ichi 2017-03-24 22:46:26 +09:00
parent 6a5355750e
commit 7f66863d84
2 changed files with 368 additions and 146 deletions

View File

@ -26,6 +26,8 @@
use std::fmt; use std::fmt;
use value::Value;
/// A tag of a TIFF field. /// A tag of a TIFF field.
// //
// This is not an enum to keep safety and API stability, while // This is not an enum to keep safety and API stability, while
@ -64,6 +66,13 @@ impl Tag {
pub fn description(&self) -> Option<&str> { pub fn description(&self) -> Option<&str> {
get_tag_info(self).map(|ti| ti.desc) get_tag_info(self).map(|ti| ti.desc)
} }
/// Returns the default value of the tag. `None` is returned if
/// it is not defined in the standard or it depends on the context.
#[inline]
pub fn default_value(&self) -> Option<Value> {
get_tag_info(self).and_then(|ti| (&ti.default).into())
}
} }
impl fmt::Display for Tag { impl fmt::Display for Tag {
@ -93,7 +102,7 @@ macro_rules! generate_well_known_tag_constants {
$( |$ctx:path| $( $( |$ctx:path| $(
// Copy the doc attribute to the actual definition. // Copy the doc attribute to the actual definition.
$( #[$attr:meta] )* $( #[$attr:meta] )*
($name:ident, $num:expr, $desc:expr) ($name:ident, $num:expr, $defval:expr, $desc:expr)
),+, )+ ),+, )+
) => ( ) => (
/// A module that contains Exif tag constants. /// A module that contains Exif tag constants.
@ -122,15 +131,18 @@ macro_rules! generate_well_known_tag_constants {
// Use a separate module to avoid name conflicts between // Use a separate module to avoid name conflicts between
// const Tag and static TagInfo. // const Tag and static TagInfo.
mod tag_info { mod tag_info {
use value::DefaultValue;
pub struct TagInfo { pub struct TagInfo {
pub name: &'static str, pub name: &'static str,
pub desc: &'static str, pub desc: &'static str,
pub default: DefaultValue,
} }
$($( $($(
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
pub static $name: TagInfo = TagInfo { pub static $name: TagInfo = TagInfo {
name: stringify!($name), desc: $desc }; name: stringify!($name), desc: $desc, default: $defval };
)+)+ )+)+
} }
@ -153,174 +165,321 @@ generate_well_known_tag_constants!(
/// A pointer to the Exif IFD. This is used for the internal structure /// A pointer to the Exif IFD. This is used for the internal structure
/// of Exif data and will not be returned to the user. /// of Exif data and will not be returned to the user.
(ExifIFDPointer, 0x8769, "Exif IFD pointer"), (ExifIFDPointer, 0x8769, DefaultValue::None,
"Exif IFD pointer"),
/// A pointer to the GPS IFD. This is used for the internal structure /// A pointer to the GPS IFD. This is used for the internal structure
/// of Exif data and will not be returned to the user. /// of Exif data and will not be returned to the user.
(GPSInfoIFDPointer, 0x8825, "GPS Info IFD pointer"), (GPSInfoIFDPointer, 0x8825, DefaultValue::None,
"GPS Info IFD pointer"),
|Context::Exif| |Context::Exif|
/// A pointer to the interoperability IFD. This is used for the internal /// A pointer to the interoperability IFD. This is used for the internal
/// structure of Exif data and will not be returned to the user. /// structure of Exif data and will not be returned to the user.
(InteropIFDPointer, 0xa005, "Interoperability IFD pointer"), (InteropIFDPointer, 0xa005, DefaultValue::None,
"Interoperability IFD pointer"),
// TIFF primary and thumbnail attributes [EXIF23 4.6.4 Table 4, // TIFF primary and thumbnail attributes [EXIF23 4.6.4 Table 4,
// 4.6.8 Table 17, and 4.6.8 Table 21]. // 4.6.8 Table 17, and 4.6.8 Table 21].
|Context::Tiff| |Context::Tiff|
(ImageWidth, 0x100, "Image width"), (ImageWidth, 0x100, DefaultValue::None,
(ImageLength, 0x101, "Image height"), "Image width"),
(BitsPerSample, 0x102, "Number of bits per component"), (ImageLength, 0x101, DefaultValue::None,
(Compression, 0x103, "Compression scheme"), "Image height"),
(PhotometricInterpretation, 0x106, "Pixel composition"), (BitsPerSample, 0x102, DefaultValue::Short(&[8, 8, 8]),
(ImageDescription, 0x10e, "Image title"), "Number of bits per component"),
(Make, 0x10f, "Manufacturer of image input equipment"), (Compression, 0x103, DefaultValue::None,
(Model, 0x110, "Model of image input equipment"), "Compression scheme"),
(StripOffsets, 0x111, "Image data location"), (PhotometricInterpretation, 0x106, DefaultValue::None,
(Orientation, 0x112, "Orientation of image"), "Pixel composition"),
(SamplesPerPixel, 0x115, "Number of components"), (ImageDescription, 0x10e, DefaultValue::None,
(RowsPerStrip, 0x116, "Number of rows per strip"), "Image title"),
(StripByteCounts, 0x117, "Bytes per compressed strip"), (Make, 0x10f, DefaultValue::None,
(XResolution, 0x11a, "Image resolution in width direction"), "Manufacturer of image input equipment"),
(YResolution, 0x11b, "Image resolution in height direction"), (Model, 0x110, DefaultValue::None,
(PlanarConfiguration, 0x11c, "Image data arrangement"), "Model of image input equipment"),
(ResolutionUnit, 0x128, "Unit of X and Y resolution"), (StripOffsets, 0x111, DefaultValue::None,
(TransferFunction, 0x12d, "Transfer function"), "Image data location"),
(Software, 0x131, "Software used"), (Orientation, 0x112, DefaultValue::Short(&[1]),
(DateTime, 0x132, "File change date and time"), "Orientation of image"),
(Artist, 0x13b, "Person who created the image"), (SamplesPerPixel, 0x115, DefaultValue::Short(&[3]),
(WhitePoint, 0x13e, "White point chromaticity"), "Number of components"),
(PrimaryChromaticities, 0x13f, "Chromaticities of primaries"), (RowsPerStrip, 0x116, DefaultValue::None,
(JPEGInterchangeFormat, 0x201, "Offset to JPEG SOI"), "Number of rows per strip"),
(JPEGInterchangeFormatLength, 0x202, "Bytes of JPEG data"), (StripByteCounts, 0x117, DefaultValue::None,
(YCbCrCoefficients, 0x211, "Color space transformation matrix coefficients"), "Bytes per compressed strip"),
(YCbCrSubSampling, 0x212, "Subsampling ratio of Y to C"), (XResolution, 0x11a, DefaultValue::Rational(&[(72, 1)]),
(YCbCrPositioning, 0x213, "Y and C positioning"), "Image resolution in width direction"),
(ReferenceBlackWhite, 0x214, "Pair of black and white reference values"), (YResolution, 0x11b, DefaultValue::Rational(&[(72, 1)]),
(Copyright, 0x8298, "Copyright holder"), "Image resolution in height direction"),
(PlanarConfiguration, 0x11c, DefaultValue::Short(&[1]),
"Image data arrangement"),
(ResolutionUnit, 0x128, DefaultValue::Short(&[2]),
"Unit of X and Y resolution"),
(TransferFunction, 0x12d, DefaultValue::None,
"Transfer function"),
(Software, 0x131, DefaultValue::None,
"Software used"),
(DateTime, 0x132, DefaultValue::None,
"File change date and time"),
(Artist, 0x13b, DefaultValue::None,
"Person who created the image"),
(WhitePoint, 0x13e, DefaultValue::None,
"White point chromaticity"),
(PrimaryChromaticities, 0x13f, DefaultValue::None,
"Chromaticities of primaries"),
(JPEGInterchangeFormat, 0x201, DefaultValue::None,
"Offset to JPEG SOI"),
(JPEGInterchangeFormatLength, 0x202, DefaultValue::None,
"Bytes of JPEG data"),
(YCbCrCoefficients, 0x211, DefaultValue::Unspecified,
"Color space transformation matrix coefficients"),
(YCbCrSubSampling, 0x212, DefaultValue::None,
"Subsampling ratio of Y to C"),
(YCbCrPositioning, 0x213, DefaultValue::Short(&[1]),
"Y and C positioning"),
(ReferenceBlackWhite, 0x214, DefaultValue::ContextDependent,
"Pair of black and white reference values"),
(Copyright, 0x8298, DefaultValue::None,
"Copyright holder"),
// Exif IFD attributes [EXIF23 4.6.5 Table 7 and 4.6.8 Table 18]. // Exif IFD attributes [EXIF23 4.6.5 Table 7 and 4.6.8 Table 18].
|Context::Exif| |Context::Exif|
(ExposureTime, 0x829a, "Exposure time"), (ExposureTime, 0x829a, DefaultValue::None,
(FNumber, 0x829d, "F number"), "Exposure time"),
(ExposureProgram, 0x8822, "Exposure program"), (FNumber, 0x829d, DefaultValue::None,
(SpectralSensitivity, 0x8824, "Spectral sensitivity"), "F number"),
(PhotographicSensitivity, 0x8827, "Photographic sensitivity"), (ExposureProgram, 0x8822, DefaultValue::None,
(OECF, 0x8828, "Optoelectric conversion factor"), "Exposure program"),
(SensitivityType, 0x8830, "Sensitivity type"), (SpectralSensitivity, 0x8824, DefaultValue::None,
(StandardOutputSensitivity, 0x8831, "Standard output sensitivity"), "Spectral sensitivity"),
(RecommendedExposureIndex, 0x8832, "Recommended exposure index"), (PhotographicSensitivity, 0x8827, DefaultValue::None,
(ISOSpeed, 0x8833, "ISO speed"), "Photographic sensitivity"),
(ISOSpeedLatitudeyyy, 0x8834, "ISO speed latitude yyy"), (OECF, 0x8828, DefaultValue::None,
(ISOSpeedLatitudezzz, 0x8835, "ISO speed latitude zzz"), "Optoelectric conversion factor"),
(ExifVersion, 0x9000, "Exif version"), (SensitivityType, 0x8830, DefaultValue::None,
(DateTimeOriginal, 0x9003, "Date and time of original data generation"), "Sensitivity type"),
(DateTimeDigitized, 0x9004, "Date and time of digital data generation"), (StandardOutputSensitivity, 0x8831, DefaultValue::None,
(OffsetTime, 0x9010, "Offset data of DateTime"), "Standard output sensitivity"),
(OffsetTimeOriginal, 0x9011, "Offset data of DateTimeOriginal"), (RecommendedExposureIndex, 0x8832, DefaultValue::None,
(OffsetTimeDigitized, 0x9012, "Offset data of DateTimeDigitized"), "Recommended exposure index"),
(ComponentsConfiguration, 0x9101, "Meaning of each component"), (ISOSpeed, 0x8833, DefaultValue::None,
(CompressedBitsPerPixel, 0x9102, "Image compression mode"), "ISO speed"),
(ShutterSpeedValue, 0x9201, "Shutter speed"), (ISOSpeedLatitudeyyy, 0x8834, DefaultValue::None,
(ApertureValue, 0x9202, "Aperture"), "ISO speed latitude yyy"),
(BrightnessValue, 0x9203, "Brightness"), (ISOSpeedLatitudezzz, 0x8835, DefaultValue::None,
(ExposureBiasValue, 0x9204, "Exposure bias"), "ISO speed latitude zzz"),
(MaxApertureValue, 0x9205, "Maximum lens aperture"), // The absence of this field means non-conformance to Exif, so the default
(SubjectDistance, 0x9206, "Subject distance"), // value specified in the standard (e.g., "0231") should not apply.
(MeteringMode, 0x9207, "Metering mode"), (ExifVersion, 0x9000, DefaultValue::None,
(LightSource, 0x9208, "Light source"), "Exif version"),
(Flash, 0x9209, "Flash"), (DateTimeOriginal, 0x9003, DefaultValue::None,
(FocalLength, 0x920a, "Lens focal length"), "Date and time of original data generation"),
(SubjectArea, 0x9214, "Subject area"), (DateTimeDigitized, 0x9004, DefaultValue::None,
(MakerNote, 0x927c, "Manufacturer notes"), "Date and time of digital data generation"),
(UserComment, 0x9286, "User comments"), (OffsetTime, 0x9010, DefaultValue::None,
(SubSecTime, 0x9290, "DateTime subseconds"), "Offset data of DateTime"),
(SubSecTimeOriginal, 0x9291, "DateTimeOriginal subseconds"), (OffsetTimeOriginal, 0x9011, DefaultValue::None,
(SubSecTimeDigitized, 0x9292, "DateTimeDigitized subseconds"), "Offset data of DateTimeOriginal"),
(Temperature, 0x9400, "Temperature"), (OffsetTimeDigitized, 0x9012, DefaultValue::None,
(Humidity, 0x9401, "Humidity"), "Offset data of DateTimeDigitized"),
(Pressure, 0x9402, "Pressure"), (ComponentsConfiguration, 0x9101, DefaultValue::ContextDependent,
(WaterDepth, 0x9403, "Water depth"), "Meaning of each component"),
(Acceleration, 0x9404, "Acceleration"), (CompressedBitsPerPixel, 0x9102, DefaultValue::None,
(CameraElevationAngle, 0x9405, "Camera elevation angle"), "Image compression mode"),
(FlashpixVersion, 0xa000, "Supported Flashpix version"), (ShutterSpeedValue, 0x9201, DefaultValue::None,
(ColorSpace, 0xa001, "Color space information"), "Shutter speed"),
(PixelXDimension, 0xa002, "Valid image width"), (ApertureValue, 0x9202, DefaultValue::None,
(PixelYDimension, 0xa003, "Valid image height"), "Aperture"),
(RelatedSoundFile, 0xa004, "Related audio file"), (BrightnessValue, 0x9203, DefaultValue::None,
(FlashEnergy, 0xa20b, "Flash energy"), "Brightness"),
(SpatialFrequencyResponse, 0xa20c, "Spatial frequency response"), (ExposureBiasValue, 0x9204, DefaultValue::None,
(FocalPlaneXResolution, 0xa20e, "Focal plane X resolution"), "Exposure bias"),
(FocalPlaneYResolution, 0xa20f, "Focal plane Y resolution"), (MaxApertureValue, 0x9205, DefaultValue::None,
(FocalPlaneResolutionUnit, 0xa210, "Focal plane resolution unit"), "Maximum lens aperture"),
(SubjectLocation, 0xa214, "Subject location"), (SubjectDistance, 0x9206, DefaultValue::None,
(ExposureIndex, 0xa215, "Exposure index"), "Subject distance"),
(SensingMethod, 0xa217, "Sensing method"), (MeteringMode, 0x9207, DefaultValue::Short(&[0]),
(FileSource, 0xa300, "File source"), "Metering mode"),
(SceneType, 0xa301, "Scene type"), (LightSource, 0x9208, DefaultValue::Short(&[0]),
(CFAPattern, 0xa302, "CFA pattern"), "Light source"),
(CustomRendered, 0xa401, "Custom image processing"), (Flash, 0x9209, DefaultValue::Unspecified,
(ExposureMode, 0xa402, "Exposure mode"), "Flash"),
(WhiteBalance, 0xa403, "White balance"), (FocalLength, 0x920a, DefaultValue::None,
(DigitalZoomRatio, 0xa404, "Digital zoom ratio"), "Lens focal length"),
(FocalLengthIn35mmFilm, 0xa405, "Focal length in 35 mm film"), (SubjectArea, 0x9214, DefaultValue::None,
(SceneCaptureType, 0xa406, "Scene capture type"), "Subject area"),
(GainControl, 0xa407, "Gain control"), (MakerNote, 0x927c, DefaultValue::None,
(Contrast, 0xa408, "Contrast"), "Manufacturer notes"),
(Saturation, 0xa409, "Saturation"), (UserComment, 0x9286, DefaultValue::None,
(Sharpness, 0xa40a, "Sharpness"), "User comments"),
(DeviceSettingDescription, 0xa40b, "Device settings description"), (SubSecTime, 0x9290, DefaultValue::None,
(SubjectDistanceRange, 0xa40c, "Subject distance range"), "DateTime subseconds"),
(ImageUniqueID, 0xa420, "Unique image ID"), (SubSecTimeOriginal, 0x9291, DefaultValue::None,
(CameraOwnerName, 0xa430, "Camera owner name"), "DateTimeOriginal subseconds"),
(BodySerialNumber, 0xa431, "Body serial number"), (SubSecTimeDigitized, 0x9292, DefaultValue::None,
(LensSpecification, 0xa432, "Lens specification"), "DateTimeDigitized subseconds"),
(LensMake, 0xa433, "Lens make"), (Temperature, 0x9400, DefaultValue::None,
(LensModel, 0xa434, "Lens model"), "Temperature"),
(LensSerialNumber, 0xa435, "Lens serial number"), (Humidity, 0x9401, DefaultValue::None,
(Gamma, 0xa500, "Gamma"), "Humidity"),
(Pressure, 0x9402, DefaultValue::None,
"Pressure"),
(WaterDepth, 0x9403, DefaultValue::None,
"Water depth"),
(Acceleration, 0x9404, DefaultValue::None,
"Acceleration"),
(CameraElevationAngle, 0x9405, DefaultValue::None,
"Camera elevation angle"),
(FlashpixVersion, 0xa000, DefaultValue::Undefined(b"0100"),
"Supported Flashpix version"),
(ColorSpace, 0xa001, DefaultValue::Unspecified,
"Color space information"),
(PixelXDimension, 0xa002, DefaultValue::None,
"Valid image width"),
(PixelYDimension, 0xa003, DefaultValue::Unspecified,
"Valid image height"),
(RelatedSoundFile, 0xa004, DefaultValue::None,
"Related audio file"),
(FlashEnergy, 0xa20b, DefaultValue::None,
"Flash energy"),
(SpatialFrequencyResponse, 0xa20c, DefaultValue::None,
"Spatial frequency response"),
(FocalPlaneXResolution, 0xa20e, DefaultValue::None,
"Focal plane X resolution"),
(FocalPlaneYResolution, 0xa20f, DefaultValue::None,
"Focal plane Y resolution"),
(FocalPlaneResolutionUnit, 0xa210, DefaultValue::Short(&[2]),
"Focal plane resolution unit"),
(SubjectLocation, 0xa214, DefaultValue::None,
"Subject location"),
(ExposureIndex, 0xa215, DefaultValue::None,
"Exposure index"),
(SensingMethod, 0xa217, DefaultValue::None,
"Sensing method"),
(FileSource, 0xa300, DefaultValue::Undefined(&[3]),
"File source"),
(SceneType, 0xa301, DefaultValue::Undefined(&[1]),
"Scene type"),
(CFAPattern, 0xa302, DefaultValue::None,
"CFA pattern"),
(CustomRendered, 0xa401, DefaultValue::Short(&[0]),
"Custom image processing"),
(ExposureMode, 0xa402, DefaultValue::None,
"Exposure mode"),
(WhiteBalance, 0xa403, DefaultValue::None,
"White balance"),
(DigitalZoomRatio, 0xa404, DefaultValue::None,
"Digital zoom ratio"),
(FocalLengthIn35mmFilm, 0xa405, DefaultValue::None,
"Focal length in 35 mm film"),
(SceneCaptureType, 0xa406, DefaultValue::Short(&[0]),
"Scene capture type"),
(GainControl, 0xa407, DefaultValue::None,
"Gain control"),
(Contrast, 0xa408, DefaultValue::Short(&[0]),
"Contrast"),
(Saturation, 0xa409, DefaultValue::Short(&[0]),
"Saturation"),
(Sharpness, 0xa40a, DefaultValue::Short(&[0]),
"Sharpness"),
(DeviceSettingDescription, 0xa40b, DefaultValue::None,
"Device settings description"),
(SubjectDistanceRange, 0xa40c, DefaultValue::None,
"Subject distance range"),
(ImageUniqueID, 0xa420, DefaultValue::None,
"Unique image ID"),
(CameraOwnerName, 0xa430, DefaultValue::None,
"Camera owner name"),
(BodySerialNumber, 0xa431, DefaultValue::None,
"Body serial number"),
(LensSpecification, 0xa432, DefaultValue::None,
"Lens specification"),
(LensMake, 0xa433, DefaultValue::None,
"Lens make"),
(LensModel, 0xa434, DefaultValue::None,
"Lens model"),
(LensSerialNumber, 0xa435, DefaultValue::None,
"Lens serial number"),
(Gamma, 0xa500, DefaultValue::None,
"Gamma"),
// GPS attributes [EXIF23 4.6.6 Table 15 and 4.6.8 Table 19]. // GPS attributes [EXIF23 4.6.6 Table 15 and 4.6.8 Table 19].
|Context::Gps| |Context::Gps|
(GPSVersionID, 0x0, "GPS tag version"), // Depends on the Exif version.
(GPSLatitudeRef, 0x1, "North or south latitude"), (GPSVersionID, 0x0, DefaultValue::ContextDependent,
(GPSLatitude, 0x2, "Latitude"), "GPS tag version"),
(GPSLongitudeRef, 0x3, "East or West Longitude"), (GPSLatitudeRef, 0x1, DefaultValue::None,
(GPSLongitude, 0x4, "Longitude"), "North or south latitude"),
(GPSAltitudeRef, 0x5, "Altitude reference"), (GPSLatitude, 0x2, DefaultValue::None,
(GPSAltitude, 0x6, "Altitude"), "Latitude"),
(GPSTimeStamp, 0x7, "GPS time (atomic clock)"), (GPSLongitudeRef, 0x3, DefaultValue::None,
(GPSSatellites, 0x8, "GPS satellites used for measurement"), "East or West Longitude"),
(GPSStatus, 0x9, "GPS receiver status"), (GPSLongitude, 0x4, DefaultValue::None,
(GPSMeasureMode, 0xa, "GPS measurement mode"), "Longitude"),
(GPSDOP, 0xb, "Measurement precision"), (GPSAltitudeRef, 0x5, DefaultValue::Byte(&[0]),
(GPSSpeedRef, 0xc, "Speed unit"), "Altitude reference"),
(GPSSpeed, 0xd, "Speed of GPS receiver"), (GPSAltitude, 0x6, DefaultValue::None,
(GPSTrackRef, 0xe, "Reference for direction of movement"), "Altitude"),
(GPSTrack, 0xf, "Direction of movement"), (GPSTimeStamp, 0x7, DefaultValue::None,
(GPSImgDirectionRef, 0x10, "Reference for direction of image"), "GPS time (atomic clock)"),
(GPSImgDirection, 0x11, "Direction of image"), (GPSSatellites, 0x8, DefaultValue::None,
(GPSMapDatum, 0x12, "Geodetic survey data used"), "GPS satellites used for measurement"),
(GPSDestLatitudeRef, 0x13, "Reference for latitude of destination"), (GPSStatus, 0x9, DefaultValue::None,
(GPSDestLatitude, 0x14, "Latitude of destination"), "GPS receiver status"),
(GPSDestLongitudeRef, 0x15, "Reference for longitude of destination"), (GPSMeasureMode, 0xa, DefaultValue::None,
(GPSDestLongitude, 0x16, "Longitude of destination"), "GPS measurement mode"),
(GPSDestBearingRef, 0x17, "Reference for bearing of destination"), (GPSDOP, 0xb, DefaultValue::None,
(GPSDestBearing, 0x18, "Bearing of destination"), "Measurement precision"),
(GPSDestDistanceRef, 0x19, "Reference for distance to destination"), (GPSSpeedRef, 0xc, DefaultValue::Ascii(&[b"K"]),
(GPSDestDistance, 0x1a, "Distance to destination"), "Speed unit"),
(GPSProcessingMethod, 0x1b, "Name of GPS processing method"), (GPSSpeed, 0xd, DefaultValue::None,
(GPSAreaInformation, 0x1c, "Name of GPS area"), "Speed of GPS receiver"),
(GPSDateStamp, 0x1d, "GPS date"), (GPSTrackRef, 0xe, DefaultValue::Ascii(&[b"T"]),
(GPSDifferential, 0x1e, "GPS differential correction"), "Reference for direction of movement"),
(GPSHPositioningError, 0x1f, "Horizontal positioning error"), (GPSTrack, 0xf, DefaultValue::None,
"Direction of movement"),
(GPSImgDirectionRef, 0x10, DefaultValue::Ascii(&[b"T"]),
"Reference for direction of image"),
(GPSImgDirection, 0x11, DefaultValue::None,
"Direction of image"),
(GPSMapDatum, 0x12, DefaultValue::None,
"Geodetic survey data used"),
(GPSDestLatitudeRef, 0x13, DefaultValue::None,
"Reference for latitude of destination"),
(GPSDestLatitude, 0x14, DefaultValue::None,
"Latitude of destination"),
(GPSDestLongitudeRef, 0x15, DefaultValue::None,
"Reference for longitude of destination"),
(GPSDestLongitude, 0x16, DefaultValue::None,
"Longitude of destination"),
(GPSDestBearingRef, 0x17, DefaultValue::Ascii(&[b"T"]),
"Reference for bearing of destination"),
(GPSDestBearing, 0x18, DefaultValue::None,
"Bearing of destination"),
(GPSDestDistanceRef, 0x19, DefaultValue::Ascii(&[b"K"]),
"Reference for distance to destination"),
(GPSDestDistance, 0x1a, DefaultValue::None,
"Distance to destination"),
(GPSProcessingMethod, 0x1b, DefaultValue::None,
"Name of GPS processing method"),
(GPSAreaInformation, 0x1c, DefaultValue::None,
"Name of GPS area"),
(GPSDateStamp, 0x1d, DefaultValue::None,
"GPS date"),
(GPSDifferential, 0x1e, DefaultValue::None,
"GPS differential correction"),
(GPSHPositioningError, 0x1f, DefaultValue::None,
"Horizontal positioning error"),
// Interoperability attributes [EXIF23 4.6.7 Table 16 and 4.6.8 Table 20]. // Interoperability attributes [EXIF23 4.6.7 Table 16 and 4.6.8 Table 20].
|Context::Interop| |Context::Interop|
(InteroperabilityIndex, 0x1, "Interoperability identification"), (InteroperabilityIndex, 0x1, DefaultValue::None,
"Interoperability identification"),
); );
#[cfg(test)] #[cfg(test)]
@ -342,4 +501,33 @@ mod tests {
_ => panic!("failed to match Tag"), _ => panic!("failed to match Tag"),
} }
} }
#[test]
fn default_value() {
assert_pat!(tag::DateTime.default_value(), None);
match tag::BitsPerSample.default_value() {
Some(Value::Short(v)) => assert_eq!(v, &[8, 8, 8]),
_ => panic!(),
}
match tag::XResolution.default_value() {
Some(Value::Rational(v)) => {
assert_eq!(v.len(), 1);
assert_eq!(v[0].num, 72);
assert_eq!(v[0].denom, 1);
},
_ => panic!(),
}
match tag::FileSource.default_value() {
Some(Value::Undefined(v)) => assert_eq!(v, &[3]),
_ => panic!(),
}
match tag::GPSAltitudeRef.default_value() {
Some(Value::Byte(v)) => assert_eq!(v, &[0]),
_ => panic!(),
}
match tag::GPSSpeedRef.default_value() {
Some(Value::Ascii(v)) => assert_eq!(v, &[b"K"]),
_ => panic!(),
}
}
} }

View File

@ -68,9 +68,43 @@ pub enum Value<'a> {
Unknown(u16, u32, u32), Unknown(u16, u32, u32),
} }
// Static default values.
pub enum DefaultValue {
None,
Byte(&'static [u8]),
Ascii(&'static [&'static [u8]]),
Short(&'static [u16]),
Rational(&'static [(u32, u32)]),
Undefined(&'static [u8]),
// Depends on other tags, JPEG markers, etc.
ContextDependent,
// Unspecified in the Exif standard.
Unspecified,
}
impl<'a> From<&'a DefaultValue> for Option<Value<'a>> {
fn from(defval: &DefaultValue) -> Option<Value> {
match *defval {
DefaultValue::None => None,
DefaultValue::Byte(s) => Some(Value::Byte(s.to_vec())),
DefaultValue::Ascii(s) => Some(Value::Ascii(s.to_vec())),
DefaultValue::Short(s) => Some(Value::Short(s.to_vec())),
DefaultValue::Rational(s) => Some(Value::Rational(
s.iter().map(|&t| tuple2rational(t)).collect())),
DefaultValue::Undefined(s) => Some(Value::Undefined(s)),
DefaultValue::ContextDependent => None,
DefaultValue::Unspecified => None,
}
}
}
/// An unsigned rational number, which is a pair of 32-bit unsigned integers. /// An unsigned rational number, which is a pair of 32-bit unsigned integers.
pub struct Rational { pub num: u32, pub denom: u32 } pub struct Rational { pub num: u32, pub denom: u32 }
fn tuple2rational(t: (u32, u32)) -> Rational {
Rational { num: t.0, denom: t.1 }
}
impl fmt::Debug for Rational { impl fmt::Debug for Rational {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Rational({}/{})", self.num, self.denom) write!(f, "Rational({}/{})", self.num, self.denom)