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.49 $ $Name: rel5_0 $ 00014 * @date $Date: 2005/03/18 02:35:14 $ 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 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; 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 * Uses psLib memory allocation functions to create a psRegion the 00113 * specified x0, x1, y0, and y1. 00114 * 00115 * @return psRegion* : Pointer to psRegion. 00116 * 00117 */ 00118 psRegion* psRegionAlloc( 00119 psF32 x0, ///< the first column of the region. 00120 psF32 x1, ///< the last column of the region. 00121 psF32 y0, ///< the first row of the region. 00122 psF32 y1 ///< the last row of the region. 00123 ); 00124 00125 /** Create a psRegion with the attribute values given as a string. 00126 * 00127 * Create a psRegion with the attribute values given as a string. The format 00128 * shall be of the standard IRAF form '[x0:x1,y0:y1]' 00129 * 00130 * @return psRegion*: A new psRegion struct, or NULL is not successful. 00131 */ 00132 psRegion* psRegionFromString( 00133 char* region ///< image rectangular region in the form '[x0:x1,y0:y1]' 00134 ); 00135 00136 /** Create a string of the standard IRAF form '[x0:x1,y0:y1]' from a psRegion. 00137 * 00138 * @return char*: A new string representing the psRegion as text, or NULL 00139 * is not successful. 00140 */ 00141 char* psRegionToString( 00142 psRegion* region ///< the psRegion to convert to a string 00143 ); 00144 00145 /** Resize a given image to the given size/type. 00146 * 00147 * @return psImage* Resized psImage. 00148 * 00149 */ 00150 psImage* psImageRecycle( 00151 psImage* old, ///< the psImage to recycle by resizing image buffer 00152 psU32 numCols, ///< the desired number of columns in image 00153 psU32 numRows, ///< the desired number of rows in image 00154 const psElemType type ///< the desired datatype of the image 00155 ); 00156 00157 /** Makes a copy of a psImage 00158 * 00159 * @return psImage* Copy of the input psImage. This may not be equal to the 00160 * output parameter 00161 * 00162 */ 00163 psImage* psImageCopy( 00164 psImage* output, ///< if not NULL, a psImage that could be recycled. 00165 const psImage* input, ///< the psImage to copy 00166 psElemType type ///< the desired datatype of the returned copy 00167 ); 00168 00169 /** Frees all children of a psImage. 00170 * 00171 * @return psS32 Number of children freed. 00172 * 00173 */ 00174 psS32 psImageFreeChildren( 00175 psImage* image ///< psImage in which all children shall be deallocated 00176 ); 00177 00178 /** Interpolate image pixel value given floating point coordinates. 00179 * 00180 * @return psF32 Pixel value interpolated from image or unexposedValue if 00181 * given x,y doesn't coorespond to a valid image location 00182 */ 00183 psC64 psImagePixelInterpolate( 00184 const psImage* input, ///< input image for interpolation 00185 float x, ///< column location to derive value of 00186 float y, ///< row location ot derive value of 00187 const psImage* mask, ///< if not NULL, the mask of the input image 00188 psU32 maskVal, ///< the mask value 00189 psC64 unexposedValue, ///< return value if x,y location is not in image. 00190 psImageInterpolateMode mode ///< interpolation mode 00191 ); 00192 00193 #define PIXEL_INTERPOLATE_FCN_PROTOTYPE(SUFFIX, RETURNTYPE) \ 00194 inline RETURNTYPE p_psImagePixelInterpolate##SUFFIX( \ 00195 const psImage* input, /**< input image for interpolation */ \ 00196 float x, /**< column location to derive value of */ \ 00197 float y, /**< row location ot derive value of */ \ 00198 const psImage* mask, /**< if not NULL, the mask of the input image */ \ 00199 psU32 maskVal, /**< the mask value */ \ 00200 RETURNTYPE unexposedValue /**< return value if x,y location is not in image. */ \ 00201 ); 00202 00203 #define PIXEL_INTERPOLATE_FCNS(MODE) \ 00204 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U8,psF64) \ 00205 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U16,psF64) \ 00206 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U32,psF64) \ 00207 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U64,psF64) \ 00208 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S8,psF64) \ 00209 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S16,psF64) \ 00210 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S32,psF64) \ 00211 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S64,psF64) \ 00212 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F32,psF64) \ 00213 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F64,psF64) \ 00214 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C32,psC64) \ 00215 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C64,psC64) 00216 00217 #ifndef SWIG 00218 PIXEL_INTERPOLATE_FCNS(FLAT) 00219 PIXEL_INTERPOLATE_FCNS(BILINEAR) 00220 PIXEL_INTERPOLATE_FCNS(BILINEAR_VARIANCE) 00221 #endif 00222 00223 #undef PIXEL_INTERPOLATE_FCN_PROTOTYPE 00224 #undef PIXEL_INTERPOLATE_FCNS 00225 00226 /// @} 00227 00228 #endif
1.3.9.1