Skip to main content

simp_rexif/
exifpost.rs

1use super::types::{ExifEntry, ExifTag, TagValue};
2
3/// Find a tag of given type
4fn other_tag<'a>(tag: ExifTag, entries1: &'a [ExifEntry], entries2: &'a [ExifEntry]) -> Option<&'a ExifEntry> {
5    entries1.iter().find(|entry| entry.tag == tag)
6    .or_else(|| entries2.iter().find(|entry| entry.tag == tag))
7}
8
9/// Does postprocessing in tags that depend on other tags to have a complete interpretation
10/// e.g. when the unit of a tag is annotated on another tag
11pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry], entries2: &[ExifEntry]) {
12    match entry.tag {
13        ExifTag::XResolution | ExifTag::YResolution => {
14            if let Some(f) = other_tag(ExifTag::ResolutionUnit, entries1, entries2) {
15                entry.unit = f.value_more_readable.clone();
16                let v = entry.value_more_readable.to_mut();
17                v.push_str(" pixels per ");
18                v.push_str(&f.value_more_readable);
19            }
20        },
21
22        ExifTag::FocalPlaneXResolution | ExifTag::FocalPlaneYResolution => {
23            if let Some(f) = other_tag(ExifTag::FocalPlaneResolutionUnit, entries1, entries2) {
24                entry.unit = f.value_more_readable.clone();
25                let v = entry.value_more_readable.to_mut();
26                v.push_str(" pixels per ");
27                v.push_str(&f.value_more_readable);
28            }
29        },
30
31        ExifTag::GPSLatitude => {
32            if let Some(f) = other_tag(ExifTag::GPSLatitudeRef, entries1, entries2) {
33                let v = entry.value_more_readable.to_mut();
34                v.push(' ');
35                v.push_str(&f.value_more_readable);
36            }
37        },
38
39        ExifTag::GPSLongitude => {
40            if let Some(f) = other_tag(ExifTag::GPSLongitudeRef, entries1, entries2) {
41                let v = entry.value_more_readable.to_mut();
42                v.push(' ');
43                v.push_str(&f.value_more_readable);
44            }
45        },
46
47        ExifTag::GPSAltitude => {
48            if let Some(f) = other_tag(ExifTag::GPSAltitudeRef, entries1, entries2) {
49                let altref = match f.value {
50                    TagValue::U8(ref fv) => fv[0],
51                    _ => return,
52                };
53
54                if altref != 0 {
55                    entry.value_more_readable.to_mut().push_str(" below sea level");
56                }
57            }
58        },
59
60        ExifTag::GPSDestLatitude => {
61            if let Some(f) = other_tag(ExifTag::GPSDestLatitudeRef, entries1, entries2) {
62                let v = entry.value_more_readable.to_mut();
63                v.push(' ');
64                v.push_str(&f.value_more_readable);
65            }
66        },
67
68        ExifTag::GPSDestLongitude => {
69            if let Some(f) = other_tag(ExifTag::GPSDestLongitudeRef, entries1, entries2) {
70                let v = entry.value_more_readable.to_mut();
71                v.push(' ');
72                v.push_str(&f.value_more_readable);
73            }
74        },
75
76        ExifTag::GPSDestDistance => {
77            if let Some(f) = other_tag(ExifTag::GPSDestDistanceRef, entries1, entries2) {
78                entry.unit = f.value_more_readable.clone();
79                let v = entry.value_more_readable.to_mut();
80                v.push(' ');
81                v.push_str(&f.value_more_readable);
82            }
83        },
84
85        ExifTag::GPSSpeed => {
86            if let Some(f) = other_tag(ExifTag::GPSSpeedRef, entries1, entries2) {
87                entry.unit = f.value_more_readable.clone();
88                let v = entry.value_more_readable.to_mut();
89                v.push(' ');
90                v.push_str(&f.value_more_readable);
91            }
92        },
93        _ => (),
94    }
95}