Skip to content

Commit 6438305

Browse files
authored
Merge pull request #2212 from neheb/1
1
2 parents d466c1e + bd1758c commit 6438305

24 files changed

+168
-169
lines changed

app/actions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ int Print::printTag(const Exiv2::ExifData& exifData, const std::string& key, con
331331
return rc;
332332
} // Print::printTag
333333

334-
int Print::printTag(const Exiv2::ExifData& exifData, EasyAccessFct easyAccessFct, const std::string& label,
335-
EasyAccessFct easyAccessFctFallback) const {
334+
int Print::printTag(const Exiv2::ExifData& exifData, const EasyAccessFct& easyAccessFct, const std::string& label,
335+
const EasyAccessFct& easyAccessFctFallback) const {
336336
int rc = 0;
337337
if (!label.empty()) {
338338
printLabel(label);

app/actions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ class Print : public Task {
155155
*/
156156
int printTag(const Exiv2::ExifData& exifData, const std::string& key, const std::string& label = "") const;
157157
//! Type for an Exiv2 Easy access function
158-
using EasyAccessFct = Exiv2::ExifData::const_iterator (*)(const Exiv2::ExifData& ed);
158+
using EasyAccessFct = std::function<Exiv2::ExifData::const_iterator(const Exiv2::ExifData& ed)>;
159159
/*!
160160
@brief Print one summary line with a label (if provided) and requested
161161
data. A line break is printed only if a label is provided.
162162
@return 1 if a line was written, 0 if the information was not found.
163163
*/
164-
int printTag(const Exiv2::ExifData& exifData, EasyAccessFct easyAccessFct, const std::string& label = "",
165-
EasyAccessFct easyAccessFctFallback = nullptr) const;
164+
int printTag(const Exiv2::ExifData& exifData, const EasyAccessFct& easyAccessFct, const std::string& label = "",
165+
const EasyAccessFct& easyAccessFctFallback = nullptr) const;
166166

167167
private:
168168
std::string path_;

include/exiv2/bmffimage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class EXIV2API BmffImage : public Image {
122122
@return address of next box
123123
@warning This function should only be called by readMetadata()
124124
*/
125-
long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, const long pbox_end, int depth);
125+
long boxHandler(std::ostream& out, Exiv2::PrintStructureOption option, long pbox_end, int depth);
126126
[[nodiscard]] static std::string indent(int i) {
127127
return std::string(2 * i, ' ');
128128
}

include/exiv2/photoshop.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ struct EXIV2API Photoshop {
4747
/// @return 0 if successful;<BR>
4848
/// 3 if no data for psTag was found in pPsData;<BR>
4949
/// -2 if the pPsData buffer does not contain valid data.
50-
static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record,
51-
uint32_t* const sizeHdr, uint32_t* const sizeData);
50+
static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record, uint32_t& sizeHdr,
51+
uint32_t& sizeData);
5252

5353
/// @brief Forwards to locateIrb() with \em psTag = \em iptc_
54-
static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
55-
uint32_t* const sizeData);
54+
static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr,
55+
uint32_t& sizeData);
5656

5757
/// @brief Forwards to locatePreviewIrb() with \em psTag = \em preview_
58-
static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t* const sizeHdr,
59-
uint32_t* const sizeData);
58+
static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr,
59+
uint32_t& sizeData);
6060

6161
/// @brief Set the new IPTC IRB, keeps existing IRBs but removes the IPTC block if there is no new IPTC data to write.
6262
/// @param pPsData Existing IRB buffer

samples/easyaccess-test.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,46 @@
55
#include <iomanip>
66
#include <iostream>
77

8-
using EasyAccessFct = Exiv2::ExifData::const_iterator (*)(const Exiv2::ExifData&);
8+
using EasyAccessFct = std::function<Exiv2::ExifData::const_iterator(const Exiv2::ExifData&)>;
9+
using EasyAccess = std::pair<const char*, EasyAccessFct>;
910

