/*
 * Print some statistics on an image
 *
 * $Date$
 * $Revision$
 *
 */

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

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

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

  char *fname;

  if (argc > 1)
    {
      fname = argv[1];
      cout << "File " << fname << endl;
    }
  else
    {
      fname = NULL;
      cout << "File (stdin)" << endl;
    }

  Image *image = NEW (StillImage ());
  ImageInformation *ii;

  try
    {
      if (fname == NULL)
        {
          image->read (fname, fn_pgm);
        }
      else
        {
          image->read (fname);
        }
    }
  catch (const exception &error)
    {
      cerr << "Reading image: " << error.what () <<endl;
      return 1;
    }

  ii = NEW (ImageInformation (*image));

  cout << "Average value (absolute): " << ii->aaverage () << endl;
  cout << "Average value (signed)  : " << ii->saverage () << endl;
  cout << "Square variance: " << ii->sqvariance () << endl;
  cout << "Standard deviation: " << ii->sdeviation () << endl;

  DELETE (ii);
  DELETE (image);

  return 0;
}

