libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit e4d4df359bf0078fb73d5cde7d5eb85f9c342a2a
parent 18cc6b0da01358774360498c4d51dd7b9164d579
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  3 Jul 2005 20:20:25 +0000

update

Diffstat:
Asrc/plugins/exiv2/Makefile.am | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/exiv2/Todo | 40++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/exiv2/metacopy.cpp | 184+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/exiv2/metacopy.hpp | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/plugins/exiv2/metacopy.lo | 12++++++++++++
5 files changed, 396 insertions(+), 0 deletions(-)

diff --git a/src/plugins/exiv2/Makefile.am b/src/plugins/exiv2/Makefile.am @@ -0,0 +1,74 @@ +INCLUDES = -I$(top_srcdir)/src/include + +# install plugins under: +plugindir = $(libdir)/libextractor + +SUBDIRS = . + +LIBS = \ + @LTLIBINTL@ @LIBS@ + +plugin_LTLIBRARIES = \ + libextractor_exiv2.la + +PLUGINFLAGS = -export-dynamic -avoid-version -module -no-undefined + +libextractor_exiv2_la_LINK = \ + /bin/sh ../../../libtool --mode=link $(CXXLD) -o libextractor_exiv2.la +libextractor_exiv2_la_LDFLAGS = \ + $(PLUGINFLAGS) $(XTRA_CPPLIBS) +libextractor_exiv2_la_LIBADD = \ + $(top_builddir)/src/main/libextractor.la + +libextractor_exiv2_la_SOURCES = \ +exiv2extractor.cc \ +basicio.cpp \ +basicio.hpp \ +canonmn.cpp \ +canonmn.hpp \ +datasets.cpp \ +datasets.hpp \ +doxygen.hpp \ +error.cpp \ +error.hpp \ +exif.cpp \ +exif.hpp \ +fujimn.cpp \ +fujimn.hpp \ +futils.cpp \ +futils.hpp \ +ifd.cpp \ +ifd.hpp \ +image.cpp \ +image.hpp \ +iptc.cpp \ +iptc.hpp \ +jpgimage.cpp \ +jpgimage.hpp \ +makernote.cpp \ +makernote.hpp \ +metacopy.cpp \ +metacopy.hpp \ +metadatum.cpp \ +metadatum.hpp \ +mn.hpp \ +nikonmn.cpp \ +nikonmn.hpp \ +olympusmn.cpp \ +olympusmn.hpp \ +panasonicmn.cpp \ +panasonicmn.hpp \ +rcsid.hpp \ +sigmamn.cpp \ +sigmamn.hpp \ +sonymn.cpp \ +sonymn.hpp \ +tags.cpp \ +tags.hpp \ +types.cpp \ +types.hpp \ +utils.cpp \ +utils.hpp \ +value.cpp \ +value.hpp + diff --git a/src/plugins/exiv2/Todo b/src/plugins/exiv2/Todo @@ -0,0 +1,40 @@ +Library Features: ++ rename erase* methods that access a file to remove* ++ add ExifData::erase(tag) ++ Thumbnail support: set (re-calculate) ++ operator>> for Value, since we already have read()? ++ Use size_t where appropriate ++ Support TIFF type ids ++ Support for broken IFD makernotes (which have corrupted IFD offsets) ++ Support non-intrusive deletion of entries from an IFD. ++ Write an example using low level IFD classes to print summary Exif info ++ Extended JPEG support (actual resolution of the image) ++ Implement proper error handling ++ Complete support to create Exif data from scratch: + + set thumbnail, write thumbnail tags ++ Make it possible to force write from metadata (just an optional arg to write?) + ++ Make Image::doWriteMetadata do its work in a single pass + ++ Revise Image and IptcData+ExifData API (aka turn it inside out) ++ Add PSD images support (and TIFF, NEF, CRW...) ++ Add support for XML metadata files + +Exiv2 functionality ++ Add offset to value for hexdump (requires metadata to have an offset) + +Bugs: ++ Handle all Todo's ++ Cleanup and fix implementation of JpegImage (must be able to read any APP0/1), + should be able to insert exv into extracted thumbs (usually w/o APP0/1) ++ Review Image interface. Is it really necessary to have so many functions there? ++ Review the handling of type ids? What if we encounter type 27 in an IFD? ++ Rational and other output operators (see Josuttis, p653) ++ Through ExifData::iterator and Metadatum::operator= it is possible to have + multiple copies of one metadatum in the metadata container ++ Checks and non-intrusive updates must be atomic, i.e., not change anything + if the metadata is not compatible ++ Review: Exception safety ++ Review: Ifd1 only at Thumbnail, do we really need Thumbnail::update() ? ++ Is the hexdump output of exiv2 byte-swapped?? ++ Should JpegImage differ between NO Jpeg comment and an empty Jpeg comment?? diff --git a/src/plugins/exiv2/metacopy.cpp b/src/plugins/exiv2/metacopy.cpp @@ -0,0 +1,184 @@ +// ***************************************************************** -*- C++ -*- +/* + * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> + * + * This program is part of the Exiv2 distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/* + Abstract : Tester application for image file handling + + File : metacopy.cpp + Version : $Rev: 560 $ + Author(s): Brad Schick (brad) <brad@robotbattle.com> + History : 13-Jul-04, brad: created + */ +// ***************************************************************************** +// included header files +#include "image.hpp" +#include "iptc.hpp" +#include "exif.hpp" +#include "types.hpp" +#include "metacopy.hpp" +#include <iostream> +#include <fstream> +#include <cassert> + +#if 0 +// ***************************************************************************** +// Main +int main(int argc, char* const argv[]) +{ +try { + // Handle command line arguments + Params params; + if (params.getopt(argc, argv)) { + params.usage(); + return 1; + } + if (params.help_) { + params.help(); + return 2; + } + + // Use MemIo to increase test coverage. + Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_)); + Exiv2::BasicIo::AutoPtr memIo(new Exiv2::MemIo); + memIo->transfer(*fileIo); + + Exiv2::Image::AutoPtr readImg = Exiv2::ImageFactory::open(memIo); + assert(readImg.get() != 0); + readImg->readMetadata(); + + Exiv2::Image::AutoPtr writeImg = Exiv2::ImageFactory::open(params.write_); + assert(writeImg.get() != 0); + if (params.preserve_) writeImg->readMetadata(); + if (params.iptc_) { + writeImg->setIptcData(readImg->iptcData()); + } + if (params.exif_) { + writeImg->setExifData(readImg->exifData()); + } + if (params.comment_) { + writeImg->setComment(readImg->comment()); + } + + try { + writeImg->writeMetadata(); + } + catch (const Exiv2::AnyError&) { + std::cerr << params.progname() << + ": Could not write metadata to (" << params.write_ << ")\n"; + return 8; + } + + return 0; +} +catch (Exiv2::AnyError& e) { + std::cerr << "Caught Exiv2 exception '" << e << "'\n"; + return 10; +} +} +#endif + +int Params::option(int opt, const std::string& optarg, int optopt) +{ + int rc = 0; + switch (opt) { + case 'h': help_ = true; break; + case 'i': iptc_ = true; break; + case 'e': exif_ = true; break; + case 'c': comment_ = true; break; + case 'p': preserve_ = true; break; + case 'a': + iptc_ =true; + exif_ =true; + comment_ =true; + break; + case ':': + std::cerr << progname() << ": Option -" << static_cast<char>(optopt) + << " requires an argument\n"; + rc = 1; + break; + case '?': + std::cerr << progname() << ": Unrecognized option -" + << static_cast<char>(optopt) << "\n"; + rc = 1; + break; + default: + std::cerr << progname() + << ": getopt returned unexpected character code " + << std::hex << opt << "\n"; + rc = 1; + break; + } + + return rc; +} + +int Params::nonoption(const std::string& argv) +{ + if (!write_.empty()) { + std::cerr << progname() << ": Unexpected extra argument (" << argv << ")\n"; + return 1; + } + if (first_) read_ = argv; + else write_ = argv; + first_ = false; + return 0; +} + +int Params::getopt(int argc, char* const argv[]) +{ + int rc = Util::Getopt::getopt(argc, argv, optstring_); + // Further consistency checks + if (help_==false) { + if (rc==0 && read_.empty() ) { + std::cerr << progname() << ": Read and write files must be specified\n"; + rc = 1; + } + if (rc==0 && write_.empty() ) { + std::cerr << progname() << ": Write file must be specified\n"; + rc = 1; + } + if (preserve_ && iptc_ && exif_ && comment_ ) { + std::cerr << progname() << ": Option -p has no effect when all metadata types are specified.\n"; + rc = 1; + } + } + return rc; +} // Params::getopt + + +void Params::usage(std::ostream& os) const +{ + os << "\nReads and writes raw metadata. Use -h option for help.\n" + << "Usage: " << progname() + << " [-iecaph] readfile writefile\n"; +} + +void Params::help(std::ostream& os) const +{ + usage(os); + os << "\nOptions:\n" + << " -i Read Iptc data from readfile and write to writefile.\n" + << " -e Read Exif data from readfile and write to writefile.\n" + << " -c Read Jpeg comment from readfile and write to writefile.\n" + << " -a Read all metadata from readfile and write to writefile.\n" + << " -p Preserve existing metadata in writefile if not replaced.\n" + << " -h Display this help and exit.\n\n"; +} // Params::help + diff --git a/src/plugins/exiv2/metacopy.hpp b/src/plugins/exiv2/metacopy.hpp @@ -0,0 +1,86 @@ +// ***************************************************************** -*- C++ -*- +/* + * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net> + * + * This program is part of the Exiv2 distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/*! + @file metacopy.hpp + @brief Defines class Params, used for the command line handling + @version $Rev: 538 $ + @author Brad Schick (brad) <brad@robotbattle.com> + @date 13-Jul-04, brad: created + */ +#ifndef METACOPY_HPP_ +#define METACOPY_HPP_ + +#include "utils.hpp" + +class Params : public Util::Getopt { +private: + std::string optstring_; + bool first_; + +public: + bool help_; //!< Help option flag. + bool iptc_; //!< Iptc option flag. + bool exif_; //!< Exif option flag. + bool comment_; //!< JPEG comment option flag. + bool preserve_; //!< Preserve existing metadata option flag. + std::string read_; //!< Source file + std::string write_; //!< Destination file + +public: + /*! + @brief Default constructor. Note that optstring_ is initialized here. + */ + Params() : optstring_(":iecaph"), + first_(true), + help_(false), + iptc_(false), + exif_(false), + comment_(false), + preserve_(false) + {} + + /*! + @brief Call Getopt::getopt() with optstring, to initiate command line + argument parsing, perform consistency checks after all command line + arguments are parsed. + + @param argc Argument count as passed to main() on program invocation. + @param argv Argument array as passed to main() on program invocation. + + @return 0 if successful, >0 in case of errors. + */ + int getopt(int argc, char* const argv[]); + + //! Handle options and their arguments. + virtual int option(int opt, const std::string& optarg, int optopt); + + //! Handle non-option parameters. + virtual int nonoption(const std::string& argv); + + //! Print a minimal usage note to an output stream. + void usage(std::ostream& os =std::cout) const; + + //! Print further usage explanations to an output stream. + void help(std::ostream& os =std::cout) const; + +}; // class Params + +#endif // METACOPY_HPP_ diff --git a/src/plugins/exiv2/metacopy.lo b/src/plugins/exiv2/metacopy.lo @@ -0,0 +1,12 @@ +# metacopy.lo - a libtool object file +# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42) Debian: 224 $ +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# Name of the PIC object. +pic_object='.libs/metacopy.o' + +# Name of the non-PIC object. +non_pic_object=none +