1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* The ExactImage library's any to multi-page TIFF converted
* Copyright (C) 2008 - 2023 René Rebe, ExactCODE GmbH
*
* 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; version 2. A copy of the GNU General
* Public License can be found in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
* ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* Alternatively, commercial licensing options are available from the
* copyright holder ExactCODE GmbH Germany.
*/
#include <math.h>
#include <iostream>
#include <fstream>
#include "ArgumentList.hh"
#include "Codecs.hh"
#include "config.h"
using namespace Utility;
ArgumentList arglist(true); // enable residual gathering
bool usage(const Argument<bool>& arg)
{
std::cerr << "any to multi-page TIFF convert, version " << VERSION << std::endl
<< "Copyright (C) 2008 - 2023 René Rebe, ExactCODE GmbH" << std::endl
<< "Usage:" << std::endl;
arglist.Usage(std::cerr);
std::cerr << " ...\n\t\tinput file(s)" << std::endl;
exit(1);
}
int main (int argc, char* argv[])
{
// setup the argument list
Argument<bool> arg_help ("h", "help",
"display this help text and exit");
arg_help.Bind (usage);
arglist.Add (&arg_help);
Argument<std::string> arg_output ("o", "output",
"output file",
1, 1, true, true);
arglist.Add (&arg_output);
// parse the specified argument list - and maybe output the Usage
if (!arglist.Read(argc, argv) || arglist.Residuals().empty())
{
if (arglist.Residuals().empty())
std::cerr << "Error: No arguments as input!" << std::endl;
usage(arg_help);
}
int errors = 0;
int tiff_page = 1;
std::fstream stream(arg_output.Get().c_str(), std::ios::in | std::ios::out | std::ios::trunc);
ImageCodec* codec = ImageCodec::MultiWrite(&stream, "tiff", ImageCodec::getExtension(arg_output.Get()));
if(!codec) {
std::cerr << "Error writing file: " << arg_output.Get() << std::endl;
return 1;
}
Image image;
const std::vector<std::string>& filenames = arglist.Residuals();
for (std::vector<std::string>::const_iterator file = filenames.begin();
file != filenames.end ();
++file)
{
for (int i = 0, n = 1; i < n; ++i)
{
int ret = ImageCodec::Read (*file, image, "", i);
if (ret == 0) {
std::cerr << "Error reading: " << *file << std::endl;
++errors;
break;
}
else {
if (i == 0) n = ret;
// std::cerr << "adding [" << tiff_page << "] " << *file << std::endl;
codec->Write (image, 75, ""/*compression*/, tiff_page++);
}
}
}
delete(codec); codec = 0;
return errors;
}
|