00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 #include "psConstants.h"
00026
00027
00028
00029
00030
00031
00032
00033 typedef enum {
00034 PS_INTERPOLATE_FLAT,
00035 PS_INTERPOLATE_BILINEAR,
00036 PS_INTERPOLATE_LANCZOS2,
00037 PS_INTERPOLATE_LANCZOS3,
00038 PS_INTERPOLATE_LANCZOS4,
00039 PS_INTERPOLATE_BILINEAR_VARIANCE,
00040 PS_INTERPOLATE_LANCZOS2_VARIANCE,
00041 PS_INTERPOLATE_LANCZOS3_VARIANCE,
00042 PS_INTERPOLATE_LANCZOS4_VARIANCE
00043
00044 } psImageInterpolateMode;
00045
00046
00047
00048
00049
00050
00051
00052 typedef struct psImage
00053 {
00054 const psMathType type;
00055 const int numCols;
00056 const int numRows;
00057 int col0;
00058 int row0;
00059
00060 union {
00061 psS8** S8;
00062 psS16** S16;
00063 psS32** S32;
00064 psS64** S64;
00065 psU8** U8;
00066 psU16** U16;
00067 psU32** U32;
00068 psU64** U64;
00069 psF32** F32;
00070 psF64** F64;
00071 psC32** C32;
00072 psC64** C64;
00073 psPtr* V;
00074 } data;
00075 const struct psImage* parent;
00076 psPtr p_rawDataBuffer;
00077 psArray* children;
00078 void *lock;
00079 }
00080 psImage;
00081
00082 #define P_PSIMAGE_SET_NUMCOLS(img,nc) {*(int*)&img->numCols = nc;}
00083 #define P_PSIMAGE_SET_NUMROWS(img,nr) {*(int*)&img->numRows = nr;}
00084 #define P_PSIMAGE_SET_TYPE(img,t) {*(psMathType*)&img->type = t;}
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 psImage* psImageAlloc(
00095 int numCols,
00096 int numRows,
00097 psElemType type
00098 )
00099 ;
00100
00101
00102
00103
00104
00105
00106
00107 bool psMemCheckImage(
00108 psPtr ptr
00109 );
00110
00111
00112
00113
00114
00115
00116
00117 bool psImageInit(
00118 psImage *image,
00119 ...
00120 );
00121
00122
00123
00124
00125
00126
00127
00128 bool psImageSet(
00129 psImage *image,
00130 int x,
00131 int y,
00132 double complex value
00133 );
00134
00135
00136
00137
00138
00139
00140
00141 double complex psImageGet(
00142 const psImage *image,
00143 int x,
00144 int y
00145 );
00146
00147
00148
00149
00150
00151 psImage* psImageRecycle(
00152 psImage* old,
00153 int numCols,
00154 int numRows,
00155 const psElemType type
00156 );
00157
00158
00159
00160
00161
00162 bool p_psImageCopyToRawBuffer(
00163 void* buffer,
00164 const psImage* input,
00165 psElemType type
00166 );
00167
00168
00169
00170
00171
00172 int psImageFreeChildren(
00173 psImage* image
00174 );
00175
00176
00177
00178
00179
00180 psF64 p_psImageGetElementF64(
00181 psImage* image,
00182 int col,
00183 int row
00184 );
00185
00186
00187
00188
00189
00190 bool p_psImagePrint(
00191 int fd,
00192 psImage *a,
00193 char *name
00194 );
00195
00196
00197
00198
00199
00200
00201 double complex psImagePixelInterpolate(
00202 const psImage* input,
00203 float x,
00204 float y,
00205 const psImage* mask,
00206 psMaskType maskVal,
00207 double complex unexposedValue,
00208 psImageInterpolateMode mode
00209 );
00210
00211 #define PIXEL_INTERPOLATE_FCN_PROTOTYPE(SUFFIX, RETURNTYPE) \
00212 inline RETURNTYPE p_psImagePixelInterpolate##SUFFIX( \
00213 const psImage* input, \
00214 float x, \
00215 float y, \
00216 const psImage* mask, \
00217 psU32 maskVal, \
00218 RETURNTYPE unexposedValue \
00219 );
00220
00221 #define PIXEL_INTERPOLATE_FCNS(MODE) \
00222 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U8,psF64) \
00223 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U16,psF64) \
00224 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U32,psF64) \
00225 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_U64,psF64) \
00226 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S8,psF64) \
00227 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S16,psF64) \
00228 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S32,psF64) \
00229 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_S64,psF64) \
00230 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F32,psF64) \
00231 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_F64,psF64) \
00232 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C32,psC64) \
00233 PIXEL_INTERPOLATE_FCN_PROTOTYPE(MODE##_C64,psC64)
00234
00235 #ifndef SWIG
00236 PIXEL_INTERPOLATE_FCNS(FLAT)
00237 PIXEL_INTERPOLATE_FCNS(BILINEAR)
00238 PIXEL_INTERPOLATE_FCNS(BILINEAR_VARIANCE)
00239 #endif
00240
00241 #undef PIXEL_INTERPOLATE_FCN_PROTOTYPE
00242 #undef PIXEL_INTERPOLATE_FCNS
00243
00244
00245
00246
00247 #define PS_ASSERT_IMAGE_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, return RVAL)
00248 #define PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, CLEANUP) \
00249 if ((NAME) == NULL || (NAME)->data.V == NULL) { \
00250 psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00251 "Unallowable operation: psImage %s or its data is NULL.", \
00252 #NAME); \
00253 CLEANUP; \
00254 }
00255
00256 #define PS_ASSERT_IMAGE_NON_EMPTY(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, return RVAL)
00257 #define PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, CLEANUP) \
00258 if ((NAME)->numCols < 1 || (NAME)->numRows < 1) { \
00259 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00260 "Unallowable operation: psImage %s has zero rows or columns (%dx%d).", \
00261 #NAME, (NAME)->numCols, (NAME)->numRows); \
00262 CLEANUP; \
00263 }
00264
00265 #define PS_ASSERT_IMAGE_TYPE(NAME, TYPE, RVAL) \
00266 if ((NAME)->type.type != TYPE) { \
00267 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00268 "Unallowable operation: psImage %s has incorrect type.", \
00269 #NAME); \
00270 return(RVAL); \
00271 }
00272
00273 #define PS_ASSERT_IMAGES_SIZE_EQUAL(NAME1, NAME2, RVAL) \
00274 if (((NAME1)->numCols != (NAME2)->numCols) || \
00275 ((NAME1)->numRows != (NAME2)->numRows)) { \
00276 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00277 "Unallowable operation: psImages %s and %s are not the same size.", \
00278 #NAME1, #NAME2); \
00279 return(RVAL); \
00280 }
00281
00282 #define PS_ASSERT_IMAGE_SIZE(NAME1, NUM_COLS, NUM_ROWS, RVAL) \
00283 if (((NAME1)->numCols != NUM_COLS) || \
00284 ((NAME1)->numRows != NUM_ROWS)) { \
00285 psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00286 "Unallowable operation: psImages %s is not the correct size.", \
00287 #NAME1); \
00288 return(RVAL); \
00289 }
00290
00291 #define PS_IMAGE_PRINT_F32(NAME) \
00292 printf("======== printing %s ========\n", #NAME); \
00293 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00294 for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00295 printf("%.2f ", (NAME)->data.F32[i][j]); \
00296 } \
00297 printf("\n"); \
00298 }\
00299
00300 #define PS_IMAGE_PRINT_F64(NAME) \
00301 printf("======== printing %s ========\n", #NAME); \
00302 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00303 for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00304 printf("%.2f ", (NAME)->data.F64[i][j]); \
00305 } \
00306 printf("\n"); \
00307 }\
00308
00309
00310
00311 #endif // PS_IMAGE_H