Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
exif-wrapper.cpp
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2014-2015 Edouard Gomez.
4 Copyright (C) 2019 Bertrand Antoine.
5 Copyright (C) 2023 Alynx Zhou.
6
7 darktable is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 darktable is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with darktable. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include <exiv2/exif.hpp>
22#include <exiv2/error.hpp>
23#include <exiv2/image.hpp>
24#include <exiv2/version.hpp>
25
26#include <cstdio>
27#include <cassert>
28
29using namespace std;
30
31extern "C" int
33 const char* filename,
34 const char* key,
35 char* buf,
36 size_t buflen)
37{
38 int ret = -1;
39
40 try
41 {
42#if EXIV2_TEST_VERSION(0,28,0)
43 Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(filename);
44#else
45 Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
46#endif
47 assert(image.get() != 0);
48 image->readMetadata();
49
50 Exiv2::ExifData &exifData = image->exifData();
51
52#if EXIV2_TEST_VERSION(0,28,0)
53 Exiv2::Value::UniquePtr val = exifData[key].getValue();
54#else
55 Exiv2::Value::AutoPtr val = exifData[key].getValue();
56#endif
57
58 if (val->typeId() != Exiv2::asciiString)
59 {
60 ret = -1;
61 goto exit;
62 }
63
64 if ((size_t)val->size() >= buflen)
65 {
66 ret = val->size()+1;
67 goto exit;
68 }
69
70 snprintf(buf, buflen, "%s", val->toString().c_str());
71
72 ret = 0;
73 }
74 catch (Exiv2::Error& e)
75 {
76 ret = -1;
77 }
78
79exit:
80
81 return ret;
82}
83
char * key
int exif_get_ascii_datafield(const char *filename, const char *key, char *buf, size_t buflen)