Added fixiso action. Implements feature #450.
This commit is contained in:
parent
45db713002
commit
b953a4e9da
@ -178,6 +178,7 @@ namespace Action {
|
||||
registerTask(extract, Task::AutoPtr(new Extract));
|
||||
registerTask(insert, Task::AutoPtr(new Insert));
|
||||
registerTask(modify, Task::AutoPtr(new Modify));
|
||||
registerTask(fixiso, Task::AutoPtr(new FixIso));
|
||||
} // TaskFactory c'tor
|
||||
|
||||
Task::AutoPtr TaskFactory::create(TaskType type)
|
||||
@ -1252,6 +1253,67 @@ namespace Action {
|
||||
return 0;
|
||||
} // Adjust::adjustDateTime
|
||||
|
||||
int FixIso::run(const std::string& path)
|
||||
try {
|
||||
if (!Exiv2::fileExists(path, true)) {
|
||||
std::cerr << path
|
||||
<< ": Failed to open the file\n";
|
||||
return -1;
|
||||
}
|
||||
Timestamp ts;
|
||||
if (Params::instance().preserve_) {
|
||||
ts.read(path);
|
||||
}
|
||||
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
|
||||
assert(image.get() != 0);
|
||||
image->readMetadata();
|
||||
Exiv2::ExifData &exifData = image->exifData();
|
||||
if (exifData.empty()) {
|
||||
std::cerr << path
|
||||
<< ": No Exif data found in the file\n";
|
||||
return -3;
|
||||
}
|
||||
Exiv2::ExifKey key("Exif.Nikon3.ISOSpeed");
|
||||
Exiv2::ExifData::iterator md = exifData.findKey(key);
|
||||
if (md == exifData.end()) {
|
||||
key = Exiv2::ExifKey("Exif.Nikon2.ISOSpeed");
|
||||
md = exifData.findKey(key);
|
||||
}
|
||||
if (md == exifData.end()) {
|
||||
key = Exiv2::ExifKey("Exif.Nikon1.ISOSpeed");
|
||||
md = exifData.findKey(key);
|
||||
}
|
||||
if (md != exifData.end()) {
|
||||
std::ostringstream os;
|
||||
os << *md;
|
||||
if (Params::instance().verbose_) {
|
||||
std::cout << "Setting Exif ISO value to " << os.str() << "\n";
|
||||
}
|
||||
exifData["Exif.Photo.ISOSpeedRatings"] = os.str();
|
||||
}
|
||||
image->writeMetadata();
|
||||
if (Params::instance().preserve_) {
|
||||
ts.touch(path);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(const Exiv2::AnyError& e)
|
||||
{
|
||||
std::cerr << "Exiv2 exception in fixiso action for file " << path
|
||||
<< ":\n" << e << "\n";
|
||||
return 1;
|
||||
} // FixIso::run
|
||||
|
||||
FixIso::AutoPtr FixIso::clone() const
|
||||
{
|
||||
return AutoPtr(clone_());
|
||||
}
|
||||
|
||||
FixIso* FixIso::clone_() const
|
||||
{
|
||||
return new FixIso(*this);
|
||||
}
|
||||
|
||||
} // namespace Action
|
||||
|
||||
// *****************************************************************************
|
||||
|
||||
@ -58,7 +58,8 @@ namespace Exiv2 {
|
||||
namespace Action {
|
||||
|
||||
//! Enumerates all tasks
|
||||
enum TaskType { none, adjust, print, rename, erase, extract, insert, modify };
|
||||
enum TaskType { none, adjust, print, rename, erase, extract, insert,
|
||||
modify, fixiso };
|
||||
|
||||
// *****************************************************************************
|
||||
// class definitions
|
||||
@ -327,6 +328,23 @@ namespace Action {
|
||||
Exiv2::Image::AutoPtr image_; //!< Image to modify
|
||||
}; // class Modify
|
||||
|
||||
/*!
|
||||
@brief %Copy ISO settings from any of the Nikon makernotes to the
|
||||
regular Exif tag, Exif.Photo.ISOSpeedRatings.
|
||||
*/
|
||||
class FixIso : public Task {
|
||||
public:
|
||||
virtual ~FixIso() {}
|
||||
virtual int run(const std::string& path);
|
||||
typedef std::auto_ptr<FixIso> AutoPtr;
|
||||
AutoPtr clone() const;
|
||||
|
||||
private:
|
||||
virtual FixIso* clone_() const;
|
||||
std::string path_;
|
||||
|
||||
}; // class FixIso
|
||||
|
||||
} // namespace Action
|
||||
|
||||
#endif // #ifndef ACTIONS_HPP_
|
||||
|
||||
@ -62,6 +62,11 @@ files. Requires option \fB\-c\fP, \fB\-m\fP or \fB\-M\fP.
|
||||
Rename files and/or set file timestamps according to the EXIF create
|
||||
timestamp. The filename format can be set with \fB\-r\fP \fIfmt\fP,
|
||||
timestamp options are \fB\-t\fP and \fB\-T\fP.
|
||||
.TP
|
||||
.B fi | fixiso
|
||||
Copy the ISO setting from any of the proprietary Nikon makernote ISO
|
||||
tags to the regular Exif ISO tag, Exif.Photo.ISOSpeedRatings. Overwrites
|
||||
an existing Exif ISO tag.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-h
|
||||
|
||||
@ -212,6 +212,8 @@ void Params::help(std::ostream& os) const
|
||||
<< " mo | modify Apply commands to modify (add, set, delete) the Exif and\n"
|
||||
<< " Iptc metadata of image files or set the Jpeg comment.\n"
|
||||
<< " Requires option -c, -m or -M.\n"
|
||||
<< " fi | fixiso Copy ISO setting from the Nikon Makernote to the regular\n"
|
||||
<< " Exif tag.\n"
|
||||
<< "\nOptions:\n"
|
||||
<< " -h Display this help and exit.\n"
|
||||
<< " -V Show the program version and exit.\n"
|
||||
@ -557,6 +559,15 @@ int Params::nonoption(const std::string& argv)
|
||||
action = true;
|
||||
action_ = Action::modify;
|
||||
}
|
||||
if (argv == "fi" || argv == "fixiso") {
|
||||
if (action_ != Action::none && action_ != Action::fixiso) {
|
||||
std::cerr << progname() << ": Action fixiso is not "
|
||||
<< "compatible with the given options\n";
|
||||
rc = 1;
|
||||
}
|
||||
action = true;
|
||||
action_ = Action::fixiso;
|
||||
}
|
||||
if (action_ == Action::none) {
|
||||
// if everything else fails, assume print as the default action
|
||||
action_ = Action::print;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user