Revamped image and introduced byte* interface (Brad, bs_1.patch with minor modifications by ahu)
parent
964e1df085
commit
9d72b7d1ec
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,101 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Test driver for image file i/o
|
||||||
|
|
||||||
|
eraseTest()
|
||||||
|
{
|
||||||
|
src=$1
|
||||||
|
test=${src}.etst
|
||||||
|
good=${src}.egd
|
||||||
|
|
||||||
|
#setup
|
||||||
|
cp $src $test
|
||||||
|
|
||||||
|
#run tests
|
||||||
|
../src/metacopy $test $test
|
||||||
|
|
||||||
|
#check results
|
||||||
|
diffCheck $test $good
|
||||||
|
}
|
||||||
|
|
||||||
|
copyTest()
|
||||||
|
{
|
||||||
|
num=$1
|
||||||
|
src=$2
|
||||||
|
dst=$3
|
||||||
|
test=${dst}.c${num}tst
|
||||||
|
good=${dst}.c${num}gd
|
||||||
|
|
||||||
|
#setup
|
||||||
|
cp $dst $test
|
||||||
|
|
||||||
|
#run tests
|
||||||
|
../src/metacopy -a $src $test
|
||||||
|
|
||||||
|
#check results
|
||||||
|
diffCheck $test $good
|
||||||
|
}
|
||||||
|
|
||||||
|
iptcTest()
|
||||||
|
{
|
||||||
|
num=$1
|
||||||
|
src=$2
|
||||||
|
dst=$3
|
||||||
|
test=${dst}.i${num}tst
|
||||||
|
good=${dst}.i${num}gd
|
||||||
|
|
||||||
|
#setup
|
||||||
|
cp $dst $test
|
||||||
|
|
||||||
|
#run tests
|
||||||
|
../src/metacopy -ip $src $test
|
||||||
|
|
||||||
|
#check results
|
||||||
|
diffCheck $test $good
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure to pass the test file first and the know good file second
|
||||||
|
diffCheck() {
|
||||||
|
|
||||||
|
test=$1
|
||||||
|
good=$2
|
||||||
|
|
||||||
|
#run diff and check results
|
||||||
|
diff -q --binary $test $good
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
let ++errors
|
||||||
|
else
|
||||||
|
rm $test
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_files=("table.jpg" "smiley1.jpg" "smiley2.jpg")
|
||||||
|
|
||||||
|
let errors=0
|
||||||
|
cd ../test
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "Erase all tests..."
|
||||||
|
foreach i ($test_files); eraseTest $i; end
|
||||||
|
eraseTest "glider.exv" #extra test
|
||||||
|
|
||||||
|
echo "Copy all tests..."
|
||||||
|
let c=0
|
||||||
|
foreach src ($test_files)
|
||||||
|
let ++c
|
||||||
|
foreach dst ($test_files); copyTest $c $src $dst; end
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Copy iptc tests..."
|
||||||
|
let c=0
|
||||||
|
foreach src ($test_files)
|
||||||
|
let ++c
|
||||||
|
foreach dst ($test_files); iptcTest $c $src $dst; end
|
||||||
|
end
|
||||||
|
|
||||||
|
echo '---------------------------------------------------------'
|
||||||
|
if [ $errors -eq 0 ]; then
|
||||||
|
echo 'All test cases passed'
|
||||||
|
else
|
||||||
|
echo $errors 'test case(s) failed!'
|
||||||
|
fi
|
@ -0,0 +1,193 @@
|
|||||||
|
// ***************************************************************** -*- C++ -*-
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 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 : $Name: $ $Revision: 1.1 $
|
||||||
|
Author(s): Brad Schick (brad) <schick@robotbattle.com>
|
||||||
|
History : 13-Jul-04, brad: created
|
||||||
|
*/
|
||||||
|
// *****************************************************************************
|
||||||
|
// included header files
|
||||||
|
#include "exif.hpp"
|
||||||
|
#include "types.hpp"
|
||||||
|
#include "metacopy.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
// *****************************************************************************
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Exiv2::Image* readImg = Exiv2::ImageFactory::instance().open(params.read_);
|
||||||
|
if (!readImg) {
|
||||||
|
std::cerr << params.progname() <<
|
||||||
|
": Could not read file (" << params.read_ << ")\n";
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
if (readImg->readMetadata()) {
|
||||||
|
std::cerr << params.progname() <<
|
||||||
|
": Could not read metadata from (" << params.read_ << ")\n";
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
readImg->detach();
|
||||||
|
|
||||||
|
Exiv2::Image* writeImg = Exiv2::ImageFactory::instance().open(params.write_);
|
||||||
|
if (!writeImg) {
|
||||||
|
std::cerr << params.progname() <<
|
||||||
|
": Could not read file (" << params.write_ << ")\n";
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.preserve_) {
|
||||||
|
if (writeImg->readMetadata()) {
|
||||||
|
std::cerr << params.progname() <<
|
||||||
|
": Could not read metadata from (" << params.write_ << ")\n";
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (params.iptc_) {
|
||||||
|
writeImg->setIptcData(readImg->iptcData(), readImg->sizeIptcData());
|
||||||
|
}
|
||||||
|
if (params.exif_) {
|
||||||
|
writeImg->setExifData(readImg->exifData(), readImg->sizeExifData());
|
||||||
|
}
|
||||||
|
if (params.comment_) {
|
||||||
|
writeImg->setComment(readImg->comment());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writeImg->writeMetadata()) {
|
||||||
|
std::cerr << params.progname() <<
|
||||||
|
": Could not write metadata to (" << params.write_ << ")\n";
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete readImg;
|
||||||
|
delete writeImg;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (Exiv2::Error& e) {
|
||||||
|
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -0,0 +1,86 @@
|
|||||||
|
// ***************************************************************** -*- C++ -*-
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 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 $Name: $ $Revision: 1.1 $
|
||||||
|
@author Brad Schick (brad) <schick@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_
|
Loading…
Reference in New Issue