From 561e801c88b3b97f8f4ade73cc9fa6dca1ba880c Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Sun, 23 Jul 2017 21:43:02 +0900 Subject: [PATCH] Stringify GPS directions (N/W/S/E) as unquoted. --- src/tag.rs | 21 ++++++++++++++++----- src/util.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/tag.rs b/src/tag.rs index c57f2bb..1c0665e 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -28,7 +28,7 @@ use std::fmt; use value; use value::Value; -use util::atou16; +use util::{atou16, isupper}; /// A tag of a TIFF field. // @@ -434,11 +434,11 @@ generate_well_known_tag_constants!( // Depends on the Exif version. (GPSVersionID, 0x0, DefaultValue::ContextDependent, d_gpsver, "GPS tag version"), - (GPSLatitudeRef, 0x1, DefaultValue::None, d_default, + (GPSLatitudeRef, 0x1, DefaultValue::None, d_gpslatlongref, "North or south latitude"), (GPSLatitude, 0x2, DefaultValue::None, d_gpsdms, "Latitude"), - (GPSLongitudeRef, 0x3, DefaultValue::None, d_default, + (GPSLongitudeRef, 0x3, DefaultValue::None, d_gpslatlongref, "East or West Longitude"), (GPSLongitude, 0x4, DefaultValue::None, d_gpsdms, "Longitude"), @@ -470,11 +470,11 @@ generate_well_known_tag_constants!( "Direction of image"), (GPSMapDatum, 0x12, DefaultValue::None, d_default, "Geodetic survey data used"), - (GPSDestLatitudeRef, 0x13, DefaultValue::None, d_default, + (GPSDestLatitudeRef, 0x13, DefaultValue::None, d_gpslatlongref, "Reference for latitude of destination"), (GPSDestLatitude, 0x14, DefaultValue::None, d_gpsdms, "Latitude of destination"), - (GPSDestLongitudeRef, 0x15, DefaultValue::None, d_default, + (GPSDestLongitudeRef, 0x15, DefaultValue::None, d_gpslatlongref, "Reference for longitude of destination"), (GPSDestLongitude, 0x16, DefaultValue::None, d_gpsdms, "Longitude of destination"), @@ -1023,6 +1023,17 @@ fn d_gpsver(w: &mut fmt::Write, value: &Value) -> fmt::Result { } } +// GPSLatitudeRef (Exif/GPS 0x1), GPSLongitudeRef (Exif/GPS 0x3) +// GPSDestLatitudeRef (Exif/GPS 0x13), GPSDestLongitudeRef (Exif/GPS 0x15) +fn d_gpslatlongref(w: &mut fmt::Write, value: &Value) -> fmt::Result { + match *value { + Value::Ascii(ref v) if (v.len() == 1 && v[0].len() == 1 && + isupper(v[0][0])) => + w.write_char(v[0][0] as char), + _ => d_default(w, value), + } +} + // GPSLatitude (Exif/GPS 0x2), GPSLongitude (Exif 0x4), // GPSDestLatitude (Exif/GPS 0x14), GPSDestLongitude (Exif 0x16) fn d_gpsdms(w: &mut fmt::Write, value: &Value) -> fmt::Result { diff --git a/src/util.rs b/src/util.rs index f549c8a..41e7b19 100644 --- a/src/util.rs +++ b/src/util.rs @@ -28,6 +28,9 @@ use std::io; use error::Error; +const ASCII_A: u8 = 0x41; +const ASCII_Z: u8 = 0x5a; + pub fn read8(reader: &mut R) -> Result where R: io::Read { let mut buf: [u8; 1] = unsafe { ::std::mem::uninitialized() }; reader.read_exact(&mut buf).and(Ok(buf[0])) @@ -60,6 +63,10 @@ pub fn atou16(bytes: &[u8]) -> Result { Ok(n) } +pub fn isupper(c: u8) -> bool { + ASCII_A <= c && c <= ASCII_Z +} + #[cfg(test)] mod tests { use std::io::Cursor; @@ -105,4 +112,13 @@ mod tests { assert_err_pat!(atou16(b":"), Error::InvalidFormat(_)); assert_err_pat!(atou16(b"-1"), Error::InvalidFormat(_)); } + + #[test] + fn isupper() { + assert!(super::isupper(b'A')); + assert!(super::isupper(b'Z')); + assert!(!super::isupper(b'A' - 1)); + assert!(!super::isupper(b'Z' + 1)); + assert!(!super::isupper(b'a')); + } }