//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
// one that was being worked on.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/** @file  pmSubtractBias.h
 *
 *  This file will contain a module which will subtract the detector bias
 *  in place from an input image.
 *
 *  @author GLG, MHPCC
 *
 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2006-06-17 01:50:43 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */

#if !defined(PM_SUBTRACT_BIAS_H)
#define PM_SUBTRACT_BIAS_H

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include<stdio.h>
#include<math.h>
#include "pslib.h"

#include "pmFPA.h"

typedef enum {
    PM_OVERSCAN_NONE,                         ///< No overscan subtraction
    PM_OVERSCAN_EDGE,                         ///< Subtract the statistic of pixels along the to-be-determined readout direction
    PM_OVERSCAN_ROWS,                         ///< Subtract rows
    PM_OVERSCAN_COLUMNS,                      ///< Subtract columns
    PM_OVERSCAN_ALL                           ///< Subtract the statistic of all pixels in overscan region
} pmOverscanAxis;

typedef enum {
    PM_FIT_NONE,                        ///< No fit
    PM_FIT_POLY_ORD,                    ///< Fit ordinary polynomial
    PM_FIT_POLY_CHEBY,                  ///< Fit Chebyshev polynomial
    PM_FIT_SPLINE                       ///< Fit cubic splines
} pmFit;

typedef struct
{
    // Inputs
    bool single;                // Reduce all overscan regions to a single value?
    pmFit fitType;              // Type of fit to overscan
    unsigned int order;         // Order of polynomial, or number of spline pieces
    psStats *stat;              // Statistic to use when reducing the minor direction
    // Outputs
    psPolynomial1D *poly;       // Result of polynomial fit
    psSpline1D *spline;         // Result of spline fit
}
pmOverscanOptions;

pmOverscanOptions *pmOverscanOptionsAlloc(bool single, pmFit fitType, unsigned int order, psStats *stat);

bool pmSubtractBias(pmReadout *in, pmOverscanOptions *overscanOpts,
                    const pmReadout *bias, const pmReadout *dark);

#if 0
pmReadout *pmSubtractBias(pmReadout *in,                ///< The input pmReadout image
                          void *fitSpec,                ///< A polynomial or spline, defining the fit type.
                          const psList *overscans,      ///< A psList of overscan images
                          pmOverscanAxis overScanAxis,  ///< Defines how overscans are applied
                          psStats *stat,                ///< The statistic to be used in combining overscan data
                          int nBin,                     ///< The amount of binning to be done image pixels.
                          pmFit fit,                    ///< PM_FIT_SPLINE, PM_FIT_POLYNOMIAL, or PM_FIT_NONE
                          const pmReadout *bias);       ///< A possibly NULL bias pmReadout which is to be subtracted
#endif

#endif
