/*
 * class GreymapWriter
 *
 * $Date$
 * $Revision$
 *
 */

#ifndef GREYMAP_WRITER_HH__
#define GREYMAP_WRITER_HH__

#include "WImage/GreymapFile.hh"

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

/**
 * An abstract image writer. The image is being written putting its content
 * from an {\em ImageArray} object into the file. A reference to the object 
 * holding the image is passed by the constructor, the actual object belongs 
 * to the outer world.
 */
/*abstract*/
class 
GreymapWriter: 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 stdout} 
   * @param data
   * the reference to the {\em ImageArray} object */
  GreymapWriter (char const *name, ImageArray<coeff> &data)
    : GreymapFile (name, data) {}

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

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

private:
  /** Fill the pixels array. This is not trivial as the coefficients may
   * contain negative values that have to be represented as grey-scale
   * pixels. */
  void pixelize (void);

protected: 
  /** Write different file formats (abstract). This is the method to be 
   * implemented for every image file format. It will be called by the
   * {\em write ()} method. 
   * @return 
   * 0 if successful, -1 on write error. */
  virtual int writefmt (void) = 0;
  
}; /* class GreymapWriter */

/** @} */

#endif /* GREYMAP_WRITER_HH__ */
