Index: /trunk/archive/modules/include/phase2.h
===================================================================
--- /trunk/archive/modules/include/phase2.h	(revision 1104)
+++ /trunk/archive/modules/include/phase2.h	(revision 1105)
@@ -24,14 +24,33 @@
 /* Convolution */
 
+/** A convolution kernel */
+typedef struct {
+    int xMin, yMin;			///< Most negative indices
+    int xMax, yMax;			///< Most positive indices
+    float **kernel;			///< The kernel data
+} psKernel;
+
+/** Constructor */
+psKernel *psKernelAlloc(int xMin,	///< Size of the kernel in the negative x direction
+			int xMax,	///< Size of the kernel in the positive x direction
+			int yMin,	///< Size of the kernel in the negative y direction
+			int yMax	///< Size of the kernel in the positive y direction
+			);
+/** Destructor */
+void psKernelFree(psKernel *myKernel	///< Kernel to destroy
+		  );
+
 /** Returns the kernel of OT shifts made during the course of the exposure. */
-psImage *psPhase2GetKernel(psVector *xShifts, ///< List of OT shifts in x; integers
-			   psVector *yShifts ///< List of OT shifts in y; integers; xshifts->n == yShifts->n
-			   );
+psKernel *psPhase2GetKernel(const psVector *xShifts, ///< List of OT shifts in x; integers
+			    const psVector *yShifts ///< List of OT shifts in y; integers;
+						    ///< xshifts->n == yShifts->n
+			    );
 
 /** Returns an image that is the result of convolving the input image with the specified kernel. */
-psImage *psPhase2ConvolveWithKernel(psImage *out, ///< Output image, or NULL
-				    const psImage *in, ///< Input image to be convolved
-				    const psImage *kernel ///< Kernel by which to convolve
-				    );
+psImage *psConvolveWithKernel(psImage *out, ///< Output image, or NULL
+			      const psImage *in, ///< Input image to be convolved
+			      const psKernel *kernel, ///< Kernel by which to convolve
+			      bool direct ///< Do direct convolution?  If not, use FFT
+			      );
 
 /************************************************************************************************************/
@@ -55,21 +74,56 @@
 		       );
 
+/** A 1D cubic-spline */
+typedef struct {
+    int n;				///< Number of spline pieces
+    float *coeff[4];			///< Coefficients.  There are 4 coefficients for each spline piece.
+    float *coeffErr[4];			///< Errors in the coefficients.
+    bool *mask[4];			///< Mask for the coefficients.
+    float *domains;			///< The boundaries between each spline piece.  Size is n+1.
+} psSpline1D;
+
+/** Constructors */
+psSpline1D *psSpline1DAlloc(int n,	///< Number of spline pieces
+			    float min,	///< Minimum data value
+			    float max	///< Maximum data value
+			    );
+psSpline1D *psSpline1DAllocGeneric(const psVector *bounds ///< Boundaries between each spline piece.  Number
+							  ///< of spline pieces can hence be inferred.
+				   );
+/** Destructor */
+void psSpline1DFree(psSpline1D *mySpline ///< Spline to destroy
+		    );
+/** Evaluator */
+float psSpline1DEval(const psSpline1D *spline, ///< Spline to evaluate
+		     float x		///< Coordinates at which to evaluate
+		     );
+
+
 /** Overscan axis */
 typedef enum {
-    PS_OVERSCAN_NONE = 0,		///< No overscan subtraction
-    PS_OVERSCAN_ROWS = 1,		///< Subtract rows
-    PS_OVERSCAN_COLUMNS = 2, 		///< Subtract columns
-    PS_OVERSCAN_ROWS_FIT = -1,		///< Subtract a fit to rows
-    PS_OVERSCAN_COLUMNS_FIT = -2,	///< Subtract a fit to columns
-    PS_OVERSCAN_ALL = 3			///< Subtract the statistic of all pixels in overscan region
+    PS_OVERSCAN_NONE,			///< No overscan subtraction
+    PS_OVERSCAN_ROWS,			///< Subtract rows
+    PS_OVERSCAN_COLUMNS, 		///< Subtract columns
+    PS_OVERSCAN_ALL			///< Subtract the statistic of all pixels in overscan region
 } psOverscanAxis;
+
+/** Fit type for bias */
+typedef enum {
+    PS_OVERSCAN_FIT_NONE,		///< No fit to bias
+    PS_OVERSCAN_FIT_LINEAR,		///< Do linear interpolation on bias
+    PS_OVERSCAN_FIT_POLYNOMIAL,		///< Fit polynomial to bias
+    PS_OVERSCAN_FIT_CHEBYSHEV,		///< Fit chebyshev to bias
+    PS_OVERSCAN_FIT_SPLINE		///< Fit cubic splines to bias
+} psBiasFit;
 
 /** Subtracts an overscan and bias from the input image. */
 psReadout *psPhase2SubtractBias(psReadout *in, ///< Input image to be de-biased, and output
-				psPolynomial1D *polySpec, ///< Polynomial specification to use for fit,
-							  ///< outputed
+				void *fitSpec, ///< Polynomial/Spline/Some other function(?) specification,
+				               ///< Also outputted
+				psOverscanAxis overscanAxis, ///< Overscan axis
+				psBiasFit fit, ///< How to fit the bias
+				int nBin, ///< Number of bins for overscan vector before fitting
 				const psList *regions, ///< Linked list of psImageRegion types.
-				psOverscanAxis overscanAxis, ///< Overscan axis
-				const psStatsOptions *stat, ///< Statistic to use
+				const psStats *stat, ///< Statistic to use
 				const psImage *bias ///< Bias (or dark) image to subtract
 				);
