Stringify GPS directions (N/W/S/E) as unquoted.
This commit is contained in:
parent
fab83f512f
commit
561e801c88
21
src/tag.rs
21
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 {
|
||||
|
|
16
src/util.rs
16
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<R>(reader: &mut R) -> Result<u8, io::Error> 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<u16, Error> {
|
|||
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'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue