Skip to content

Commit 4b95f8e

Browse files
committed
exif: implement reading user-defined EXIF tags from files
1 parent 789b601 commit 4b95f8e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/common/exif.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,52 @@ static bool _exif_decode_exif_data(dt_image_t *img, Exiv2::ExifData &exifData)
23522352
}
23532353
};
23542354

2355+
dt_pthread_mutex_lock(&darktable.metadata_threadsafe);
2356+
for(GList *iter = dt_metadata_get_list(); iter; iter = iter->next)
2357+
{
2358+
dt_metadata_t *metadata = (dt_metadata_t *)iter->data;
2359+
if(!FIND_EXIF_TAG(metadata->tagname))
2360+
{
2361+
continue;
2362+
}
2363+
2364+
int ival = pos->toLong();
2365+
std::string str = pos->print(&exifData);
2366+
char *value = g_locale_to_utf8(str.c_str(), str.length(), NULL, NULL, NULL);
2367+
if(value == NULL)
2368+
{
2369+
// need non-const char* for g_strstrip
2370+
value = g_strdup(str.c_str());
2371+
}
2372+
g_strstrip(value);
2373+
2374+
gchar *str_value = g_strdup_printf("(%d)", ival);
2375+
if(g_strcmp0(value, str_value) == 0)
2376+
{
2377+
// no string mapping available in exiv2, so we use exiv2's
2378+
// default string conversion.
2379+
g_free(value);
2380+
str = pos->toString();
2381+
// for consistency with the handling above. don't want to mix two
2382+
// allocators, that causes me headaches.
2383+
value = g_strdup(str.c_str());
2384+
// no need to keep this around for longer.
2385+
str = nullptr;
2386+
}
2387+
g_free(str_value);
2388+
2389+
char *adr = value;
2390+
// Skip any lang="" or charset=xxx
2391+
while(!strncmp(value, "lang=", 5) || !strncmp(value, "charset=", 8))
2392+
{
2393+
while(*value != ' ' && *value) value++;
2394+
while(*value == ' ') value++;
2395+
}
2396+
dt_metadata_set_import(img->id, metadata->tagname, value);
2397+
g_free(adr);
2398+
}
2399+
dt_pthread_mutex_unlock(&darktable.metadata_threadsafe);
2400+
23552401
img->exif_inited = TRUE;
23562402
return true;
23572403
}

0 commit comments

Comments
 (0)