1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2010 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <exiv2/image.hpp>
#include <exiv2/exif.hpp>
#include <iostream>
#include <iomanip>
#if EXIV2_MAJOR_VERSION >= 1 || (EXIV2_MAJOR_VERSION == 0 && EXIV2_MINOR_VERSION >= 27)
#define HAVE_EXIV2_ERROR_CODE
#endif
int
main (int argc, char* const argv[])
{
Exiv2::Image::AutoPtr image;
Exiv2::ExifData exifData;
std::string filename;
std::string make;
std::string model;
std::string serial;
int i;
int retval = 0;
const char *temp[] = {
"Exif.Canon.SerialNumber",
"Exif.Fujifilm.SerialNumber",
"Exif.Nikon3.SerialNO",
"Exif.Nikon3.SerialNumber",
"Exif.OlympusEq.InternalSerialNumber",
"Exif.OlympusEq.SerialNumber",
"Exif.Olympus.SerialNumber2",
"Exif.Sigma.SerialNumber",
NULL };
try {
/* open file */
if (argc == 2)
filename = argv[1];
if (filename.empty())
#ifdef HAVE_EXIV2_ERROR_CODE
throw Exiv2::Error(Exiv2::kerErrorMessage, "No filename specified");
#else
throw Exiv2::Error(1, "No filename specified");
#endif
image = Exiv2::ImageFactory::open(filename);
image->readMetadata();
/* get exif data */
exifData = image->exifData();
if (exifData.empty()) {
std::string error(argv[1]);
error += ": No Exif data found in the file";
#ifdef HAVE_EXIV2_ERROR_CODE
throw Exiv2::Error(Exiv2::kerErrorMessage, error);
#else
throw Exiv2::Error(1, error);
#endif
}
/* try to find make, model and serial number */
make = exifData["Exif.Image.Make"].toString();
model = exifData["Exif.Image.Model"].toString();
for (i=0; temp[i] != NULL; i++) {
if (exifData[temp[i]].idx())
serial = exifData[temp[i]].toString();
if (!serial.empty())
break;
}
std::cout << model << "\n";
std::cout << make << "\n";
std::cout << serial << "\n";
} catch (Exiv2::AnyError& e) {
std::cout << "Failed to load: " << e << "\n";
retval = -1;
}
return retval;
}
|