Skip to content

Commit

Permalink
several keys added to easyaccess
Browse files Browse the repository at this point in the history
sample easyaccess-test enhanced with additional optional arguments
"category" for easier definition of some tests
  • Loading branch information
norbertwg committed Oct 7, 2022
1 parent a2cb06a commit e38d3d9
Show file tree
Hide file tree
Showing 7 changed files with 1,342 additions and 119 deletions.
10 changes: 8 additions & 2 deletions README-SAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,16 @@ Conversion test driver
#### easyaccess-test

```
Usage: easyaccess-test file
Usage: ..\build\bin\easyaccess-test.exe file [category [category ...]]
Categories: Orientation | ISOspeed | DateTimeOriginal | FlashBias | ExposureMode | SceneMode |
MacroMode | ImageQuality | WhiteBalance | LensName | Saturation | Sharpness |
Contrast | SceneCaptureType | MeteringMode | Make | Model | ExposureTime | FNumber |
ShutterSpeed | Aperture | Brightness | ExposureBias | MaxAperture | SubjectDistance |
LightSource | Flash | SerialNumber | FocalLength | SubjectArea | FlashEnergy |
ExposureIndex | SensingMethod | AFpoint
```

Sample program using high-level metadata access functions
Sample program using high-level metadata access functions. Without specification of a category, metadata for all categories are shown.

