Index: /trunk/archive/pslib/include/psImage.h
===================================================================
--- /trunk/archive/pslib/include/psImage.h	(revision 243)
+++ /trunk/archive/pslib/include/psImage.h	(revision 243)
@@ -0,0 +1,279 @@
+# ifndef PS_IMAGE_H
+# define PS_IMAGE_H
+
+/** \file psImage.h
+ *  \brief Basic image definitions and operations.
+ *  \ingroup AstroGroup
+ */
+
+/** General image manipulation functions.
+ */
+
+/// basic image data structure.
+typedef struct psImage {
+    psType type; 			///< image data type and dimension
+    int nx, ny;				///< size of image 
+    int x0, y0;				///< data region relative to parent 
+    psF32 **rows;		        ///< == rows_f32 
+    psS8  **rows_s8;			///< pointers to psS8 data 
+    psS16 **rows_s16;			///< pointers to psS16 data 
+    psS32 **rows_s32;			///< pointers to psS32 data 
+    psU8  **rows_u8;			///< pointers to psU8 data 
+    psU16 **rows_u16;			///< pointers to psU16 data 
+    psU32 **rows_u32;			///< pointers to psU32 data 
+    psF32 **rows_f32;			///< pointers to psF32 data 
+    psF64 **rows_f64;			///< pointers to psF64 data 
+    struct psImage *parent;		///< parent, if a subimage 
+    struct psImage *children;		///< children of this region 
+    int Nchildren;			///< number of subimages 
+    struct psMetaDataSet *md;		///< metadata associated with image
+    psObjectArray *objtable;		///< objects associated with image
+} psImage;
+
+/*** Image structure manipulation ***/
+/// Create an image of the specified size and type.
+typedef int PS_IMAGE_DEPTH;		// RHL Added this to make the psImage compile XXX
+
+psImage *
+psImageAlloc (int nx,			///< image width 
+	      int ny,			///< image height 
+	      PS_IMAGE_DEPTH depth	///< image depth 
+    );
+
+/// Create a subimage of the specified area.
+psImage *
+psImageSubset (psImage *image,		///< parent image 
+	       int nx,			///< subimage width (<= image.nx - x0)  
+	       int ny,			///< subimage width (<= image.ny - y0)  
+	       int x0,			///< subimage x-offset (0 <= x0 < nx)   
+	       int y0			///< subimage y-offset (0 <= y0 < ny)   
+    );
+
+/// Destroy the specified image (destroy children if they exist).
+void 
+psImageFree (psImage *image		///< free this image
+);
+
+/// Destroy the children of the specified image.
+int 
+psImageFreeChildren (psImage *image	///< free children of this image
+);
+
+/// Create a copy of the specified image.
+psImage *
+psImageCopy (psImage *output, 		///< target structure for output image data
+	     psImage *input		///< copy this image 
+);
+
+/*** various image pixel extractions ***/
+
+typedef enum { PS_STAT_MODE_MEDIAN } psStatMode;
+
+/// Extract pixels from rectlinear region to a vector.
+psFloatArray *
+psImageSlice (psImage *input, 		///< extract slice from this image
+	      int x, 			///< starting x coord of region to slice
+	      int y, 			///< starting y coord of region to slice
+	      int nx, 			///< width of region in x
+	      int ny, 			///< width of region in y
+	      int direction,		///< direction of vector along slice
+	      psStats *stats		///< defines statistics used to find output values
+);
+
+/// Extract pixels along a line to a vector.
+psFloatArray *
+psImageCut (psImage *input, 		///< extract cut from this image
+	    float xs, 			///< starting x coord of cut
+	    float ys, 			///< starting y coord of cut
+	    float xe, 			///< ending x coord of cut
+	    float ye, 			///< ending y coord of cut
+	    float dw, 			///< width of cut
+	    psStats *stats		///< defines statistics used to find output values
+    );
+
+/// Extract radial annulii data to a vector.
+psFloatArray *
+psImageRadialCut (psImage *input, 	///< extract profile from this image
+		  float x, 		///< center x coord of annulii
+		  float y, 		///< center y coord of annulii
+		  float radius, 	///< outer radius of annulii
+		  float dr,		///< radial step size of annulii
+		  psStats *stats		///< defines statistics used to find output values
+    );
+
+/// Extract a 2-d contour from an image at the given threshold.
+psFloatArray *
+psImageContour (psImage *input, 	///< create contour for this image
+		float threshold,	///< contour image at this threshold
+		int binning		///< bin image by this value for contour calculation
+);
+
+/*** various image geometry manipulation ***/
+/// Rebin image to new scale.
+psImage *
+psImageRebin (psImage *input, 		///< rebin this image
+	      float scale, 		///< rebinning scale: doutput = scale*dinput
+	      psStats *stats		///< defines statistics used to find output values
+);
+
+/// Rotate image by given angle.
+psImage *
+psImageRotate (psImage *input, 		///< rotate this image
+	       float angle		///< rotate by this amount (degrees)
+);
+
+/// Shift image by an arbitrary number of pixels in either direction.
+/// Drop edge pixels, and set newly exposed pixels to 'exposed'.
+psImage *
+psImageShift (psImage *input, 		///< shift this image
+	      float dx, 		///< shift by this amount in x
+	      float dy, 		///< shift by this amount in y
+	      float exposed		///< set exposed pixels to this value
+);
+
+/// Roll image by an integer number of pixels in either direction.
+/// Edge pixels wrap to the other side (no values are lost).
+psImage *
+psImageRoll (psImage *input, 		///< roll this image
+	     int dx, 			///< roll this amount in x
+	     int dy			///< roll this amount in y
+);
+
+/// Determine statistics for image (or subimage).
+psStats *
+psImageGetStats (psImage *input, 	///< image (or subimage) to calculate stats
+		 psStats *stats);	///< defines statistics to be calculated
+
+/// Construct a histogram from an image (or subimage).
+psHistogram *
+psImageHistogram (psHistogram *hist,	///< input histogram description & target
+		  psImage *input	///< determine histogram of this image
+    );
+
+/// Fit a 2-D polynomial surface to an image.
+psPolynomial2D *
+psImageFitPolynomial (psImage *input, 	///< image to fit
+		      psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
+);
+
+/// Evaluate a 2-D polynomial surface to image pixels.
+int
+psImageEvalPolynomial (psImage *input, 	///< image to fit
+		       psPolynomial2D *coeffs ///< coefficient structure carries in desired terms
+);
+
+/*** image input/output routines ***/
+/// Read an image or subimage from a named file.
+psImage *
+psImageReadSection (psImage *output, 	///< place data in this structure for output 
+		    int x, 		///< starting x coord of region
+		    int y, 		///< starting y coord of region
+		    int dx, 		///< x size of region (-1 for full range)
+		    int dy, 		///< y size of region (-1 for full range)
+		    int z, 		///< plane of interest
+		    char *extname, 	///< MEF extension name ("PHU" for primary header)
+		    char *filename	///< file to read data from
+);
+
+/// Read an image or subimage from file descriptor.
+psImage *
+psImageFReadSection (psImage *output,	///< place data in this structure for output 
+		     int x,		///< starting x coord of region		   
+		     int y,		///< starting y coord of region		   
+		     int dx,		///< x size of region (-1 for full range)	   
+		     int dy,		///< y size of region (-1 for full range)	   
+		     int z,		///< plane of interest			   
+		     char *extname,	///< MEF extension name ("PHU" for primary header)			   
+		     FILE *f		///< file descriptor to read data from		   
+);
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageWriteSection (psImage *input,    ///< image to write out
+		     int x, 		///< starting x coord of region		   
+		     int y, 		///< starting y coord of region		   
+		     int z, 		///< plane of interest			   
+		     char *extname, 	///< MEF extension name ("PHU" for primary header)			   
+		     char *filename	///< file to write data to		   
+);
+
+/// Write an image section to named file (which may exist).
+psImage *
+psImageFWriteSection(psImage *input,	///< image to write out
+		     int x, 		///< starting x coord of region		   
+		     int y, 		///< starting y coord of region		   
+		     int z, 		///< plane of interest			   
+		     char *extname, 	///< MEF extension name			   
+		     FILE *f		///< file descriptor to write data to		   
+);
+
+/// Read only header from image file.
+struct psMetadata *
+psImageReadHeader(struct psMetadata *output, 	///< read data to this structure
+		  char *extname, 	///< MEF extension name ("PHU" for primary header)
+		  char *filename	///< file to read from
+); 
+
+/// Read only header from image file descriptor.
+struct psMetadata *
+psImageFReadHeader (struct psMetadata *output, ///< read data to this structure
+		   char *extname, 	///< MEF extension name ("PHU" for primary header)
+		   FILE *f		///< file descriptor to read from
+); 
+
+/*** image FFT operations ***/
+/// Perform an FFT on the image.
+psImage *
+psImageFFT (psImage *input, 		///< image to FFT
+	    int direction		///< FFT direction 
+);
+
+/*** basic pixel manipulations ***/
+/// Clip image values outside of range to given values.
+int
+psImageClip (psImage *input, 		///< clip this image
+	     float min, 		///< clip pixels with values < min
+	     float vmin, 		///< set min-clipped pixels to vmin
+	     float max, 		///< clip pixels with values > max
+	     float vmax			///< set max-clipped pixels to vmax
+);
+
+/// Clip NaN image pixels to given value.
+int
+psImageClipNaN (psImage *input, 	///< clip this image
+		float value		///< set nan pixels to this value
+);
+
+/*** image arithmetic ***/
+/// Perform a binary operation on two images.
+psImage *
+psImageBinaryOp (psImage *out,		///< destination image (may be NULL) 
+		 psImage *in1,		///< first input image 
+		 char *operator,	///< operator 
+		 psImage *in2		///< second input image 
+);
+
+/// Perform a unary operation on an image.
+psImage *
+psImageUnaryOp (psImage *out,		///< destination image (may be NULL) 
+		psImage *in1,		///< input image 
+		char *operator		///< operator 
+);
+
+/// Overlay subregion of image with another image.
+int 
+psImageOverlaySection (psImage *image,		///< input image 
+		psImage *overlay,	///< image to overlay 
+		int x0,			///< x offset of overlay subimage 
+		int y0,			///< y offset of overlay subimage 
+		char *operator		///< overlay operation 
+);
+
+# endif
+/* image overlay operations 
+    PS_OVERLAY_EQUALS   = '=', 
+    PS_OVERLAY_ADD      = '+', 
+    PS_OVERLAY_SUBTRACT = '-', 
+    PS_OVERLAY_MULTIPLY = '*', 
+    PS_OVERLAY_DIVIDE   = '/', 
+*/
