Changeset 1840 for trunk/psLib/src/image/psImageExtraction.c
- Timestamp:
- Sep 21, 2004, 12:30:19 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageExtraction.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageExtraction.c
r1613 r1840 10 10 * @author Robert DeSonia, MHPCC 11 11 * 12 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-0 8-25 00:04:01$12 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-21 22:30:19 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 #include "psImageExtraction.h" 23 23 #include "psError.h" 24 25 #include "psImageErrors.h" 24 26 25 27 psImage* psImageSubset(psImage* image, … … 34 36 35 37 if (image == NULL || image->data.V == NULL) { 36 psError(__func__, "Can not subset image because input image or its pixel buffer is NULL."); 38 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset", 39 PS_ERR_BAD_PARAMETER_NULL, true, 40 PS_ERRORTEXT_psImage_IMAGE_NULL); 37 41 return NULL; 38 42 } 39 43 40 44 if (image->type.dimen != PS_DIMEN_IMAGE) { 41 psError(__func__, "Can not subset image because input image is not an image."); 45 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset", 46 PS_ERR_BAD_PARAMETER_TYPE, true, 47 PS_ERRORTEXT_psImage_NOT_AN_IMAGE); 42 48 return NULL; 43 49 } 44 50 45 51 if (numCols < 1 || numRows < 1) { 46 psError(__func__, 47 "Can not subset image because number of rows or columns are zero (%dx%d).", numCols, numRows); 48 return NULL; 49 } 50 51 if (col0 >= image->numCols || row0 >= image->numRows) { 52 psError(__func__, 53 "Can not subset image because col0,row0 (%d,%d) is not a valid pixel location.", col0, row0); 54 return NULL; 55 } 56 57 /* validate subimage size */ 58 if (col0 + numCols >= image->numCols || row0 + numRows >= image->numRows) { 59 psError(__func__, 60 "Can not subset image outside of image boundaries (size=%dx%d, " 61 "subset=[%d:%d,%d:%d]).", 62 image->numCols, image->numRows, col0, col0 + numCols, row0, row0 + numRows); 52 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset", 53 PS_ERR_BAD_PARAMETER_VALUE, true, 54 PS_ERRORTEXT_psImage_AREA_NEGATIVE, 55 numCols,numRows); 56 return NULL; 57 } 58 59 if ( col0 >= image->numCols || 60 row0 >= image->numRows || 61 col0 + numCols >= image->numCols || 62 row0 + numRows >= image->numRows ) { 63 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset", 64 PS_ERR_BAD_PARAMETER_VALUE, true, 65 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID, 66 col0, col0 + numCols, row0, row0 + numRows, 67 image->numCols, image->numRows); 63 68 return NULL; 64 69 } … … 104 109 // section should be of the form '[x1:x2,y1:y2]' 105 110 if (section == NULL) { 106 psError(__func__,"The subsection string input can not be NULL."); 111 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection", 112 PS_ERR_BAD_PARAMETER_NULL, true, 113 PS_ERRORTEXT_psImage_SUBSECTION_NULL); 107 114 return NULL; 108 115 } 109 116 110 117 if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) { 111 psError(__func__,"The subsection string (%s) can not be parsed. " 112 "Needs to be of the form '[x1:x2,y1:y2]'", 113 section); 118 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection", 119 PS_ERR_BAD_PARAMETER_NULL, true, 120 PS_ERRORTEXT_psImage_SUBSECTION_INVALID, 121 section); 114 122 return NULL; 115 123 } … … 120 128 { 121 129 if (image == NULL || image->data.V == NULL) { 122 psError(__func__, "Can not subset image because input image or its " 123 "pixel buffer is NULL."); 130 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 131 PS_ERR_BAD_PARAMETER_NULL, true, 132 PS_ERRORTEXT_psImage_IMAGE_NULL); 124 133 return NULL; 125 134 } 126 135 127 136 if (image->parent != NULL) { 128 psError(__func__, "Can not perform a trim on a child image."); 137 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 138 PS_ERR_BAD_PARAMETER_NULL, true, 139 PS_ERRORTEXT_psImage_NOT_PARENT); 129 140 return NULL; 130 141 } … … 134 145 y0 >= image->numRows || y1 >= image->numRows || 135 146 x0 > x1 || y0 > y1 ) { 136 psError(__func__, "Can not subset image because specified region " 137 "[%d:%d,%d:%d] is not valid for image of size %dx%d.", 138 x0,x1,y0,y1,image->numCols,image->numRows); 147 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 148 PS_ERR_BAD_PARAMETER_VALUE, true, 149 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID, 150 x0, x1, y0, y1, 151 image->numCols, image->numRows); 139 152 return NULL; 140 153 } … … 179 192 180 193 if (input == NULL || input->data.V == NULL) { 181 psError(__func__, "Can not copy image because input image or its pixel buffer is NULL."); 194 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy", 195 PS_ERR_BAD_PARAMETER_NULL, true, 196 PS_ERRORTEXT_psImage_IMAGE_NULL); 182 197 psFree(output); 183 198 return NULL; … … 185 200 186 201 if (input == output) { 187 psError (__func__,188 "Can not copy image because given input and output "189 "parameter reference the same psImage struct.");202 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy", 203 PS_ERR_BAD_PARAMETER_NULL, true, 204 PS_ERRORTEXT_psImage_INPLACE_NOTSUPPORTED); 190 205 psFree(output); 191 206 return NULL; … … 193 208 194 209 if (input->type.dimen != PS_DIMEN_IMAGE) { 195 psError(__func__, "Can not copy image because input image is not actually an image."); 210 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy", 211 PS_ERR_BAD_PARAMETER_TYPE, true, 212 PS_ERRORTEXT_psImage_NOT_AN_IMAGE); 196 213 psFree(output); 197 214 return NULL; … … 205 222 206 223 if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) { 207 psError(__func__, "Can not copy image to/from a void* matrix"); 224 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy", 225 PS_ERR_BAD_PARAMETER_TYPE, true, 226 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 227 PS_TYPE_PTR_NAME); 208 228 psFree(output); 209 229 return NULL; … … 220 240 return output; 221 241 } 242 222 243 #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \ 223 244 ps##INTYPE *in; \ … … 232 253 } 233 254 234 #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \ 235 switch (inDatatype) { \ 236 case PS_TYPE_S8: \ 237 PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \ 238 break; \ 239 case PS_TYPE_S16: \ 240 PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \ 241 break; \ 242 case PS_TYPE_S32: \ 243 PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \ 244 break; \ 245 case PS_TYPE_S64: \ 246 PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \ 247 break; \ 248 case PS_TYPE_U8: \ 249 PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \ 250 break; \ 251 case PS_TYPE_U16: \ 252 PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \ 253 break; \ 254 case PS_TYPE_U32: \ 255 PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \ 256 break; \ 257 case PS_TYPE_U64: \ 258 PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \ 259 break; \ 260 case PS_TYPE_F32: \ 261 PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \ 262 break; \ 263 case PS_TYPE_F64: \ 264 PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \ 265 break; \ 266 case PS_TYPE_C32: \ 267 PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \ 268 break; \ 269 case PS_TYPE_C64: \ 270 PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \ 271 break; \ 272 default: \ 273 break; \ 255 #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) { \ 256 switch (inDatatype) { \ 257 case PS_TYPE_S8: \ 258 PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \ 259 break; \ 260 case PS_TYPE_S16: \ 261 PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \ 262 break; \ 263 case PS_TYPE_S32: \ 264 PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \ 265 break; \ 266 case PS_TYPE_S64: \ 267 PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \ 268 break; \ 269 case PS_TYPE_U8: \ 270 PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \ 271 break; \ 272 case PS_TYPE_U16: \ 273 PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \ 274 break; \ 275 case PS_TYPE_U32: \ 276 PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \ 277 break; \ 278 case PS_TYPE_U64: \ 279 PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \ 280 break; \ 281 case PS_TYPE_F32: \ 282 PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \ 283 break; \ 284 case PS_TYPE_F64: \ 285 PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \ 286 break; \ 287 case PS_TYPE_C32: \ 288 PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \ 289 break; \ 290 case PS_TYPE_C64: \ 291 PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \ 292 break; \ 293 default: \ 294 break; \ 295 } \ 274 296 } 275 297 … … 311 333 PSIMAGE_COPY_CASE(output, C64); 312 334 break; 313 default: 314 break; 335 default: { 336 char* typeStr; 337 PS_TYPE_NAME(typeStr,type); 338 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy", 339 PS_ERR_BAD_PARAMETER_TYPE, true, 340 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 341 typeStr); 342 psFree(output); 343 344 break; 345 } 315 346 } 316 347 return output; … … 338 369 339 370 if (in == NULL || in->data.V == NULL) { 340 psError(__func__, "Input image can not be NULL."); 371 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 372 PS_ERR_BAD_PARAMETER_NULL, true, 373 PS_ERRORTEXT_psImage_IMAGE_NULL); 341 374 psFree(out); 342 375 return NULL; 343 376 } 344 377 345 if (numRows == 0 || numCols == 0) { 346 psError(__func__, "The specified region contains no data (%dx%d)", numCols, numRows); 378 if (numRows < 1 || numCols < 1) { 379 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 380 PS_ERR_BAD_PARAMETER_NULL, true, 381 PS_ERRORTEXT_psImage_SUBSET_ZERO_SIZE, 382 col,col+numCols,row,row+numRows); 347 383 psFree(out); 348 384 return NULL; … … 374 410 if (mask != NULL) { 375 411 if (inRows != mask->numRows || inCols != mask->numCols) { 376 psError(__func__, 377 "The mask and image dimensions did not match (%dx%d vs %dx%d)", 378 mask->numCols, mask->numRows, in->numCols, in->numRows); 412 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 413 PS_ERR_BAD_PARAMETER_VALUE, true, 414 PS_ERRORTEXT_psImage_IMAGE_MASK_SIZE, 415 mask->numCols,mask->numRows, 416 inCols, inRows); 379 417 psFree(out); 380 418 } 381 419 if (mask->type.type != PS_TYPE_MASK) { 382 psError(__func__, "The mask datatype (%d) must be %s.", mask->type.type, PS_TYPE_MASK_NAME); 420 char* typeStr; 421 PS_TYPE_NAME(typeStr,mask->type.type); 422 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 423 PS_ERR_BAD_PARAMETER_TYPE, true, 424 PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE, 425 typeStr, PS_TYPE_MASK_NAME); 383 426 psFree(out); 384 427 } 385 428 } 386 429 387 if (row >= inRows || col >= inCols || col + numCols > in->numCols || row + numRows > in->numRows) { 388 psError(__func__, 389 "The specified image region (%d,%d to %d,%d) is outside of image area (0,0 to %d,%d).", 390 col, row, col + numCols - 1, row + numRows - 1, in->numCols - 1, in->numRows - 1); 430 if (row >= inRows || col >= inCols || col + numCols > inCols || row + numRows > inRows) { 431 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 432 PS_ERR_BAD_PARAMETER_VALUE, true, 433 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID, 434 col, row, col+numCols, row+numRows, 435 inCols, inRows); 391 436 psFree(out); 392 437 return NULL; 393 438 } 439 440 if (stats == NULL) { 441 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 442 PS_ERR_BAD_PARAMETER_NULL, true, 443 PS_ERRORTEXT_psImage_STAT_NULL); 444 psFree(out); 445 return NULL; 446 } 447 394 448 // verify that the stats struct specifies a 395 449 // single stats operation 396 if (stats == NULL || p_psGetStatValue(stats, &statVal) == false) { 397 psError(__func__, "The stat options didn't specify a single supported statistic type."); 450 if (p_psGetStatValue(stats, &statVal) == false) { 451 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 452 PS_ERR_BAD_PARAMETER_VALUE, false, 453 PS_ERRORTEXT_psImage_BAD_STAT); 398 454 psFree(out); 399 455 return NULL; … … 410 466 psU32* outPosition = NULL; 411 467 412 // recycle output to make a proper 413 // sized/type output structure 414 // n.b. type is double as that is the 415 // type given for all stats in 468 // recycle output to make a proper sized/type output structure 469 // n.b. type is double as that is the type given for all stats is 416 470 // psStats. 417 471 out = psVectorRecycle(out, numCols, PS_TYPE_F64); … … 474 528 PSIMAGE_CUT_VERTICAL(C32); 475 529 PSIMAGE_CUT_VERTICAL(C64); 476 default: 477 psError(__func__, "Unsupported datatype (%d)", type); 478 psFree(out); 479 out = NULL; 530 default: { 531 char* typeStr; 532 PS_TYPE_NAME(typeStr,type); 533 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 534 PS_ERR_BAD_PARAMETER_TYPE, true, 535 PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, 536 typeStr); 537 psFree(out); 538 out = NULL; 539 } 480 540 } 481 541 psFree(imgVec); 482 542 psFree(maskVec); 483 } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) { // Cut 484 // 485 // 486 // 487 // 488 // 489 // 490 // 491 // 492 // 493 // in 494 // Y 495 // direction 543 } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) { 544 // Cut in Y direction 496 545 psVector* imgVec = NULL; 497 546 psVector* maskVec = NULL; … … 509 558 maskVec->n = maskVec->nalloc = numCols; 510 559 } 511 // recycle output to make a proper 512 // sized/type output structure 513 // n.b. type is double as that is the 514 // type given for all stats in 560 // recycle output to make a proper sized/type output structure 561 // n.b. type is double as that is the type given for all stats in 515 562 // psStats. 516 563 out = psVectorRecycle(out, numRows, PS_TYPE_F64); … … 535 582 } 536 583 myStats = psVectorStats(myStats, imgVec, maskVec, maskVal); 537 (void)p_psGetStatValue(myStats, &statVal); // we 538 // know 539 // it 540 // works 541 // cause we tested it 542 // above 584 (void)p_psGetStatValue(myStats, &statVal); // we know it works cause we tested it above 543 585 *outData = statVal; 544 586 if (outPosition != NULL) { … … 551 593 psFree(imgVec); 552 594 psFree(maskVec); 553 } else { // don't 554 // know 555 // what 556 // the 557 // direction 558 // flag 559 // is 560 psError(__func__, "Invalid direction flag (%d)", direction); 595 } else { // don't know what the direction flag is 596 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice", 597 PS_ERR_BAD_PARAMETER_VALUE, true, 598 PS_ERRORTEXT_psImage_SLICE_DIRECTION_INVALID, 599 direction); 561 600 psFree(out); 562 601 out = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
