Changeset 1407 for trunk/psLib/src/image/psImage.c
- Timestamp:
- Aug 6, 2004, 2:06:06 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImage.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r1406 r1407 1 1 2 /** @file psImage.c 2 3 * … … 9 10 * @author Ross Harman, MHPCC 10 11 * 11 * @version $Revision: 1.3 7$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-08-0 6 22:34:05$12 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-07 00:06:06 $ 13 14 * 14 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 19 19 20 /******************************************************************************/ 21 20 22 /* INCLUDE FILES */ 23 21 24 /******************************************************************************/ 22 25 … … 29 32 #include "psImage.h" 30 33 31 static void imageFree(psImage * image);34 static void imageFree(psImage * image); 32 35 33 36 /*****************************************************************************/ 37 34 38 /* FUNCTION IMPLEMENTATION - PUBLIC */ 39 35 40 /*****************************************************************************/ 36 41 37 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, 38 const psElemType type) 42 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type) 39 43 { 40 44 int area = 0; 41 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 42 int rowSize = numCols*elementSize; // row size in bytes. 43 44 area = numCols*numRows; 45 int elementSize = PSELEMTYPE_SIZEOF(type); // element 46 47 // size in 48 // bytes 49 int rowSize = numCols * elementSize; // row 50 51 // size 52 53 // in bytes. 54 55 area = numCols * numRows; 45 56 46 57 if (area < 1) { 47 psError(__func__, "Invalid value for number of rows or columns "48 " (numRows=%d, numCols=%d).", numRows, numCols);58 psError(__func__, 59 "Invalid value for number of rows or columns " "(numRows=%d, numCols=%d).", numRows, numCols); 49 60 return NULL; 50 61 } 51 62 52 psImage *image = (psImage *) psAlloc(sizeof(psImage));53 if(image == NULL) { 54 psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);55 }56 57 p_psMemSetDeallocator(image,(psFreeFcn)imageFree); 58 59 image->data.V = psAlloc(sizeof(void*)*numRows); 60 i f(image->data.V == NULL) {61 psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);62 }63 64 65 image->data.V[0] = psAlloc(area *elementSize);66 if (image->data.V[0] == NULL) {67 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);68 } 69 70 for (int i = 1; i < numRows; i++) {71 image->data.V[i] = (void *)((int8_t*)image->data.V[i-1]+rowSize);72 } 73 74 *(int *)&image->col0 = 0;75 *(int *)&image->row0 = 0;76 *(unsigned int *)&image->numCols = numCols;77 *(unsigned int *)&image->numRows = numRows;78 *(psDimen *)&image->type.dimen = PS_DIMEN_IMAGE;79 *(psElemType *)&image->type.type = type;63 psImage *image = (psImage *) psAlloc(sizeof(psImage)); 64 65 if (image == NULL) { 66 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 67 } 68 69 p_psMemSetDeallocator(image, (psFreeFcn) imageFree); 70 71 image->data.V = psAlloc(sizeof(void *) * numRows); 72 if (image->data.V == NULL) { 73 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 74 } 75 76 image->data.V[0] = psAlloc(area * elementSize); 77 if (image->data.V[0] == NULL) { 78 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); 79 } 80 81 for (int i = 1; i < numRows; i++) { 82 image->data.V[i] = (void *)((int8_t *) image->data.V[i - 1] + rowSize); 83 } 84 85 *(int *)&image->col0 = 0; 86 *(int *)&image->row0 = 0; 87 *(unsigned int *)&image->numCols = numCols; 88 *(unsigned int *)&image->numRows = numRows; 89 *(psDimen *) & image->type.dimen = PS_DIMEN_IMAGE; 90 *(psElemType *) & image->type.type = type; 80 91 image->parent = NULL; 81 92 image->nChildren = 0; … … 85 96 } 86 97 87 static void imageFree(psImage * image)98 static void imageFree(psImage * image) 88 99 { 89 100 if (image == NULL) { … … 92 103 93 104 if (image->type.type == PS_TYPE_PTR) { 94 // 2-D array of pointers -- must dereference 105 // 2-D array of pointers -- must 106 // dereference 95 107 unsigned int oldNumRows = image->numRows; 96 108 unsigned int oldNumCols = image->numCols; 97 psPTR *rowPtr;98 99 for (unsigned int row=0;row<oldNumRows;row++) {109 psPTR *rowPtr; 110 111 for (unsigned int row = 0; row < oldNumRows; row++) { 100 112 rowPtr = image->data.PTR[row]; 101 for (unsigned int col =0;col<oldNumCols;col++) {113 for (unsigned int col = 0; col < oldNumCols; col++) { 102 114 psMemDecrRefCounter(rowPtr[col]); 103 115 } … … 112 124 } 113 125 114 psImage* psImageRecycle(psImage* old, 115 unsigned int numCols, 116 unsigned int numRows, 117 const psElemType type) 126 psImage *psImageRecycle(psImage * old, unsigned int numCols, unsigned int numRows, const psElemType type) 118 127 { 119 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 120 int rowSize = numCols*elementSize; // row size in bytes. 128 int elementSize = PSELEMTYPE_SIZEOF(type); // element 129 130 // size in 131 // bytes 132 int rowSize = numCols * elementSize; // row 133 134 // size 135 136 // in bytes. 121 137 122 138 if (old == NULL) { 123 old = psImageAlloc(numCols, numRows,type);139 old = psImageAlloc(numCols, numRows, type); 124 140 return old; 125 141 } 126 142 127 143 if (old->type.dimen != PS_DIMEN_IMAGE) { 128 psError(__func__, "Can not realloc image because input is not an image.");144 psError(__func__, "Can not realloc image because input is not an image."); 129 145 return NULL; 130 146 } 131 147 132 148 if (old->type.type == PS_TYPE_PTR) { 133 // 2-D array of pointers -- must dereference 149 // 2-D array of pointers -- must 150 // dereference 134 151 unsigned int oldNumRows = old->numRows; 135 152 unsigned int oldNumCols = old->numCols; 136 psPTR *rowPtr;137 138 for (unsigned int row=0;row<oldNumRows;row++) {153 psPTR *rowPtr; 154 155 for (unsigned int row = 0; row < oldNumRows; row++) { 139 156 rowPtr = old->data.PTR[row]; 140 for (unsigned int col =0;col<oldNumCols;col++) {157 for (unsigned int col = 0; col < oldNumCols; col++) { 141 158 psMemDecrRefCounter(rowPtr[col]); 142 159 rowPtr[col] = NULL; … … 146 163 147 164 /* image already the right size/type? */ 148 if (numCols == old->numCols && numRows == old->numRows && 149 type == old->type.type) { 165 if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) { 150 166 return old; 151 167 } 152 153 168 // Resize the image buffer 154 old->data.V[0] = psRealloc(old->data.V[0], numCols * numRows * elementSize);155 old->data.V = (void **) psRealloc(old->data.V,numRows * sizeof(void*));169 old->data.V[0] = psRealloc(old->data.V[0], numCols * numRows * elementSize); 170 old->data.V = (void **)psRealloc(old->data.V, numRows * sizeof(void *)); 156 171 157 172 // recreate the row pointers 158 for (int i = 1; i < numRows; i++) {159 old->data.V[i] = (void *)((int8_t*)old->data.V[i-1]+rowSize);160 } 161 162 *(unsigned int *)&old->numCols = numCols;163 *(unsigned int *)&old->numRows = numRows;164 *(psElemType *)&old->type.type = type;173 for (int i = 1; i < numRows; i++) { 174 old->data.V[i] = (void *)((int8_t *) old->data.V[i - 1] + rowSize); 175 } 176 177 *(unsigned int *)&old->numCols = numCols; 178 *(unsigned int *)&old->numRows = numRows; 179 *(psElemType *) & old->type.type = type; 165 180 166 181 return old; 167 182 } 168 183 169 int psImageFreeChildren(psImage * image)184 int psImageFreeChildren(psImage * image) 170 185 { 171 186 int i = 0; … … 181 196 children = image->children; 182 197 183 for (i=0; i<nChildren; i++) {198 for (i = 0; i < nChildren; i++) { 184 199 if (children[i] != NULL) { 185 200 numFreed++; … … 191 206 image->nChildren = 0; 192 207 image->children = NULL; 193 194 208 195 209 return numFreed; … … 202 216 linear interpolation is performed on the image. 203 217 *****************************************************************************/ 204 psF32 psImagePixelInterpolate( 205 const psImage *input, 206 float x, 207 float y, 208 psF32 unexposedValue, 209 psImageInterpolateMode mode) 218 psF32 psImagePixelInterpolate(const psImage * input, 219 float x, float y, psF32 unexposedValue, psImageInterpolateMode mode) 210 220 { 211 221 212 222 if (input == NULL) { 213 psError(__func__, "Image can not be NULL.");223 psError(__func__, "Image can not be NULL."); 214 224 return unexposedValue; 215 225 } 216 217 226 #define PSIMAGE_PIXEL_INTERPOLATE_CASE(TYPE) \ 218 227 case PS_TYPE_##TYPE: \ … … 243 252 PSIMAGE_PIXEL_INTERPOLATE_CASE(C64); 244 253 default: 245 psError(__func__, "Unsupported image datatype (%d)",input->type.type);254 psError(__func__, "Unsupported image datatype (%d)", input->type.type); 246 255 } 247 256 … … 303 312 PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C32) 304 313 PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C64) 305 306 314 #define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(TYPE) \ 307 315 inline psF64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \ … … 359 367 return(pixel); \ 360 368 } 361 362 369 #define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(TYPE) \ 363 370 inline psC64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \ … … 428 435 PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C32) 429 436 PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C64) 430 431
Note:
See TracChangeset
for help on using the changeset viewer.