[Sample](#TOC1) Programs [Test](#TOC2) Programs

Expand Down
127 changes: 81 additions & 46 deletions samples/easyaccess-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,57 @@
#include <iomanip>
#include <iostream>

// Type for an Exiv2 Easy access function
using EasyAccessFct = Exiv2::ExifData::const_iterator (*)(const Exiv2::ExifData&);

static constexpr auto easyAccess = std::array{
std::pair("Orientation", &Exiv2::orientation),
std::pair("ISO speed", &Exiv2::isoSpeed),
std::pair("Date & time original", &Exiv2::dateTimeOriginal),
std::pair("Flash bias", &Exiv2::flashBias),
std::pair("Exposure mode", &Exiv2::exposureMode),
std::pair("Scene mode", &Exiv2::sceneMode),
std::pair("Macro mode", &Exiv2::macroMode),
std::pair("Image quality", &Exiv2::imageQuality),
std::pair("White balance", &Exiv2::whiteBalance),
std::pair("Lens name", &Exiv2::lensName),
std::pair("Saturation", &Exiv2::saturation),
std::pair("Sharpness", &Exiv2::sharpness),
std::pair("Contrast", &Exiv2::contrast),
std::pair("Scene capture type", &Exiv2::sceneCaptureType),
std::pair("Metering mode", &Exiv2::meteringMode),
std::pair("Camera make", &Exiv2::make),
std::pair("Camera model", &Exiv2::model),
std::pair("Exposure time", &Exiv2::exposureTime),
std::pair("FNumber", &Exiv2::fNumber),
std::pair("Shutter speed value", &Exiv2::shutterSpeedValue),
std::pair("Aperture value", &Exiv2::apertureValue),
std::pair("Brightness value", &Exiv2::brightnessValue),
std::pair("Exposure bias", &Exiv2::exposureBiasValue),
std::pair("Max aperture value", &Exiv2::maxApertureValue),
std::pair("Subject distance", &Exiv2::subjectDistance),
std::pair("Light source", &Exiv2::lightSource),
std::pair("Flash", &Exiv2::flash),
std::pair("Camera serial number", &Exiv2::serialNumber),
std::pair("Focal length", &Exiv2::focalLength),
std::pair("Subject location/area", &Exiv2::subjectArea),
std::pair("Flash energy", &Exiv2::flashEnergy),
std::pair("Exposure index", &Exiv2::exposureIndex),
std::pair("Sensing method", &Exiv2::sensingMethod),
std::pair("AF point", &Exiv2::afPoint),
std::make_tuple("Orientation", &Exiv2::orientation, "Orientation"),
std::make_tuple("ISO speed", &Exiv2::isoSpeed, "ISOspeed"),
std::make_tuple("Date & time original", &Exiv2::dateTimeOriginal, "DateTimeOriginal"),
std::make_tuple("Flash bias", &Exiv2::flashBias, "FlashBias"),
std::make_tuple("Exposure mode", &Exiv2::exposureMode, "ExposureMode"),
std::make_tuple("Scene mode", &Exiv2::sceneMode, "SceneMode"),
std::make_tuple("Macro mode", &Exiv2::macroMode, "MacroMode"),
std::make_tuple("Image quality", &Exiv2::imageQuality, "ImageQuality"),
std::make_tuple("White balance", &Exiv2::whiteBalance, "WhiteBalance"),
std::make_tuple("Lens name", &Exiv2::lensName, "LensName"),
std::make_tuple("Saturation", &Exiv2::saturation, "Saturation"),
std::make_tuple("Sharpness", &Exiv2::sharpness, "Sharpness"),
std::make_tuple("Contrast", &Exiv2::contrast, "Contrast"),
std::make_tuple("Scene capture type", &Exiv2::sceneCaptureType, "SceneCaptureType"),
std::make_tuple("Metering mode", &Exiv2::meteringMode, "MeteringMode"),
std::make_tuple("Camera make", &Exiv2::make, "Make"),
std::make_tuple("Camera model", &Exiv2::model, "Model"),
std::make_tuple("Exposure time", &Exiv2::exposureTime, "ExposureTime"),
std::make_tuple("FNumber", &Exiv2::fNumber, "FNumber"),
std::make_tuple("Shutter speed value", &Exiv2::shutterSpeedValue, "ShutterSpeed"),
std::make_tuple("Aperture value", &Exiv2::apertureValue, "Aperture"),
std::make_tuple("Brightness value", &Exiv2::brightnessValue, "Brightness"),
std::make_tuple("Exposure bias", &Exiv2::exposureBiasValue, "ExposureBias"),
std::make_tuple("Max aperture value", &Exiv2::maxApertureValue, "MaxAperture"),
std::make_tuple("Subject distance", &Exiv2::subjectDistance, "SubjectDistance"),
std::make_tuple("Light source", &Exiv2::lightSource, "LightSource"),
std::make_tuple("Flash", &Exiv2::flash, "Flash"),
std::make_tuple("Camera serial number", &Exiv2::serialNumber, "SerialNumber"),
std::make_tuple("Focal length", &Exiv2::focalLength, "FocalLength"),
std::make_tuple("Subject location/area", &Exiv2::subjectArea, "SubjectArea"),
std::make_tuple("Flash energy", &Exiv2::flashEnergy, "FlashEnergy"),
std::make_tuple("Exposure index", &Exiv2::exposureIndex, "ExposureIndex"),
std::make_tuple("Sensing method", &Exiv2::sensingMethod, "SensingMethod"),
std::make_tuple("AF point", &Exiv2::afPoint, "AFpoint"),
};

static const void printFct(EasyAccessFct fct, Exiv2::ExifData ed, const char* label) {
auto pos = fct(ed);
std::cout << std::setw(21) << std::left << label;
if (pos != ed.end()) {
std::cout << " (" << std::setw(35) << pos->key() << ") : " << pos->print(&ed) << "\n";
} else {
std::cout << " (" << std::setw(35) << " "
<< ") : \n";
}
}

int main(int argc, char** argv) {
try {
Exiv2::XmpParser::initialize();
Expand All @@ -50,27 +64,48 @@ int main(int argc, char** argv) {
Exiv2::enableBMFF();
#endif

if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
if (argc < 2) {
int count = 0;
std::cout << "Usage: " << argv[0] << " file [category [category ...]]\nCategories: ";
for (auto&& [label, fct, name] : easyAccess) {
if (count > 0)
std::cout << " | ";
if (count == 6 || count == 12 || count == 19 || count == 25 || count == 31)
std::cout << "\n ";

std::cout << name;
count++;
}
std::cout << "\n";
return EXIT_FAILURE;
}

auto image = Exiv2::ImageFactory::open(argv[1]);
image->readMetadata();
Exiv2::ExifData& ed = image->exifData();

for (auto&& [label, fct] : easyAccess) {
auto pos = fct(ed);
std::cout << std::setw(21) << std::left << label;
if (pos != ed.end()) {
std::cout << " (" << std::setw(35) << pos->key() << ") : " << pos->print(&ed) << "\n";
} else {
std::cout << " (" << std::setw(35) << " "
<< ") : \n";
if (argc > 2) {
for (int i = 2; i < argc; i++) {
bool categoryOk = false;
for (auto&& [label, fct, name] : easyAccess) {
if (strcmp(argv[i], name) == 0) {
printFct(fct, ed, label);
categoryOk = true;
break;
}
}
if (!categoryOk) {
std::cout << "Categoy >" << argv[i] << "< is invalid.\n";
return EXIT_FAILURE;
}
}
} else {
for (auto&& [label, fct, name] : easyAccess) {
printFct(fct, ed, label);
}
}

return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
} catch (Exiv2::Error& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return EXIT_FAILURE;
Expand Down
Loading

0 comments on commit e38d3d9

Please sign in to comment.