/*
 * class GreymapReader
 *
 * $Date$
 * $Revision$
 *
 */

#ifndef GREYMAP_READER_HH__
#define GREYMAP_READER_HH__

#include "WImage/GreymapFile.hh"
#include <fstream>

/** 
 * @addtogroup WImage 
 * @{ */

/**
 * An abstract greyscale image reader. The image is being read putting its 
 * content into an {\em ImageArray} object. A reference to such an object is 
 * passed by the constructor, the actual object belongs to the outer world.
 */
/*abstract*/
class 
GreymapReader: public GreymapFile
{
public:
  
  /** Constructor. Only calls the mother class' constructor to initialize
   * the {\em ImageArray} reference. 
   * @param name
   * the file name, if {\em NULL}, then {\em stdin}
   * @param data
   * the reference to the {\em ImageArray} object */
  GreymapReader (char const *name, ImageArray<coeff> &data) 
    : GreymapFile (name, data) {}

  /** Destructor - does nothing. */
  virtual ~GreymapReader (void) {}

  /** Read the image. All steps independent of the file format will be 
   * performed, like testing for file readability etc. 
   * @exception invalid_argument
   * invalid file format
   * @exception ios_base::failure
   * a read error has occured [not supported by all libraries, so eventually 
   * {\em invalid_argument} instead] */
  virtual void read (void);

private:
  /** Fill the coefficient array. If the file contains pixels rather than 
   * coefficients (like any bitmap format) this function will be called to 
   * create and fill the coefficient array. */
  void unpixel (void);
protected:
  /** Read different file formats (abstract). This is the method to be 
   * implemented for every image file format. It will be called by the
   * {\em read ()} method. 
   * @return 
   * 0 if successful, -1 on read error, -2 on file format error. */
  virtual int readfmt (void) = 0;
  
}; /* class GreymapReader */

/** @} */

#endif /* GREYMAP_READER_HH__ */