10-
struct EasyAccess {
11-
const char* label_;
12-
EasyAccessFct findFct_;
11+
static const EasyAccess easyAccess[] = {
12+
{"Orientation", Exiv2::orientation},
13+
{"ISO speed", Exiv2::isoSpeed},
14+
{"Date & time original", Exiv2::dateTimeOriginal},
15+
{"Flash bias", Exiv2::flashBias},
16+
{"Exposure mode", Exiv2::exposureMode},
17+
{"Scene mode", Exiv2::sceneMode},
18+
{"Macro mode", Exiv2::macroMode},
19+
{"Image quality", Exiv2::imageQuality},
20+
{"White balance", Exiv2::whiteBalance},
21+
{"Lens name", Exiv2::lensName},
22+
{"Saturation", Exiv2::saturation},
23+
{"Sharpness", Exiv2::sharpness},
24+
{"Contrast", Exiv2::contrast},
25+
{"Scene capture type", Exiv2::sceneCaptureType},
26+
{"Metering mode", Exiv2::meteringMode},
27+
{"Camera make", Exiv2::make},
28+
{"Camera model", Exiv2::model},
29+
{"Exposure time", Exiv2::exposureTime},
30+
{"FNumber", Exiv2::fNumber},
31+
{"Shutter speed value", Exiv2::shutterSpeedValue},
32+
{"Aperture value", Exiv2::apertureValue},
33+
{"Brightness value", Exiv2::brightnessValue},
34+
{"Exposure bias", Exiv2::exposureBiasValue},
35+
{"Max aperture value", Exiv2::maxApertureValue},
36+
{"Subject distance", Exiv2::subjectDistance},
37+
{"Light source", Exiv2::lightSource},
38+
{"Flash", Exiv2::flash},
39+
{"Camera serial number", Exiv2::serialNumber},
40+
{"Focal length", Exiv2::focalLength},
41+
{"Subject location/area", Exiv2::subjectArea},
42+
{"Flash energy", Exiv2::flashEnergy},
43+
{"Exposure index", Exiv2::exposureIndex},
44+
{"Sensing method", Exiv2::sensingMethod},
45+
{"AF point", Exiv2::afPoint},
1346
};
1447

15-
static const EasyAccess easyAccess[] = {{"Orientation", Exiv2::orientation},
16-
{"ISO speed", Exiv2::isoSpeed},
17-
{"Date & time original", Exiv2::dateTimeOriginal},
18-
{"Flash bias", Exiv2::flashBias},
19-
{"Exposure mode", Exiv2::exposureMode},
20-
{"Scene mode", Exiv2::sceneMode},
21-
{"Macro mode", Exiv2::macroMode},
22-
{"Image quality", Exiv2::imageQuality},
23-
{"White balance", Exiv2::whiteBalance},
24-
{"Lens name", Exiv2::lensName},
25-
{"Saturation", Exiv2::saturation},
26-
{"Sharpness", Exiv2::sharpness},
27-
{"Contrast", Exiv2::contrast},
28-
{"Scene capture type", Exiv2::sceneCaptureType},
29-
{"Metering mode", Exiv2::meteringMode},
30-
{"Camera make", Exiv2::make},
31-
{"Camera model", Exiv2::model},
32-
{"Exposure time", Exiv2::exposureTime},
33-
{"FNumber", Exiv2::fNumber},
34-
{"Shutter speed value", Exiv2::shutterSpeedValue},
35-
{"Aperture value", Exiv2::apertureValue},
36-
{"Brightness value", Exiv2::brightnessValue},
37-
{"Exposure bias", Exiv2::exposureBiasValue},
38-
{"Max aperture value", Exiv2::maxApertureValue},
39-
{"Subject distance", Exiv2::subjectDistance},
40-
{"Light source", Exiv2::lightSource},
41-
{"Flash", Exiv2::flash},
42-
{"Camera serial number", Exiv2::serialNumber},
43-
{"Focal length", Exiv2::focalLength},
44-
{"Subject location/area", Exiv2::subjectArea},
45-
{"Flash energy", Exiv2::flashEnergy},
46-
{"Exposure index", Exiv2::exposureIndex},
47-
{"Sensing method", Exiv2::sensingMethod},
48-
{"AF point", Exiv2::afPoint}};
49-
5048
int main(int argc, char** argv) {
5149
try {
5250
Exiv2::XmpParser::initialize();
@@ -64,9 +62,9 @@ int main(int argc, char** argv) {
6462
image->readMetadata();
6563
Exiv2::ExifData& ed = image->exifData();
6664

67-
for (auto&& ea : easyAccess) {
68-
auto pos = ea.findFct_(ed);
69-
std::cout << std::setw(21) << std::left << ea.label_;
65+
for (auto&& [label, fct] : easyAccess) {
66+
auto pos = fct(ed);
67+
std::cout << std::setw(21) << std::left << label;
7068
if (pos != ed.end()) {
7169
std::cout << " (" << std::setw(35) << pos->key() << ") : " << pos->print(&ed) << "\n";
7270
} else {

samples/largeiptc-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(int argc, char* const argv[]) {
5252
const Exiv2::byte* record;
5353
uint32_t sizeHdr = 0;
5454
uint32_t sizeData = 0;
55-
Exiv2::Photoshop::locateIptcIrb(irb.data(), irb.size(), &record, &sizeHdr, &sizeData);
55+
Exiv2::Photoshop::locateIptcIrb(irb.data(), irb.size(), &record, sizeHdr, sizeData);
5656
Exiv2::DataBuf rawIptc = Exiv2::IptcParser::encode(iptcData);
5757
std::cout << "Comparing IPTC and IRB size... ";
5858
if (static_cast<uint32_t>(rawIptc.size()) != sizeData) {

src/bmffimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ std::string BmffImage::uuidName(Exiv2::DataBuf& uuid) {
153153
}
154154

155155
long BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStructureOption option /* = kpsNone */,
156-
const long pbox_end, int depth) {
156+
long pbox_end, int depth) {
157157
long address = io_->tell();
158158
// never visit a box twice!
159159
if (depth == 0)

src/iptc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ int IptcParser::decode(IptcData& iptcData, const byte* pData, size_t size) {
363363
#ifdef EXIV2_DEBUG_MESSAGES
364364
std::cerr << "IptcParser::decode, size = " << size << "\n";
365365
#endif
366-
const byte* pRead = pData;
367-
const byte* const pEnd = pData + size;
366+
auto pRead = pData;
367+
const auto pEnd = pData + size;
368368
iptcData.clear();
369369

370370
uint16_t record = 0;

src/jpgimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void JpegBase::readMetadata() {
264264
uint32_t sizeHdr = 0;
265265
const byte* pCur = &psBlob[0];
266266
const byte* pEnd = pCur + psBlob.size();
267-
while (pCur < pEnd && 0 == Photoshop::locateIptcIrb(pCur, pEnd - pCur, &record, &sizeHdr, &sizeIptc)) {
267+
while (pCur < pEnd && 0 == Photoshop::locateIptcIrb(pCur, pEnd - pCur, &record, sizeHdr, sizeIptc)) {
268268
#ifdef EXIV2_DEBUG_MESSAGES
269269
std::cerr << "Found IPTC IRB, size = " << sizeIptc << "\n";
270270
#endif

src/makernote_int.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace fs = std::filesystem;
3737
namespace {
3838
// Todo: Can be generalized further - get any tag as a string/long/...
3939
//! Get the Value for a tag within a particular group
40-
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* const pRoot, const uint16_t& tag,
40+
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag,
4141
const Exiv2::Internal::IfdId& group);
4242
//! Get the model name from tag Exif.Image.Model
4343
std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot);
@@ -884,7 +884,7 @@ constexpr auto nikonArrayIdx = std::array{
884884
NikonArrayIdx{0x00b7, "0101", 84, 1, NA}, // tag 0xb7 in sample image metadata for each version
885885
};
886886

887-
int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* const /*pRoot*/) {
887+
int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* /*pRoot*/) {
888888
if (size < 4)
889889
return -1;
890890

@@ -896,7 +896,7 @@ int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* c
896896
return it->idx_;
897897
}
898898

899-
DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* const pRoot) {
899+
DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* pRoot) {
900900
DataBuf buf;
901901

902902
if (size < 4)
@@ -938,7 +938,7 @@ DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent*
938938
return buf;
939939
}
940940

941-
int sonyCsSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) {
941+
int sonyCsSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
942942
std::string model = getExifModel(pRoot);
943943
if (model.empty())
944944
return -1;
@@ -948,7 +948,7 @@ int sonyCsSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, Tif
948948
}
949949
return idx;
950950
}
951-
int sony2010eSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) {
951+
int sony2010eSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
952952
static constexpr auto models = std::array{
953953
"SLT-A58", "SLT-A99", "ILCE-3000", "ILCE-3500", "NEX-3N", "NEX-5R", "NEX-5T",
954954
"NEX-6", "VG30E", "VG900", "DSC-RX100", "DSC-RX1", "DSC-RX1R", "DSC-HX300",
@@ -957,14 +957,14 @@ int sony2010eSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/,
957957
return std::find(models.begin(), models.end(), getExifModel(pRoot)) != models.end() ? 0 : -1;
958958
}
959959

960-
int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) {
960+
int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
961961
// Not valid for models beginning
962962
std::string model = getExifModel(pRoot);
963963
const std::array strs{"SLT-", "HV", "ILCA-"};
964964
return std::any_of(strs.begin(), strs.end(), [&model](auto& m) { return startsWith(model, m); }) ? -1 : 0;
965965
}
966966

967-
int sonyMisc2bSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) {
967+
int sonyMisc2bSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
968968
// From Exiftool: https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Sony.pm
969969
// > First byte must be 9 or 12 or 13 or 15 or 16 and 4th byte must be 2 (deciphered)
970970

@@ -991,7 +991,7 @@ int sonyMisc2bSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/,
991991
}
992992
return -1;
993993
}
994-
int sonyMisc3cSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) {
994+
int sonyMisc3cSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* pRoot) {
995995
// From Exiftool (Tag 9400c): https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/Sony.pm
996996
// > first byte decoded: 62, 48, 215, 28, 106 respectively
997997

@@ -1023,7 +1023,7 @@ int sonyMisc3cSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/,
10231023
// *****************************************************************************
10241024
// local definitions
10251025
namespace {
1026-
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* const pRoot, const uint16_t& tag,
1026+
const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* pRoot, const uint16_t& tag,
10271027
const Exiv2::Internal::IfdId& group) {
10281028
Exiv2::Internal::TiffFinder finder(tag, group);
10291029
if (!pRoot)
@@ -1033,7 +1033,7 @@ const Exiv2::Value* getExifValue(Exiv2::Internal::TiffComponent* const pRoot, co
10331033
return (!te || !te->pValue()) ? nullptr : te->pValue();
10341034
}
10351035

1036-
std::string getExifModel(Exiv2::Internal::TiffComponent* const pRoot) {
1036+
std::string getExifModel(Exiv2::Internal::TiffComponent* pRoot) {
10371037
// Lookup the Exif.Image.Model tag
10381038
const auto value = getExifValue(pRoot, 0x0110, Exiv2::Internal::ifd0Id);
10391039
return (!value || value->count() == 0) ? std::string("") : std::string(value->toString());

0 commit comments

Comments
 (0)