#include "exif.hpp"
#include <iostream>
#include <iomanip>
int main()
try {
Exiv2::ExifData exifData;
Exiv2::Value* v = Exiv2::Value::create(Exiv2::asciiString);
v->read("1999:12:31 23:59:59");
Exiv2::ExifKey key("Exif.Photo.DateTimeOriginal");
exifData.add(key, v);
std::cout << "Added key \"" << key << "\", value \"" << *v << "\"\n";
delete v;
Exiv2::URationalValue* rv = new Exiv2::URationalValue;
rv->read("1/2 1/3");
rv->value_.push_back(std::make_pair(2,3));
rv->value_.push_back(std::make_pair(3,4));
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
exifData.add(key, rv);
std::cout << "Added key \"" << key << "\", value \"" << *rv << "\"\n";
delete rv;
key = Exiv2::ExifKey("Exif.Photo.DateTimeOriginal");
Exiv2::ExifData::iterator pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
std::string date = pos->toString();
date.replace(0,4,"2000");
pos->setValue(date);
std::cout << "Modified key \"" << key
<< "\", new value \"" << pos->value() << "\"\n";
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
v = pos->getValue();
rv = dynamic_cast<Exiv2::URationalValue*>(v);
if (rv == 0) throw Exiv2::Error("Downcast failed");
rv->value_[2] = std::make_pair(88,77);
pos->setValue(rv);
delete v;
std::cout << "Modified key \"" << key
<< "\", new value \"" << pos->value() << "\"\n";
key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities");
pos = exifData.findKey(key);
if (pos == exifData.end()) throw Exiv2::Error("Key not found");
exifData.erase(pos);
std::cout << "Deleted key \"" << key << "\"\n";
int rc = exifData.write("img_2158.jpg");
if (rc) {
std::string error = Exiv2::ExifData::strError(rc, "img_2158.jpg");
throw Exiv2::Error(error);
}
return 0;
}
catch (Exiv2::Error& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}