/*
 * Diff two images by counting the counterences
 *
 * $Date$
 * $Revision$
 *
 */

#include <iostream>
#include <stdexcept>
#include <cstdio>
#include <cmath>
#include <WTools.hh>

#if !(defined __WATCOMC__ && __WATCOMC__ < 1230)
using namespace std;
#endif

int 
main (int argc, char *argv[])
{
  cout << "pgmcount version " << WAVE_VERSION << " (c) 2001-2004 by Herbert"
#ifdef PFI
       << " (pfi support enabled)"
#endif
       << endl;

  if (argc != 3)
    {
      cerr << "Usage: pgmcount <file1> <file2>" << endl;
      return 1;
    }
  Image *img1 = NEW (StillImage ());
  Image *img2 = NEW (StillImage ());

  try 
    {
      img1->read (argv[1]);
    }
  catch (const exception &error)
    {
      cerr << "Error reading " << argv[1] << ": " << error.what () << endl;
      return 1;
    }
  
  try 
    {
      img2->read (argv[2]);
    }
  catch (const exception &error)
    {
      cerr << "Error reading " << argv[2] << ": " << error.what () << endl;
      return 1;
    }
  
  if (img1->size () != img2->size ())
    {
      cerr << "Error, image dimensions differ." << endl;
      return 1;
    }
  
  int result = 0;
  for (int i = 0; i < img1->size (); i++)
    {
      if (fabs (img1->at (i) - img2->at (i)) > COEFF_EPSILON)
        {
          ++result;
        }
    }
  
  cout << "pgmcount: " << result << " differences found." << endl;
  
  return 0;
}
