Changeset 2375 for trunk/psLib/src/image
- Timestamp:
- Nov 16, 2004, 10:00:21 AM (22 years ago)
- Location:
- trunk/psLib/src/image
- Files:
-
- 5 edited
-
psImage.c (modified) (3 diffs)
-
psImage.h (modified) (4 diffs)
-
psImageConvolve.c (modified) (4 diffs)
-
psImageErrors.h (modified) (1 diff)
-
psImageManip.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r2291 r2375 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.5 3$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-11- 06 00:44:56$11 * @version $Revision: 1.54 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-11-16 20:00:21 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 #include "psImageErrors.h" 27 27 28 static void imageFree(psImage* image); 28 static void imageFree(psImage* image) 29 { 30 if (image == NULL) { 31 return; 32 } 33 34 if (image->type.type == PS_TYPE_PTR) { 35 // 2-D array of pointers -- must dereference elements 36 psU32 oldNumRows = image->numRows; 37 psU32 oldNumCols = image->numCols; 38 psPtr* rowPtr; 39 40 for (psU32 row = 0; row < oldNumRows; row++) { 41 rowPtr = image->data.PTR[row]; 42 for (psU32 col = 0; col < oldNumCols; col++) { 43 psMemDecrRefCounter(rowPtr[col]); 44 } 45 } 46 } 47 48 if (image->parent != NULL) { 49 psArrayRemove(image->parent->children,image); 50 image->parent = NULL; 51 } 52 53 psImageFreeChildren(image); 54 55 psFree(image->rawDataBuffer); 56 psFree(image->data.V); 57 } 29 58 30 59 psImage* psImageAlloc(psU32 numCols, … … 71 100 } 72 101 73 static void imageFree(psImage* image) 102 psRegion* psRegionAlloc(double x0, 103 double x1, 104 double y0, 105 double y1) 74 106 { 75 if (image == NULL) { 76 return; 77 } 78 79 if (image->type.type == PS_TYPE_PTR) { 80 // 2-D array of pointers -- must dereference elements 81 psU32 oldNumRows = image->numRows; 82 psU32 oldNumCols = image->numCols; 83 psPtr* rowPtr; 84 85 for (psU32 row = 0; row < oldNumRows; row++) { 86 rowPtr = image->data.PTR[row]; 87 for (psU32 col = 0; col < oldNumCols; col++) { 88 psMemDecrRefCounter(rowPtr[col]); 89 } 90 } 91 } 92 93 if (image->parent != NULL) { 94 psArrayRemove(image->parent->children,image); 95 image->parent = NULL; 96 } 97 98 psImageFreeChildren(image); 99 100 psFree(image->rawDataBuffer); 101 psFree(image->data.V); 102 } 107 psRegion* out = psAlloc(sizeof(psRegion)); 108 109 out->x0 = x0; 110 out->y0 = y0; 111 out->x1 = x1; 112 out->y1 = y1; 113 114 return out; 115 } 116 117 118 119 psRegion* psRegionFromString(char* region) 120 { 121 psS32 col0; 122 psS32 col1; 123 psS32 row0; 124 psS32 row1; 125 126 // section should be of the form '[col0:col1,row0:row1]' 127 if (region == NULL) { 128 psError(PS_ERR_BAD_PARAMETER_NULL, true, 129 PS_ERRORTEXT_psImage_SUBSECTION_NULL); 130 return NULL; 131 } 132 133 if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) { 134 psError(PS_ERR_BAD_PARAMETER_NULL, true, 135 PS_ERRORTEXT_psImage_SUBSECTION_INVALID, 136 region); 137 return NULL; 138 } 139 140 if (col0 > col1 || row0 > row1) { 141 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 142 PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED, 143 col0,col1,row0,row1); 144 return NULL; 145 } 146 147 return psRegionAlloc(col0,col1,row0,row1); 148 } 149 103 150 104 151 psImage* psImageRecycle(psImage* old, -
trunk/psLib/src/image/psImage.h
r2204 r2375 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.4 2$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-1 0-27 00:57:31 $13 * @version $Revision: 1.43 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-11-16 20:00:21 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 75 75 psImage; 76 76 77 /** Basic image region structure. 78 * 79 * Struct for specifying a rectangular area in an image. 80 * 81 */ 82 typedef struct 83 { 84 double x0; ///< the first column of the region. 85 double x1; ///< the last column of the region. 86 double y0; ///< the first row of the region. 87 double y1; ///< the last row of the region. 88 } 89 psRegion; 90 77 91 /** Create an image of the specified size and type. 78 92 * … … 84 98 */ 85 99 psImage* psImageAlloc( 86 psU32 numCols, ///< Number of rows in image.87 psU32 numRows, ///< Number of columns in image.100 psU32 numCols, ///< Number of rows in image. 101 psU32 numRows, ///< Number of columns in image. 88 102 const psElemType type ///< Type of data for image. 103 ); 104 105 /** Create an image of the specified size and type. 106 * 107 * Uses psLib memory allocation functions to create an image struct of the 108 * specified size and type. 109 * 110 * @return psImage* : Pointer to psImage. 111 * 112 */ 113 psRegion* psRegionAlloc( 114 double x0, ///< the first column of the region. 115 double x1, ///< the last column of the region. 116 double y0, ///< the first row of the region. 117 double y1 ///< the last row of the region. 118 ); 119 120 psRegion* psRegionFromString( 121 char* region ///< image rectangular region in the form '[x0:x1,y0:y1]' 89 122 ); 90 123 … … 96 129 psImage* psImageRecycle( 97 130 psImage* old, ///< the psImage to recycle by resizing image buffer 98 psU32 numCols, ///< the desired number of columns in image99 psU32 numRows, ///< the desired number of rows in image131 psU32 numCols, ///< the desired number of columns in image 132 psU32 numRows, ///< the desired number of rows in image 100 133 const psElemType type ///< the desired datatype of the image 101 134 ); -
trunk/psLib/src/image/psImageConvolve.c
r2273 r2375 5 5 * @author Robert DeSonia, MHPCC 6 6 * 7 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $8 * @date $Date: 2004-11- 04 01:05:00$7 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2004-11-16 20:00:21 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 93 93 psBool relative) 94 94 { 95 psS32 x = 0; 96 psS32 y = 0; 97 psS32 t = 0; 98 psS32 deltaT; 95 psS32 lastX; 96 psS32 lastY; 97 psS32 lastT; 98 psS32 x; 99 psS32 y; 100 psS32 t; 99 101 psS32 oldX; 100 102 psS32 oldY; … … 148 150 ps##TYPE *xShiftData = xShifts->data.TYPE; \ 149 151 ps##TYPE *yShiftData = yShifts->data.TYPE; \ 150 x = 0; \ 151 y = 0; \ 152 t = 0; \ 153 for (psS32 lcv = 0; lcv < length; lcv++) { \ 154 if (relative) { \ 155 x += xShiftData[lcv]; \ 156 y += yShiftData[lcv]; \ 157 t += tShiftData[lcv]; \ 158 } else { \ 159 x = xShiftData[lcv]; \ 160 y = yShiftData[lcv]; \ 161 t = tShiftData[lcv]; \ 162 } \ 152 lastX = xShiftData[length-1]; \ 153 lastY = yShiftData[length-1]; \ 154 \ 155 for (int lcv = 0; lcv < length; lcv++) { \ 156 x = lastX - xShiftData[lcv]; \ 157 y = lastY - yShiftData[lcv]; \ 158 \ 163 159 if (x < xMin) { \ 164 160 xMin = x; \ … … 172 168 } \ 173 169 } \ 170 \ 171 normalizeTime = 1.0 / (psKernelType)(lastT - tShiftData[0]); \ 174 172 result = psKernelAlloc(xMin,xMax,yMin,yMax); \ 175 173 kernel = result->kernel; \ 176 174 \ 177 normalizeTime = 1.0 / (psKernelType)(t); \ 175 lastT = 0; \ 176 for (int i = 0; i < length; i++) { \ 177 t = tShiftData[i] - lastT; \ 178 x = lastX - xShiftData[i]; \ 179 y = lastY - yShiftData[i]; \ 180 \ 181 kernel[y][x] += (psKernelType)t * normalizeTime; \ 182 lastT = t; \ 183 } \ 184 break; \ 185 } 186 187 #define RELATIVE_KERNEL_GENERATE_CASE(TYPE) \ 188 case PS_TYPE_##TYPE: { \ 189 ps##TYPE *tShiftData = tShifts->data.TYPE; \ 190 ps##TYPE *xShiftData = xShifts->data.TYPE; \ 191 ps##TYPE *yShiftData = yShifts->data.TYPE; \ 192 \ 178 193 x = 0; \ 179 194 y = 0; \ 180 195 t = 0; \ 181 for (psS32 i = 0; i < length; i++) { \ 182 deltaT = t; \ 183 oldX = x; \ 184 oldY = y; \ 185 if (relative) { \ 186 t += tShiftData[i]; \ 187 x += xShiftData[i]; \ 188 y += yShiftData[i]; \ 189 } else { \ 190 t = tShiftData[i]; \ 191 x = xShiftData[i]; \ 192 y = yShiftData[i]; \ 196 \ 197 for (int lcv = length-1; lcv >= 0; lcv--) { \ 198 t += tShiftData[lcv]; \ 199 \ 200 if (x < xMin) { \ 201 xMin = x; \ 202 } else if (x > xMax) { \ 203 xMax = x; \ 193 204 } \ 194 deltaT = t - deltaT; \ 205 if (y < yMin) { \ 206 yMin = y; \ 207 } else if (y > yMax) { \ 208 yMax = y; \ 209 } \ 210 x += xShiftData[lcv]; \ 211 y += yShiftData[lcv]; \ 195 212 \ 196 kernel[oldY][oldX] += deltaT * normalizeTime; \ 213 } \ 214 result = psKernelAlloc(xMin,xMax,yMin,yMax); \ 215 kernel = result->kernel; \ 216 \ 217 normalizeTime = 1.0 / (psKernelType)t; \ 218 x = 0; \ 219 y = 0; \ 220 for (psS32 i = length-1; i >= 0; i--) { \ 221 kernel[y][x] += (psKernelType)(tShiftData[i]) * normalizeTime; \ 222 x += xShiftData[i]; \ 223 y += yShiftData[i]; \ 224 \ 197 225 } \ 198 226 break; \ 199 227 } 200 228 201 switch (xShifts->type.type) { 202 KERNEL_GENERATE_CASE(U8); 203 KERNEL_GENERATE_CASE(U16); 204 KERNEL_GENERATE_CASE(U32); 205 KERNEL_GENERATE_CASE(U64); 206 KERNEL_GENERATE_CASE(S8); 207 KERNEL_GENERATE_CASE(S16); 208 KERNEL_GENERATE_CASE(S32); 209 KERNEL_GENERATE_CASE(S64); 210 KERNEL_GENERATE_CASE(F32); 211 KERNEL_GENERATE_CASE(F64); 212 KERNEL_GENERATE_CASE(C32); 213 KERNEL_GENERATE_CASE(C64); 214 215 default: { 216 char* typeStr; 217 PS_TYPE_NAME(typeStr,xShifts->type.type); 218 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 219 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 220 typeStr); 229 if (relative) { 230 switch (xShifts->type.type) { 231 RELATIVE_KERNEL_GENERATE_CASE(U8); 232 RELATIVE_KERNEL_GENERATE_CASE(U16); 233 RELATIVE_KERNEL_GENERATE_CASE(U32); 234 RELATIVE_KERNEL_GENERATE_CASE(U64); 235 RELATIVE_KERNEL_GENERATE_CASE(S8); 236 RELATIVE_KERNEL_GENERATE_CASE(S16); 237 RELATIVE_KERNEL_GENERATE_CASE(S32); 238 RELATIVE_KERNEL_GENERATE_CASE(S64); 239 RELATIVE_KERNEL_GENERATE_CASE(F32); 240 RELATIVE_KERNEL_GENERATE_CASE(F64); 241 RELATIVE_KERNEL_GENERATE_CASE(C32); 242 RELATIVE_KERNEL_GENERATE_CASE(C64); 243 244 default: { 245 char* typeStr; 246 PS_TYPE_NAME(typeStr,xShifts->type.type); 247 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 248 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 249 typeStr); 250 } 251 } 252 } else { 253 switch (xShifts->type.type) { 254 KERNEL_GENERATE_CASE(U8); 255 KERNEL_GENERATE_CASE(U16); 256 KERNEL_GENERATE_CASE(U32); 257 KERNEL_GENERATE_CASE(U64); 258 KERNEL_GENERATE_CASE(S8); 259 KERNEL_GENERATE_CASE(S16); 260 KERNEL_GENERATE_CASE(S32); 261 KERNEL_GENERATE_CASE(S64); 262 KERNEL_GENERATE_CASE(F32); 263 KERNEL_GENERATE_CASE(F64); 264 KERNEL_GENERATE_CASE(C32); 265 KERNEL_GENERATE_CASE(C64); 266 267 default: { 268 char* typeStr; 269 PS_TYPE_NAME(typeStr,xShifts->type.type); 270 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 271 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 272 typeStr); 273 } 221 274 } 222 275 } -
trunk/psLib/src/image/psImageErrors.h
r2093 r2375 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-1 0-13 23:34:57$9 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-11-16 20:00:21 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psLib/src/image/psImageManip.h
r2204 r2375 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-1 0-27 00:57:31 $13 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-11-16 20:00:21 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 83 83 psImage* image, ///< target image 84 84 const psImage* overlay, ///< the overlay image 85 psS32 col0, ///< the column to start overlay86 psS32 row0, ///< the row to start overlay85 psS32 col0, ///< the column to start overlay 86 psS32 row0, ///< the row to start overlay 87 87 const char *op ///< the operation to perform for overlay 88 88 ); … … 103 103 const psImage* restrict mask, ///< mask for input image. If NULL, no masking is done. 104 104 psMaskType maskVal, ///< the bits to check in mask. 105 psU32 scale, ///< the scale to rebin for each dimension105 psU32 scale, ///< the scale to rebin for each dimension 106 106 const psStats* stats 107 107 ///< the statistic to perform when rebinning. Only one method should be set. … … 121 121 psImage* out, ///< an psImage to recycle. If NULL, a new image is created 122 122 const psImage* in, ///< input image 123 psS32 scale, ///< resample scaling factor123 psS32 scale, ///< resample scaling factor 124 124 psImageInterpolateMode mode ///< the interpolation mode used in resampling 125 125 ); … … 176 176 psImage* out, ///< an psImage to recycle. If NULL, a new image is created 177 177 const psImage* in, ///< input image 178 psS32 dx, ///< number of pixels to roll in the x-dimension179 psS32 dy ///< number of pixels to roll in the y-dimension178 psS32 dx, ///< number of pixels to roll in the x-dimension 179 psS32 dy ///< number of pixels to roll in the y-dimension 180 180 ); 181 181
Note:
See TracChangeset
for help on using the changeset viewer.
