1
|
/*
|
2
|
* main.cpp
|
3
|
*
|
4
|
* Created on: Sep 15, 2011
|
5
|
* Author: sasha
|
6
|
*/
|
7
|
|
8
|
#include "image.hpp"
|
9
|
#include "exif.hpp"
|
10
|
#include <math.h>
|
11
|
#include <stdio.h>
|
12
|
#include <iostream>
|
13
|
|
14
|
|
15
|
int main(int argc, char **argv)
|
16
|
{
|
17
|
std::string filename;
|
18
|
if (argc == 1)
|
19
|
{
|
20
|
std::cout << "usage: input filename\n";
|
21
|
return -1;
|
22
|
}
|
23
|
else
|
24
|
{
|
25
|
filename = argv[1];
|
26
|
}
|
27
|
std::cout << "start program\n",fflush(0);
|
28
|
|
29
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
|
30
|
Exiv2::ExifData exifData;
|
31
|
double latitude = 50.236;
|
32
|
double longitude = -43.236;
|
33
|
char scratchBufLatitude[100];
|
34
|
long int degLatitude, minLatitude, secLatitude;
|
35
|
char scratchBufLongitude[100];
|
36
|
long int degLongitude, minLongitude, secLongitude;
|
37
|
|
38
|
if ( exifData.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID")) == exifData.end())
|
39
|
{
|
40
|
Exiv2::Value::AutoPtr value = Exiv2::Value::create(Exiv2::unsignedByte);
|
41
|
value->read("2 0 0 0");
|
42
|
exifData.add(Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID"), value.get());
|
43
|
exifData["Exif.GPSInfo.GPSMapDatum"] = "WGS-84";
|
44
|
}
|
45
|
|
46
|
exifData["Exif.GPSInfo.GPSLatitudeRef"] = (latitude < 0 ) ? "S" : "N";
|
47
|
degLatitude = (int)floor(fabs(latitude));
|
48
|
minLatitude = (int)floor((fabs(latitude) - degLatitude)*60);
|
49
|
secLatitude = (int)floor(((fabs(latitude) - degLatitude)*60 - minLatitude )*60);
|
50
|
snprintf(scratchBufLatitude, 100, "%ld/1 %ld/1 %ld/1", degLatitude, minLatitude, secLatitude);
|
51
|
exifData["Exif.GPSInfo.GPSLatitude"] = scratchBufLatitude;
|
52
|
|
53
|
exifData["Exif.GPSInfo.GPSLongitudeRef"] = (longitude < 0 ) ? "W" : "E";
|
54
|
degLongitude = (int)floor(fabs(longitude));
|
55
|
minLongitude = (int)floor((fabs(longitude) - degLongitude)*60);
|
56
|
secLongitude = (int)floor(((fabs(longitude) - degLongitude)*60 - minLongitude )*60);
|
57
|
snprintf(scratchBufLongitude, 100, "%ld/1 %ld/1 %ld/1", degLongitude, minLongitude, secLongitude);
|
58
|
exifData["Exif.GPSInfo.GPSLongitude"] = scratchBufLongitude;
|
59
|
|
60
|
image->setExifData(exifData);
|
61
|
image->writeMetadata();
|
62
|
|
63
|
Exiv2::ExifMetadata::iterator it = exifData.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID"));
|
64
|
if ( it != exifData.end())
|
65
|
{
|
66
|
std::ostringstream out;
|
67
|
out << exifData.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSLatitudeRef"))->value().toString() << " ";
|
68
|
Exiv2::ExifMetadata::iterator itL = exifData.findKey(Exiv2::ExifKey("Exif.GPSInfo.GPSLatitude"));
|
69
|
out << itL->value().toFloat(0) << "deg " << itL->value().toFloat(1) << "' " << itL->value().toFloat(2) << "\"";
|
70
|
|
71
|
std::cout << "writed Latitude: " << out.str() << "\n", fflush(0);
|
72
|
}
|
73
|
else
|
74
|
{
|
75
|
std::cout << "GPS tag is empty\n", fflush(0);
|
76
|
}
|
77
|
std::cout << "all OK\n", fflush(0);
|
78
|
return 0;
|
79
|
}
|