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
|
/*
* Copyright (C) 2005 - 2023 René Rebe, ExactCODE GmbH
* (C) 2005 Archivista GmbH, CH-8042 Zuerich
*
* 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 <iostream>
#include "Image.hh"
#include "Codecs.hh"
#include "ArgumentList.hh"
#include "empty-page.hh"
#include "config.h"
using namespace Utility;
ArgumentList arglist;
bool usage(const Argument<bool>& arg)
{
std::cerr << "ExactImage Empty page detector, version " VERSION << std::endl
<< "Copyright (C) 2005 - 2023 René Rebe, ExactCODE GmbH" << std::endl
<< "Usage:" << std::endl;
arglist.Usage(std::cerr);
exit(1);
}
int main (int argc, char* argv[])
{
// setup the argument list
Argument<bool> arg_help ("h", "help",
"display this help text and exit");
Argument<std::string> arg_input ("i", "input", "input file",
1, 1);
Argument<int> arg_margin ("m", "margin",
"border margin to skip", 16, 0, 1);
Argument<float> arg_percent ("p", "percentage",
"coverate for non-empty page", 0.05, 0, 1);
arg_help.Bind (usage);
arglist.Add (&arg_help);
arglist.Add (&arg_input);
arglist.Add (&arg_margin);
arglist.Add (&arg_percent);
// parse the specified argument list - and maybe output the Usage
if (!arglist.Read (argc, argv))
{
usage(arg_help);
}
const int margin = arg_margin.Get();
if (margin % 8 != 0) {
std::cerr << "For speed reasons, the margin has to be a multiple of 8."
<< std::endl;
return 1;
}
Image image;
if (!ImageCodec::Read (arg_input.Get(), image)) {
std::cerr << "Error reading: " << arg_input.Get() << std::endl;
return 1;
}
int set_pixels;
const double percent = arg_percent.Get();
bool is_empty = detect_empty_page (image, percent, margin, margin, &set_pixels);
double image_percent = (float) set_pixels / (image.w * image.h) * 100;
std::cerr << "The image has " << set_pixels
<< " dark pixels from a total of "
<< image.w * image.h
<< " (" << image_percent << "%)." << std::endl;
if (!is_empty) {
std::cerr << "non-empty" << std::endl;
return 1;
}
std::cerr << "empty" << std::endl;
return 0;
}
|