/*
 * Implementation of class PfgReader
 *
 * $Date$
 * $Revision$
 *
 */

#include "WImage/ImageArray.hh"
#include "WImage/PfgReader.hh"
#include "WImage/debug.h"
#include <pfi.h>
#include <cstdio>

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

int
PfgReader::readfmt (void)
{
  
  int xsize = 0, ysize = 0;
  double *values = NULL;
  int colors, rgbmodel;
  
  if (pfi_properties_name ((char*)m_fname, &ysize, &xsize, 
                           &colors, &rgbmodel) < 0)
    {
      return -2;
    }

  values = NEW (double [ysize * xsize * colors * (int)sizeof (*values)]);

  if (pfi_read_name ((char*)m_fname, ysize, xsize, colors, values) < 0)
    {
      DELETE (values);
      return -2;
    }
  
  if (colors > 1 || rgbmodel != 0)
    {
      return -2;
    }

  m_coeffs->import (ysize, xsize, (coeff*)values);
  
  return 0;
}

