made use of new easyaccess functions to support macro mode, orientation, lens name, and better iso values

v0.27.3
brad 17 years ago
parent 6bcd8cacd4
commit 2b7a80d4bb

@ -31,6 +31,7 @@
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <exiv2/image.hpp>
#include <exiv2/easyaccess.hpp>
#include <exiv2/exif.hpp>
#include <exiv2/iptc.hpp>
#include <exiv2/tags.hpp>
@ -43,13 +44,20 @@
#define BOOST_FILESYSTEM_NO_DEPRECATED
namespace fs = boost::filesystem;
typedef Exiv2::ExifData::const_iterator (*EasyAccessFct)(const Exiv2::ExifData& ed);
std::string scrub(const std::string &dirty)
std::string scrub(const std::string &dirty, bool strip_space = false)
{
std::string scrub = boost::trim_copy(dirty);
if(strip_space) {
boost::regex space("\\s");
scrub = boost::regex_replace(scrub, space, "");
}
boost::regex dash("[:/\\\\|<>]");
boost::regex under("[\"'\\[\\]\\{\\}#=%\\$\\?,\\+\\*]");
scrub = boost::regex_replace(scrub, dash, "-");
return boost::regex_replace(scrub, under, "_");
}
@ -69,6 +77,22 @@ bool exif_data(const Exiv2::Image *image, const char *key, Exiv2::ExifData::cons
return ok;
}
bool exif_data_easy(const Exiv2::Image *image, EasyAccessFct easy, Exiv2::ExifData::const_iterator &md)
{
assert(image && easy);
bool ok = false;
try {
const Exiv2::ExifData &exifData = image->exifData();
md = easy(exifData);
if(md != exifData.end() && md->typeId() != Exiv2::undefined)
ok = true;
}
catch(const Exiv2::AnyError&) {
}
return ok;
}
bool iptc_data(const Exiv2::Image *image, const char *key, Exiv2::IptcData::const_iterator &md)
{
bool ok = false;
@ -550,26 +574,38 @@ std::string exif_meter(const Exiv2::Image *image, const fs::path &)
return scrub(md->print());
}
std::string exif_iso(const Exiv2::Image *image, const fs::path &)
std::string exif_macro(const Exiv2::Image *image, const fs::path &)
{
Exiv2::ExifData::const_iterator md;
bool done = exif_data(image, "Exif.Photo.ISOSpeedRatings", md);
if(!done)
done = exif_data(image, "Exif.CanonSi.ISOSpeed", md);
if(!done)
done = exif_data(image, "Exif.Nikon1.ISOSpeed", md);
if(!done)
done = exif_data(image, "Exif.Nikon2.ISOSpeed", md);
if(!done)
done = exif_data(image, "Exif.Nikon3.ISOSpeed", md);
bool done = exif_data_easy(image, Exiv2::macroMode, md);
if(!done)
done = exif_data(image, "Exif.MinoltaCsNew.ISOSpeed", md);
if(!done)
done = exif_data(image, "Exif.MinoltaCsOld.ISOSpeed", md);
return "";
return scrub(md->print());
}
std::string exif_orientation(const Exiv2::Image *image, const fs::path &)
{
Exiv2::ExifData::const_iterator md;
bool done = exif_data_easy(image, Exiv2::orientation, md);
if(!done)
done = exif_data(image, "Exif.MinoltaCs5D.ISOSpeed", md);
return "";
return scrub(md->print(), true);
}
std::string exif_lens(const Exiv2::Image *image, const fs::path &)
{
Exiv2::ExifData::const_iterator md;
bool done = exif_data_easy(image, Exiv2::lensName, md);
if(!done)
done = exif_data(image, "Exif.MinoltaCs7D.ISOSpeed", md);
return "";
return scrub(md->print());
}
std::string exif_iso(const Exiv2::Image *image, const fs::path &)
{
Exiv2::ExifData::const_iterator md;
bool done = exif_data_easy(image, Exiv2::isoSpeed, md);
if(!done)
return "";
return scrub(md->print());

@ -96,6 +96,9 @@ std::string exif_distance(const Exiv2::Image *image, const fs::path &path);
//std::string xmp_distance(const Exiv2::Image *image, const fs::path &path);
std::string exif_meter(const Exiv2::Image *image, const fs::path &path);
//std::string xmp_meter(const Exiv2::Image *image, const fs::path &path);
std::string exif_macro(const Exiv2::Image *image, const fs::path &path);
std::string exif_orientation(const Exiv2::Image *image, const fs::path &path);
std::string exif_lens(const Exiv2::Image *image, const fs::path &path);
std::string exif_keyword(const Exiv2::Image *image, const fs::path &path);
std::string iptc_keyword(const Exiv2::Image *image, const fs::path &path);
//std::string xmp_keyword(const Exiv2::Image *image, const fs::path &path);

@ -141,6 +141,12 @@ const Pattern g_patterns[] = {
{exif_distance, NULL, NULL, NULL} },
{"@meter", "meter mode (multi-segment)",
{exif_meter, NULL, NULL, NULL} },
{"@macro", "macro mode (Off)",
{exif_macro, NULL, NULL, NULL} },
{"@orient", "orientation (top_left)",
{exif_orientation, NULL, NULL, NULL} },
{"@lens", "lens name (Tamron 90mm f-2.8)",
{exif_lens, NULL, NULL, NULL} },
{"@key", "first keyword (Family)",
{exif_keyword, iptc_keyword, NULL, NULL} },

Loading…
Cancel
Save