00001 /** @file psImage.h 00002 * 00003 * @brief Contains basic image definitions and operations 00004 * 00005 * This file defines the basic type for an image struct and functions useful 00006 * in manupulating images. 00007 * 00008 * @ingroup Image 00009 * 00010 * @author Robert DeSonia, MHPCC 00011 * @author Ross Harman, MHPCC 00012 * 00013 * @version $Revision: 1.1.1.1 $ $Name: $ 00014 * @date $Date: 2005/06/15 21:08:12 $ 00015 * 00016 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00017 */ 00018 #ifndef PS_IMAGE_H 00019 #define PS_IMAGE_H 00020 00021 #include <complex.h> 00022 #include <stdio.h> 00023 #include "psType.h" 00024 #include "psArray.h" 00025 00026 /// @addtogroup Image 00027 /// @{ 00028 00029 /** enumeration of options in interpolation 00030 * 00031 */ 00032 typedef enum { 00033 PS_INTERPOLATE_FLAT, ///< 'flat' interpolation (nearest pixel) 00034 PS_INTERPOLATE_BILINEAR, ///< bi-linear interpolation 00035 PS_INTERPOLATE_LANCZOS2, ///< Sinc interpolation with 4x4 pixel kernel 00036 PS_INTERPOLATE_LANCZOS3, ///< Sinc interpolation with 6x6 pixel kernel 00037 PS_INTERPOLATE_LANCZOS4, ///< Sinc interpolation with 8x8 pixel kernel 00038 PS_INTERPOLATE_BILINEAR_VARIANCE, ///< Variance version of PS_INTERPOLATE_BILINEAR 00039 PS_INTERPOLATE_LANCZOS2_VARIANCE, ///< Variance version of PS_INTERPOLATE_LANCZOS2 00040 PS_INTERPOLATE_LANCZOS3_VARIANCE, ///< Variance version of PS_INTERPOLATE_LANCZOS3 00041 PS_INTERPOLATE_LANCZOS4_VARIANCE, ///< Variance version of PS_INTERPOLATE_LANCZOS4 00042 PS_INTERPOLATE_NUM_MODES ///< enum end-marker; does not coorespond to a interpolation mode 00043 } psImageInterpolateMode; 00044 00045 /** Basic image data structure. 00046 * 00047 * Struct for maintaining image data of varying types. It also contains 00048 * information about image size, parent images and children images. 00049 * 00050 */ 00051 typedef struct psImage 00052 { 00053 const psType type; ///< Image data type and dimension. 00054 const psU32 numCols; ///< Number of columns in image 00055 const psU32 numRows; ///< Number of rows in image. 00056 const psS32 col0; ///< Column position relative to parent. 00057 const psS32 row0; ///< Row position relative to parent. 00058 00059 union { 00060 psU8** U8; ///< Unsigned 8-bit integer data. 00061 psU16** U16; ///< Unsigned 16-bit integer data. 00062 psU32** U32; ///< Unsigned 32-bit integer data. 00063 psU64** U64; ///< Unsigned 64-bit integer data. 00064 psS8** S8; ///< Signed 8-bit integer data. 00065 psS16** S16; ///< Signed 16-bit integer data. 00066 psS32** S32; ///< Signed 32-bit integer data. 00067 psS64** S64; ///< Signed 64-bit integer data. 00068 psF32** F32; ///< Single-precision float data. 00069 psF64** F64; ///< Double-precision float data. 00070 psC32** C32; ///< Single-precision complex data. 00071 psC64** C64; ///< Double-precision complex data. 00072 psPtr** PTR; ///< Void pointers. 00073 psPtr* V; ///< Pointer to data. 00074 } data; ///< Union for data types. 00075 const struct psImage* parent; ///< Parent, if a subimage. 00076 psArray* children; ///< Children of this region. 00077 00078 psPtr rawDataBuffer; ///< Raw data buffer for Allocating/Freeing Images 00079 } 00080 psImage; 00081 00082 /** Basic image region structure. 00083 * 00084 * Struct for specifying a rectangular area in an image. 00085 * 00086 */ 00087 typedef struct 00088 { 00089 psF32 x0; ///< the first column of the region. 00090 psF32 x1; ///< the last column of the region. 00091 psF32 y0; ///< the first row of the region. 00092 psF32 y1; ///< the last row of the region. 00093 } 00094 psRegion; 00095 00096 /** Create an image of the specified size and type. 00097 * 00098 * Uses psLib memory allocation functions to create an image struct of the 00099 * specified size and type. 00100 * 00101 * @return psImage* : Pointer to psImage. 00102 * 00103 */ 00104 psImage* psImageAlloc( 00105 psU32 numCols, ///< Number of rows in image. 00106 psU32 numRows, ///< Number of columns in image. 00107 const psElemType type ///< Type of data for image. 00108 ); 00109 00110 /** Create a psRegion with the specified attributes. 00111 * 00112 * @return psRegion : a cooresponding psRegion. 00113 */ 00114 psRegion psRegionSet( 00115 psF32 x0, ///< the first column of the region. 00116 psF32 x1, ///< the last column of the region + 1. 00117 psF32 y0, ///< the first row of the region. 00118 psF32 y1 ///< the last row of the region + 1. 00119 ); 00120 00121 /** Create a psRegion with the attribute values given as a string. 00122 * 00123 * Create a psRegion with the attribute values given as a string. The format 00124 * shall be of the standard IRAF form '[x0:x1,y0:y1]' 00125 * 00126 * @return psRegion: A new psRegion struct, or NULL is not successful. 00127 */ 00128 psRegion psRegionFromString( 00129 char* region ///< image rectangular region in the form '[x0:x1,y0:y1]' 00130 ); 00131 00132 /** Create a string of the standard IRAF form '[x0:x1,y0:y1]' from a psRegion. 00133 * 00134 * @return char*: A new string representing the psRegion as text, or NULL 00135 * is not successful. 00136 */ 00137 char* psRegionToString( 00138 psRegion region ///< the psRegion to convert to a string 00139 ); 00140 00141 /** Resize a given image to the given size/type. 00142 * 00143 * @return psImage* Resized psImage. 00144 * 00145 */ 00146 psImage* psImageRecycle( 00147 psImage* old, ///< the psImage to recycle by resizing image buffer 00148 psU32 numCols, ///< the desired number of columns in image 00149 psU32 numRows, ///< the desired number of rows in image 00150 const psElemType type ///< the desired datatype of the image 00151 ); 00152 00153 /** Copy an image to a new buffer 00154 * 00155 * @return True if image copied or false if error 00156 */ 00157 bool p_psImageCopyToRawBuffer( 00158 void* buffer, ///< the buffer used to copy the image 00159 const psImage* input, ///< the input image to be copied 00160 psElemType type ///< the datatype of the image to be copied 00161 ); 00162 00163 /** Frees all children of a psImage. 00164 * 00165 * @return psS32 Number of children freed. 00166 * 00167 */ 00168 psS32 psImageFreeChildren( 00169 psImage* image ///< psImage in which all children shall be deallocated 00170 ); 00171 00172 /** get an element of an image as a psF64. 00173 * 00174 * @return psF64 pixel value at specified location 00175 */ 00176 psF64 p_psImageGetElementF64( 00177 psImage* image, ///< input image 00178 int col, ///< pixel column 00179 int row ///< pixel row 00180 ); 00181 00182 /** print image pixel values. 00183 * 00184 * @return bool TRUE is successful, otherwise FALSE. 00185 */ 00186 bool p_psImagePrint( 00187 FILE *f, ///< Destination stream 00188 psImage *a, ///< image to print 00189 char *name ///< name of the image (for title) 00190 ); 00191 00192 /** Interpolate image pixel value given floating point coordinates. 00193 * 00194 * @return psF32 Pixel value interpolated from image or unexposedValue if 00195 * given x,y doesn't coorespond to a valid image location 00196 */ 00197 psC64 psImagePixelInterpolate( 00198 const psImage* input, ///< input image for interpolation 00199 float x, ///< column location to derive value of 00200 float y, ///< row location ot derive value of 00201 const psImage* mask, ///< if not NULL, the mask of the input image 00202 psU32 maskVal, ///< the mask value 00203 psC64 unexposedValue, ///< return value if x,y location is not in image. 00204 psImageInterpolateMode mode ///< interpolation mode 00205 ); 00206 00207 #define PIXEL_INTERPOLATE_FCN_PROTOTYPE(SUFFIX, RETURNTYPE) \ 00208 inline RETURNTYPE p_psImagePixelInterpolate##SUFFIX( \ 00209 const psImage* input, /**< input image for interpolation */ \ 00210 float x, /**< column location to derive value of */ \ 00211 float y, /**< row location ot derive value of */ \ 00212 const psImage* mask, /**< if not NULL, the mask of the input image */ \ 00213 psU32 maskVal, /**< the mask value */ \ 00214 RETURNTYPE unexposedValue /**< return value if x,y location is not in image. */ \ 00215 ); 00216 00217 #define PIXEL_INTERPOLATE_FCNS(MODE) \ 00218 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U8,psF64) \ 00219 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U16,psF64) \ 00220 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U32,psF64) \ 00221 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U64,psF64) \ 00222 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S8,psF64) \ 00223 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S16,psF64) \ 00224 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S32,psF64) \ 00225 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S64,psF64) \ 00226 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F32,psF64) \ 00227 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F64,psF64) \ 00228 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C32,psC64) \ 00229 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C64,psC64) 00230 00231 #ifndef SWIG 00232 PIXEL_INTERPOLATE_FCNS(FLAT) 00233 PIXEL_INTERPOLATE_FCNS(BILINEAR) 00234 PIXEL_INTERPOLATE_FCNS(BILINEAR_VARIANCE) 00235 #endif // ! SWIG 00236 00237 #undef PIXEL_INTERPOLATE_FCN_PROTOTYPE 00238 #undef PIXEL_INTERPOLATE_FCNS 00239 00240 /// @} 00241 00242 #endif // PS_IMAGE_H
1.4.1