File: easyaccess-test.cpp

package info (click to toggle)
exiv2 0.28.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 109,216 kB
  • sloc: cpp: 77,667; python: 9,619; javascript: 237; makefile: 193; sh: 172; ansic: 51; sed: 16
file content (114 lines) | stat: -rw-r--r-- 4,168 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: GPL-2.0-or-later
// Sample program using high-level metadata access functions

#include <exiv2/exiv2.hpp>
#include <iomanip>
#include <iostream>

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

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

static 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();
    ::atexit(Exiv2::XmpParser::terminate);

    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();

    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 << "Category >" << argv[i] << "< is invalid.\n";
          return EXIT_FAILURE;
        }
      }
    } else {
      for (auto&& [label, fct, name] : easyAccess) {
        printFct(fct, ed, label);
      }

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