diff --git a/src/actions.cpp b/src/actions.cpp index aced45d2..2086750a 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -20,13 +20,13 @@ */ /* File: actions.cpp - Version: $Name: $ $Revision: 1.33 $ + Version: $Name: $ $Revision: 1.34 $ Author(s): Andreas Huggel (ahu) History: 08-Dec-03, ahu: created */ // ***************************************************************************** #include "rcsid.hpp" -EXIV2_RCSID("@(#) $Name: $ $Revision: 1.33 $ $RCSfile: actions.cpp,v $"); +EXIV2_RCSID("@(#) $Name: $ $Revision: 1.34 $ $RCSfile: actions.cpp,v $"); // ***************************************************************************** // included header files @@ -38,6 +38,7 @@ EXIV2_RCSID("@(#) $Name: $ $Revision: 1.33 $ $RCSfile: actions.cpp,v $"); #include "types.hpp" #include "exif.hpp" #include "canonmn.hpp" +#include "iptc.hpp" #ifndef HAVE_TIMEGM # include "timegm.h" #endif @@ -126,29 +127,31 @@ namespace Action { int Print::run(const std::string& path) try { path_ = path; - Exiv2::ExifData exifData; - int rc = exifData.read(path); - if (rc) { - std::cerr << Exiv2::ExifData::strError(rc, path) << "\n"; - return rc; - } + int rc = 0; switch (Params::instance().printMode_) { - case Params::summary: printSummary(exifData); break; - case Params::interpreted: printInterpreted(exifData); break; - case Params::values: printValues(exifData); break; - case Params::hexdump: printHexdump(exifData); break; + case Params::summary: rc = printSummary(); break; + case Params::interpreted: rc = printInterpreted(); break; + case Params::values: rc = printValues(); break; + case Params::hexdump: rc = printHexdump(); break; + case Params::iptc: rc = printIptc(); break; } - return 0; + return rc; } - catch(const Exiv2::Error& e) - { + catch(const Exiv2::Error& e) { std::cerr << "Exif exception in print action for file " << path << ":\n" << e << "\n"; return 1; } // Print::run - void Print::printSummary(const Exiv2::ExifData& exifData) + int Print::printSummary() { + Exiv2::ExifData exifData; + int rc = exifData.read(path_); + if (rc) { + std::cerr << Exiv2::ExifData::strError(rc, path_) << "\n"; + return rc; + } + align_ = 16; // Filename @@ -394,6 +397,7 @@ namespace Action { printTag(exifData, "Exif.Photo.UserComment", "Exif comment"); std::cout << std::endl; + return 0; } // Print::printSummary int Print::printTag(const Exiv2::ExifData& exifData, @@ -416,8 +420,15 @@ namespace Action { return rc; } // Print::printTag - void Print::printInterpreted(const Exiv2::ExifData& exifData) + int Print::printInterpreted() { + Exiv2::ExifData exifData; + int rc = exifData.read(path_); + if (rc) { + std::cerr << Exiv2::ExifData::strError(rc, path_) << "\n"; + return rc; + } + Exiv2::ExifData::const_iterator md; for (md = exifData.begin(); md != exifData.end(); ++md) { std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right @@ -428,12 +439,22 @@ namespace Action { << md->tagName() << " " << std::dec << *md << "\n"; } + + return 0; } // Print::printInterpreted - void Print::printValues(const Exiv2::ExifData& exifData) + int Print::printValues() { + Exiv2::ExifData exifData; + int rc = exifData.read(path_); + if (rc) { + std::cerr << Exiv2::ExifData::strError(rc, path_) << "\n"; + return rc; + } + + Exiv2::ExifData::const_iterator end = exifData.end(); Exiv2::ExifData::const_iterator md; - for (md = exifData.begin(); md != exifData.end(); ++md) { + for (md = exifData.begin(); md != end; ++md) { std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << md->tag() << " " << std::setw(9) << std::setfill(' ') << std::left @@ -448,10 +469,50 @@ namespace Action { << std::dec << md->value() << "\n"; } + + return 0; } // Print::printValues - void Print::printHexdump(const Exiv2::ExifData& exifData) + int Print::printIptc() + { + Exiv2::IptcData iptcData; + int rc = iptcData.read(path_); + if (rc) { + std::cerr << Exiv2::IptcData::strError(rc, path_) << "\n"; + return rc; + } + + Exiv2::IptcData::const_iterator end = iptcData.end(); + Exiv2::IptcData::const_iterator md; + for (md = iptcData.begin(); md != end; ++md) { + std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right + << std::hex << md->tag() << " " + << std::setw(9) << std::setfill(' ') << std::left + << md->recordName() << " " + << std::setw(9) << std::setfill(' ') << std::left + << md->typeName() << " " + << std::dec << std::setw(3) + << std::setfill(' ') << std::right + << md->count() << " " + << std::setw(27) << std::setfill(' ') << std::left + << md->tagName() << " " + << std::dec << md->value() + << "\n"; + } + + return 0; + } // Print::printIptc + + + int Print::printHexdump() { + Exiv2::ExifData exifData; + int rc = exifData.read(path_); + if (rc) { + std::cerr << Exiv2::ExifData::strError(rc, path_) << "\n"; + return rc; + } + Exiv2::ExifData::const_iterator md; for (md = exifData.begin(); md != exifData.end(); ++md) { std::cout << std::setw(4) << std::setfill(' ') << std::left @@ -472,6 +533,8 @@ namespace Action { md->copy(buf.pData_, exifData.byteOrder()); Exiv2::hexdump(std::cout, buf.pData_, buf.size_); } + + return 0; } // Print::printHexdump Print::AutoPtr Print::clone() const diff --git a/src/actions.hpp b/src/actions.hpp index 8f9af6e4..56871c40 100644 --- a/src/actions.hpp +++ b/src/actions.hpp @@ -22,7 +22,7 @@ @file actions.hpp @brief Implements base class Task, TaskFactory and the various supported actions (derived from Task). - @version $Name: $ $Revision: 1.10 $ + @version $Name: $ $Revision: 1.11 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 11-Dec-03, ahu: created @@ -149,14 +149,16 @@ namespace Action { typedef std::auto_ptr AutoPtr; AutoPtr clone() const; + //! Print uninterpreted Iptc information + int printIptc(); //! Print Exif summary information - void printSummary(const Exiv2::ExifData& exifData); + int printSummary(); //! Print the interpreted value for each Exif tag - void printInterpreted(const Exiv2::ExifData& exifData); + int printInterpreted(); //! Print uninterpreted Exif information - void printValues(const Exiv2::ExifData& exifData); + int printValues(); //! Print Exif information in hexdump format - void printHexdump(const Exiv2::ExifData& exifData); + int printHexdump(); /*! @brief Print one summary line with a label (if provided) and requested data. A line break is printed only if a label is provided. diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 049c9294..c8cf5c9c 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -22,13 +22,13 @@ Abstract: Command line program to display and manipulate image %Exif data File: exiv2.cpp - Version: $Name: $ $Revision: 1.12 $ + Version: $Name: $ $Revision: 1.13 $ Author(s): Andreas Huggel (ahu) History: 10-Dec-03, ahu: created */ // ***************************************************************************** #include "rcsid.hpp" -EXIV2_RCSID("@(#) $Name: $ $Revision: 1.12 $ $RCSfile: exiv2.cpp,v $"); +EXIV2_RCSID("@(#) $Name: $ $Revision: 1.13 $ $RCSfile: exiv2.cpp,v $"); // ***************************************************************************** // included header files @@ -141,8 +141,9 @@ void Params::help(std::ostream& os) const << " -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option\n" << " is only used with the `adjust' action.\n" << " -p mode Print mode for the `print' action. Possible modes are `s'\n" - << " for a summary (the default), `i' for interpreted data, `v'\n" - << " for uninterpreted data values and `h' for a hexdump.\n" + << " for a summary (the default), `i' for interpreted Exif data,\n" + << " `v' for plain Exif data values, `h' for a hexdump of the\n" + << " Exif data and `I' for Iptc data values.\n" << " -d tgt Delete target for the `delete' action. Possible targets are\n" << " `e' to delete the whole Exif section (the default) and `t'\n" << " to delete only the Exif thumbnail from the files.\n" @@ -210,6 +211,7 @@ int Params::option(int opt, const std::string& optarg, int optopt) case 'i': printMode_ = interpreted; break; case 'v': printMode_ = values; break; case 'h': printMode_ = hexdump; break; + case 'I': printMode_ = iptc; break; default: std::cerr << progname() << ": Unrecognized print mode `" << optarg << "'\n"; diff --git a/src/exiv2.hpp b/src/exiv2.hpp index 2a199c08..34235205 100644 --- a/src/exiv2.hpp +++ b/src/exiv2.hpp @@ -21,7 +21,7 @@ /*! @file exiv2.hpp @brief Defines class Params, used for the command line handling of exiv2 - @version $Name: $ $Revision: 1.3 $ + @version $Name: $ $Revision: 1.4 $ @author Andreas Huggel (ahu) ahuggel@gmx.net @date 08-Dec-03, ahu: created @@ -86,7 +86,7 @@ public: static Params& instance(); //! Enumerates print modes - enum PrintMode { summary, interpreted, values, hexdump }; + enum PrintMode { summary, interpreted, values, hexdump, iptc }; //! Enumerates delete targets enum DelTarget { delExif, delThumb }; //! Enumerates extract targets