]>
git.datanom.net - lensdb.git/blob - lib/main.cpp
7 static const char* LensMakers
[] = {
24 "Meyer Optik Görlitz",
29 "OM Digital Solutions",
35 "Schneider Kreuznach",
40 "Schneider Kreuznach",
53 static void print_all(gpointer key
, gpointer value
, gpointer user_data
) {
54 cout
<< (gchar
*)key
<< " = " << (gchar
*)value
<< endl
;
57 ExifScanner::ExifScanner(const char* file
): file(file
) {
58 exif_tags
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
59 get_data_from_image();
62 ExifScanner::~ExifScanner() {
63 g_hash_table_destroy(exif_tags
);
66 std::string
ExifScanner::get_error() {
70 void ExifScanner::get_data_from_image() {
72 // create our ExifTool object
73 ExifTool
*et
= new ExifTool();
74 // read metadata from the image
75 TagInfo
*info
= et
->ImageInfo(file
);
77 // print returned information
78 for (TagInfo
*i
=info
; i
; i
=i
->next
) {
79 g_hash_table_insert(exif_tags
, g_strdup(i
->name
), g_strdup(i
->value
));
81 // we are responsible for deleting the information when done
83 } else if (et
->LastComplete() <= 0) {
84 error
= "Error executing exiftool!";
86 // print exiftool stderr messages
87 char *err
= et
->GetError();
92 delete et
; // delete our ExifTool object
96 string
ExifScanner::get_maker() {
99 //g_hash_table_foreach(exif_tags, print_all, NULL);
100 gchar
* lensId
= g_strdup((gchar
*)g_hash_table_lookup(exif_tags
, "LensMake"));
101 gulong len
= char_len(lensId
);
102 if (!lensId
|| g_strcmp0("Unknown (2822)", lensId
) == 0 || len
< 1) {
103 const gchar
* s
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensID");
104 if (s
&& g_strcmp0("Unknown (2822)", s
) != 0) {
105 gchar
* pos
= g_strstr_len(s
, -1, " ");
106 //cout << pos << endl;
108 //cout << "S length: " << strlen(s) << "POS length: " << strlen(pos) << endl;
110 lensId
= g_strndup(s
, strlen(s
) - strlen(pos
));
112 len
= g_utf8_strlen(lensId
, -1);
116 if (match_maker(lensId
) == false) {
121 if (!lensId
|| g_strcmp0("Unknown (2822)", lensId
) == 0 || len
< 1) {
122 const gchar
* s
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensModel");
124 gchar
* pos
= g_strstr_len(s
, -1, " ");
125 //cout << pos << endl;
127 //cout << "S length: " << strlen(s) << "POS length: " << strlen(pos) << endl;
129 lensId
= g_strndup(s
, strlen(s
) - strlen(pos
));
130 len
= char_len(lensId
);
135 if (match_maker(lensId
) == false) {
140 if (!lensId
|| len
< 1)
141 maker
= get_cstring("Unknown");
143 maker
= get_cstring(lensId
);
149 string
ExifScanner::get_serial_number() {
152 const gchar
* id
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensSerialNumber");
153 gulong len
= char_len(id
);
154 if (!id
|| len
< 1) {
155 id
= (gchar
*)g_hash_table_lookup(exif_tags
, "SerialNumber");
160 sn
= get_cstring("Unknown");
162 sn
= get_cstring(id
);
167 string
ExifScanner::get_lens() {
170 const gchar
* lensId
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensID");
171 gulong len
= char_len(lensId
);
172 if (!lensId
|| g_strcmp0("Unknown (2822)", lensId
) == 0 || len
< 1) {
173 lensId
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensModel");
174 len
= char_len(lensId
);
175 if (!lensId
|| g_strcmp0("Unknown (2822)", lensId
) == 0 || len
< 1) {
176 lensId
= (gchar
*)g_hash_table_lookup(exif_tags
, "LensSpec");
177 len
= char_len(lensId
);
181 if (!lensId
|| g_strcmp0("Unknown (2822)", lensId
) == 0 || len
< 1)
182 lens
= get_cstring("Unknown");
184 lens
= get_cstring(lensId
);
189 gchar
* ExifScanner::get_cstring(string s
) {
190 gchar
* cstring
= g_strdup(s
.c_str());
195 bool ExifScanner::match_maker(const gchar
* maker
) {
197 const char* lensmaker
= NULL
;
199 if (maker
== NULL
) return false;
201 lensmaker
= LensMakers
[i
];
203 if (g_ascii_strcasecmp(lensmaker
, maker
) == 0) {
207 lensmaker
= LensMakers
[i
];
213 gulong
ExifScanner::char_len(const gchar
* elem
) {
216 return g_utf8_strlen(elem
, -1);
This page took 0.962583 seconds and 6 git commands to generate.