Added -pI print mode to print plain Iptc data

v0.27.3
Andreas Huggel 21 years ago
parent 54e126d3e4
commit 14d54e507e

@ -20,13 +20,13 @@
*/ */
/* /*
File: actions.cpp File: actions.cpp
Version: $Name: $ $Revision: 1.33 $ Version: $Name: $ $Revision: 1.34 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 08-Dec-03, ahu: created History: 08-Dec-03, ahu: created
*/ */
// ***************************************************************************** // *****************************************************************************
#include "rcsid.hpp" #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 // included header files
@ -38,6 +38,7 @@ EXIV2_RCSID("@(#) $Name: $ $Revision: 1.33 $ $RCSfile: actions.cpp,v $");
#include "types.hpp" #include "types.hpp"
#include "exif.hpp" #include "exif.hpp"
#include "canonmn.hpp" #include "canonmn.hpp"
#include "iptc.hpp"
#ifndef HAVE_TIMEGM #ifndef HAVE_TIMEGM
# include "timegm.h" # include "timegm.h"
#endif #endif
@ -126,29 +127,31 @@ namespace Action {
int Print::run(const std::string& path) int Print::run(const std::string& path)
try { try {
path_ = path; path_ = path;
Exiv2::ExifData exifData; int rc = 0;
int rc = exifData.read(path);
if (rc) {
std::cerr << Exiv2::ExifData::strError(rc, path) << "\n";
return rc;
}
switch (Params::instance().printMode_) { switch (Params::instance().printMode_) {
case Params::summary: printSummary(exifData); break; case Params::summary: rc = printSummary(); break;
case Params::interpreted: printInterpreted(exifData); break; case Params::interpreted: rc = printInterpreted(); break;
case Params::values: printValues(exifData); break; case Params::values: rc = printValues(); break;
case Params::hexdump: printHexdump(exifData); 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 " std::cerr << "Exif exception in print action for file "
<< path << ":\n" << e << "\n"; << path << ":\n" << e << "\n";
return 1; return 1;
} // Print::run } // 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; align_ = 16;
// Filename // Filename
@ -394,6 +397,7 @@ namespace Action {
printTag(exifData, "Exif.Photo.UserComment", "Exif comment"); printTag(exifData, "Exif.Photo.UserComment", "Exif comment");
std::cout << std::endl; std::cout << std::endl;
return 0;
} // Print::printSummary } // Print::printSummary
int Print::printTag(const Exiv2::ExifData& exifData, int Print::printTag(const Exiv2::ExifData& exifData,
@ -416,8 +420,15 @@ namespace Action {
return rc; return rc;
} // Print::printTag } // 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; Exiv2::ExifData::const_iterator md;
for (md = exifData.begin(); md != exifData.end(); ++md) { for (md = exifData.begin(); md != exifData.end(); ++md) {
std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right std::cout << "0x" << std::setw(4) << std::setfill('0') << std::right
@ -428,12 +439,22 @@ namespace Action {
<< md->tagName() << " " << md->tagName() << " "
<< std::dec << *md << "\n"; << std::dec << *md << "\n";
} }
return 0;
} // Print::printInterpreted } // 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; 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::cout << "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << md->tag() << " " << std::hex << md->tag() << " "
<< std::setw(9) << std::setfill(' ') << std::left << std::setw(9) << std::setfill(' ') << std::left
@ -448,10 +469,50 @@ namespace Action {
<< std::dec << md->value() << std::dec << md->value()
<< "\n"; << "\n";
} }
return 0;
} // Print::printValues } // 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; Exiv2::ExifData::const_iterator md;
for (md = exifData.begin(); md != exifData.end(); ++md) { for (md = exifData.begin(); md != exifData.end(); ++md) {
std::cout << std::setw(4) << std::setfill(' ') << std::left std::cout << std::setw(4) << std::setfill(' ') << std::left
@ -472,6 +533,8 @@ namespace Action {
md->copy(buf.pData_, exifData.byteOrder()); md->copy(buf.pData_, exifData.byteOrder());
Exiv2::hexdump(std::cout, buf.pData_, buf.size_); Exiv2::hexdump(std::cout, buf.pData_, buf.size_);
} }
return 0;
} // Print::printHexdump } // Print::printHexdump
Print::AutoPtr Print::clone() const Print::AutoPtr Print::clone() const

@ -22,7 +22,7 @@
@file actions.hpp @file actions.hpp
@brief Implements base class Task, TaskFactory and the various supported @brief Implements base class Task, TaskFactory and the various supported
actions (derived from Task). actions (derived from Task).
@version $Name: $ $Revision: 1.10 $ @version $Name: $ $Revision: 1.11 $
@author Andreas Huggel (ahu) @author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 11-Dec-03, ahu: created @date 11-Dec-03, ahu: created
@ -149,14 +149,16 @@ namespace Action {
typedef std::auto_ptr<Print> AutoPtr; typedef std::auto_ptr<Print> AutoPtr;
AutoPtr clone() const; AutoPtr clone() const;
//! Print uninterpreted Iptc information
int printIptc();
//! Print Exif summary information //! Print Exif summary information
void printSummary(const Exiv2::ExifData& exifData); int printSummary();
//! Print the interpreted value for each Exif tag //! Print the interpreted value for each Exif tag
void printInterpreted(const Exiv2::ExifData& exifData); int printInterpreted();
//! Print uninterpreted Exif information //! Print uninterpreted Exif information
void printValues(const Exiv2::ExifData& exifData); int printValues();
//! Print Exif information in hexdump format //! 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 @brief Print one summary line with a label (if provided) and requested
data. A line break is printed only if a label is provided. data. A line break is printed only if a label is provided.

@ -22,13 +22,13 @@
Abstract: Command line program to display and manipulate image %Exif data Abstract: Command line program to display and manipulate image %Exif data
File: exiv2.cpp File: exiv2.cpp
Version: $Name: $ $Revision: 1.12 $ Version: $Name: $ $Revision: 1.13 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net> Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 10-Dec-03, ahu: created History: 10-Dec-03, ahu: created
*/ */
// ***************************************************************************** // *****************************************************************************
#include "rcsid.hpp" #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 // 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" << " -a time Time adjustment in the format [-]HH[:MM[:SS]]. This option\n"
<< " is only used with the `adjust' action.\n" << " is only used with the `adjust' action.\n"
<< " -p mode Print mode for the `print' action. Possible modes are `s'\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 a summary (the default), `i' for interpreted Exif data,\n"
<< " for uninterpreted data values and `h' for a hexdump.\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" << " -d tgt Delete target for the `delete' action. Possible targets are\n"
<< " `e' to delete the whole Exif section (the default) and `t'\n" << " `e' to delete the whole Exif section (the default) and `t'\n"
<< " to delete only the Exif thumbnail from the files.\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 'i': printMode_ = interpreted; break;
case 'v': printMode_ = values; break; case 'v': printMode_ = values; break;
case 'h': printMode_ = hexdump; break; case 'h': printMode_ = hexdump; break;
case 'I': printMode_ = iptc; break;
default: default:
std::cerr << progname() << ": Unrecognized print mode `" std::cerr << progname() << ": Unrecognized print mode `"
<< optarg << "'\n"; << optarg << "'\n";

@ -21,7 +21,7 @@
/*! /*!
@file exiv2.hpp @file exiv2.hpp
@brief Defines class Params, used for the command line handling of exiv2 @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) @author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 08-Dec-03, ahu: created @date 08-Dec-03, ahu: created
@ -86,7 +86,7 @@ public:
static Params& instance(); static Params& instance();
//! Enumerates print modes //! Enumerates print modes
enum PrintMode { summary, interpreted, values, hexdump }; enum PrintMode { summary, interpreted, values, hexdump, iptc };
//! Enumerates delete targets //! Enumerates delete targets
enum DelTarget { delExif, delThumb }; enum DelTarget { delExif, delThumb };
//! Enumerates extract targets //! Enumerates extract targets

Loading…
Cancel
Save