Changeset 6750 for trunk/psLib/src/imageops
- Timestamp:
- Mar 31, 2006, 4:43:57 PM (20 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 4 edited
-
psImageGeomManip.c (modified) (2 diffs)
-
psImageGeomManip.h (modified) (2 diffs)
-
psImagePixelExtract.c (modified) (14 diffs)
-
psImageStats.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageGeomManip.c
r6484 r6750 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.2 0$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-0 2-24 23:43:15$12 * @version $Revision: 1.21 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-04-01 02:43:57 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 749 749 col0 = region.x0; 750 750 col1 = region.x1; 751 //If [0,0,0,0] specified, the whole image is to be included 752 if (row0 == 0 && col0 == 0 && row1 == 0 && col1 == 0) { 753 row0 = input->row0; 754 col0 = input->col0; 755 row1 = input->row0 + input->numRows; 756 col1 = input->col0 + input->numCols; 757 } 751 758 if (col1 < 1) { 752 col1 += input-> numCols;759 col1 += input->col0 + input->numCols; 753 760 } 754 761 755 762 if (row1 < 1) { 756 row1 += input-> numRows;763 row1 += input->row0 + input->numRows; 757 764 } 758 765 -
trunk/psLib/src/imageops/psImageGeomManip.h
r6354 r6750 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 2-08 01:03:35$10 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-04-01 02:43:57 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 150 150 const psPlaneTransform *outToIn, ///< the transform to apply 151 151 psRegion region, ///< the size of the transformed image 152 const psPixels* pixels, /**< if not NULL, consists of psPixelCoords and specifies which pixels in 153 * output image shall be transformed; otherwise, entire image generated*/ 152 const psPixels* pixels, /**< if not NULL, consists of psPixelCoords and specifies 153 * which pixels in output image shall be transformed; 154 * otherwise, entire image generated*/ 154 155 psImageInterpolateMode mode, ///< the interpolation scheme to be used 155 double exposedValue ///< Exposed value to which non-corresponding pixels are set156 double exposedValue ///< Exposed value to which non-corresponding pixels are set 156 157 ); 157 158 -
trunk/psLib/src/imageops/psImagePixelExtract.c
r6631 r6750 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 3-17 20:38:19$10 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-04-01 02:43:57 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 57 57 return NULL; 58 58 } 59 PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL); 60 PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL); 61 PS_ASSERT_INT_POSITIVE(input->numCols, NULL); 62 PS_ASSERT_INT_POSITIVE(input->numRows, NULL); 59 if (input->col0 < 0) { 60 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 61 "psImage input is invalid. col0 cannot be negative.\n"); 62 psFree(out); 63 return NULL; 64 } 65 if (input->row0 < 0) { 66 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 67 "psImage input is invalid. row0 cannot be negative.\n"); 68 psFree(out); 69 return NULL; 70 } 71 if (input->numCols < 1) { 72 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 73 "psImage input is invalid. numCols must be greater than 0.\n"); 74 psFree(out); 75 return NULL; 76 } 77 if (input->numRows < 1) { 78 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 79 "psImage input is invalid. numRows must be greater than 0.\n"); 80 psFree(out); 81 return NULL; 82 } 63 83 if (row >= (input->numRows + input->row0) ) { 64 84 psError(PS_ERR_BAD_PARAMETER_NULL, true, 65 85 "Specified row number is out of range for specified image.\n"); 86 psFree(out); 66 87 return NULL; 67 88 } else if ( row < input->row0 && row >= 0 ) { 68 89 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 69 90 "Specified row number is out of range for specified image.\n"); 91 psFree(out); 70 92 return NULL; 71 93 } else if ( row < 0 ) { … … 74 96 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 75 97 "Specified row number is out of range for specified image.\n"); 98 psFree(out); 76 99 return NULL; 77 100 } … … 164 187 return NULL; 165 188 } 166 PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL); 167 PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL); 168 PS_ASSERT_INT_POSITIVE(input->numCols, NULL); 169 PS_ASSERT_INT_POSITIVE(input->numRows, NULL); 189 if (input->col0 < 0) { 190 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 191 "psImage input is invalid. col0 cannot be negative.\n"); 192 psFree(out); 193 return NULL; 194 } 195 if (input->row0 < 0) { 196 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 197 "psImage input is invalid. row0 cannot be negative.\n"); 198 psFree(out); 199 return NULL; 200 } 201 if (input->numCols < 1) { 202 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 203 "psImage input is invalid. numCols must be greater than 0.\n"); 204 psFree(out); 205 return NULL; 206 } 207 if (input->numRows < 1) { 208 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 209 "psImage input is invalid. numRows must be greater than 0.\n"); 210 psFree(out); 211 return NULL; 212 } 170 213 if (column >= (input->numCols + input->col0) ) { 171 214 psError(PS_ERR_BAD_PARAMETER_NULL, true, 172 215 "Specified column number is out of range for specified image.\n"); 216 psFree(out); 173 217 return NULL; 174 218 } else if ( column < input->col0 && column >= 0 ) { 175 219 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 176 220 "Specified column number is out of range for specified image.\n"); 221 psFree(out); 177 222 return NULL; 178 223 } else if ( column < 0 ) { … … 181 226 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 182 227 "Specified column number is out of range for specified image.\n"); 228 psFree(out); 183 229 return NULL; 184 230 } … … 263 309 return NULL; 264 310 } 265 PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL); 266 PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL); 267 PS_ASSERT_INT_POSITIVE(input->numCols, NULL); 268 PS_ASSERT_INT_POSITIVE(input->numRows, NULL); 311 if (input->col0 < 0) { 312 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 313 "psImage input is invalid. col0 cannot be negative.\n"); 314 psFree(out); 315 return NULL; 316 } 317 if (input->row0 < 0) { 318 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 319 "psImage input is invalid. row0 cannot be negative.\n"); 320 psFree(out); 321 return NULL; 322 } 323 if (input->numCols < 1) { 324 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 325 "psImage input is invalid. numCols must be greater than 0.\n"); 326 psFree(out); 327 return NULL; 328 } 329 if (input->numRows < 1) { 330 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 331 "psImage input is invalid. numRows must be greater than 0.\n"); 332 psFree(out); 333 return NULL; 334 } 269 335 /* 270 336 if (col1 < 1) { 271 337 col1 += input->numCols; 272 338 } 273 339 274 340 if (row1 < 1) { 275 341 row1 += input->numRows; 276 342 } 277 343 278 344 if ( col0 < 0 || 279 345 row0 < 0 || … … 296 362 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 297 363 "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n", 298 region.x0, input->col0, input->col0+input->numCols );364 region.x0, input->col0, input->col0+input->numCols-1); 299 365 return NULL; 300 366 } … … 305 371 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 306 372 "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n", 307 region.y0, input->row0, input->row0+input->numRows );373 region.y0, input->row0, input->row0+input->numRows-1); 308 374 return NULL; 309 375 } … … 315 381 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 316 382 "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n", 317 region.x1, col1+input->col0, input->col0, input->col0+input->numCols );383 region.x1, col1+input->col0, input->col0, input->col0+input->numCols-1); 318 384 return NULL; 319 385 } … … 323 389 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 324 390 "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n", 325 region.x1, col1, input->col0, input->col0+input->numCols );391 region.x1, col1, input->col0, input->col0+input->numCols-1); 326 392 return NULL; 327 393 } … … 332 398 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 333 399 "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n", 334 region.y1, row1+input->row0, input->row0, input->row0+input->numRows );400 region.y1, row1+input->row0, input->row0, input->row0+input->numRows-1); 335 401 return NULL; 336 402 } … … 340 406 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 341 407 "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n", 342 region.y1, row1, input->row0, input->row0+input->numRows );408 region.y1, row1, input->row0, input->row0+input->numRows-1); 343 409 return NULL; 344 410 } … … 583 649 return NULL; 584 650 } 585 // PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL); 586 // PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL); 587 // PS_ASSERT_INT_POSITIVE(input->numCols, NULL); 588 // PS_ASSERT_INT_POSITIVE(input->numRows, NULL); 651 if (input->col0 < 0) { 652 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 653 "psImage input is invalid. col0 cannot be negative.\n"); 654 psFree(out); 655 return NULL; 656 } 657 if (input->row0 < 0) { 658 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 659 "psImage input is invalid. row0 cannot be negative.\n"); 660 psFree(out); 661 return NULL; 662 } 663 if (input->numCols < 1) { 664 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 665 "psImage input is invalid. numCols must be greater than 0.\n"); 666 psFree(out); 667 return NULL; 668 } 669 if (input->numRows < 1) { 670 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 671 "psImage input is invalid. numRows must be greater than 0.\n"); 672 psFree(out); 673 return NULL; 674 } 589 675 psS32 numCols = input->numCols; 590 676 psS32 numRows = input->numRows; … … 598 684 } 599 685 600 601 float startCol = region.x0; 602 float startRow = region.y0; 603 float endCol = region.x1; 604 float endRow = region.y1; 605 if (startCol < 0 || startCol >= numCols || 606 startRow < 0 || startRow >= numRows || 607 endCol < 0 || endCol >= numCols || 608 endRow < 0 || endRow >= numRows) { 609 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 610 PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE, 611 startCol,startRow,endCol,endRow, 612 numCols-1,numRows-1); 613 psFree(out); 614 return NULL; 615 } 686 float col0 = region.x0; 687 float row0 = region.y0; 688 float col1 = region.x1; 689 float row1 = region.y1; 690 691 //Make sure x0 of region is inside image. If so, set col0 to corresponding index number. 692 if (col0 >= input->col0 && col0 < (input->col0 + input->numCols) ) { 693 col0 -= input->col0; 694 } else { 695 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 696 "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n", 697 region.x0, input->col0, input->col0+input->numCols); 698 psFree(out); 699 return NULL; 700 } 701 //Make sure y0 of region is inside image. If so, set row0 to corresponding index number. 702 if (row0 >= input->row0 && row0 < (input->row0 + input->numRows) ) { 703 row0 -= input->row0; 704 } else { 705 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 706 "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n", 707 region.y0, input->row0, input->row0+input->numRows); 708 psFree(out); 709 return NULL; 710 } 711 /* 712 //Make sure x1 of region is valid. If negative, index from tail (if valid). 713 if (col1 < 0) { 714 col1 += input->numCols; 715 if (col1 < 0) { 716 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 717 "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n", 718 region.x1, col1+input->col0, input->col0, input->col0+input->numCols); 719 psFree(out); 720 return NULL; 721 } 722 } else if (col1 >= input->col0 && col1 < (input->col0 + input->numCols) ) { 723 col1 -= input->col0; 724 } else { 725 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 726 "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n", 727 region.x1, col1, input->col0, input->col0+input->numCols); 728 psFree(out); 729 return NULL; 730 } 731 //Make sure y1 of region is valid. If negative, index from tail (if valid). 732 if (row1 < 0) { 733 row1 += input->numRows; 734 if (row1 < 0) { 735 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 736 "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n", 737 region.y1, row1+input->row0, input->row0, input->row0+input->numRows); 738 psFree(out); 739 return NULL; 740 } 741 } else if (row1 >= input->row0 && row1 < (input->row0 + input->numRows) ) { 742 row1 -= input->row0; 743 } else { 744 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 745 "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n", 746 region.y1, row1, input->row0, input->row0+input->numRows); 747 psFree(out); 748 return NULL; 749 } 750 */ 751 /* //Now make sure that the region makes sense. 752 if (col0 > col1 || row0 > row1) { 753 if (col0 > col1) { 754 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 755 "Invalid psRegion specified. x0=%f=%f is greater than x1=%f=%f.\n", 756 region.x0, col0, region.x1, col1); 757 } else { 758 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 759 "Invalid psRegion specified. y0=%f=%f is greater than y1=%f=%f.\n", 760 region.y0, row0, region.y1, row1); 761 } 762 psFree(out); 763 return NULL; 764 } else if (col0 == col1 && row0 == row1) { 765 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 766 "Invalid psRegion specified. Region contains only 1 pixel.\n"); 767 psFree(out); 768 return NULL; 769 } 770 */ 771 if (col1 < 0 || row1 < 0 || col0 < 0 || row0 < 0 || col0 >= numCols || col1 >= numCols || 772 row0 >= numRows || row1 >= numRows) { 773 psFree(out); 774 return NULL; 775 } 776 float startCol = col0; 777 float startRow = row0; 778 float endCol = col1; 779 float endRow = row1; 780 /* 781 float startCol = region.x0; 782 float startRow = region.y0; 783 float endCol = region.x1; 784 float endRow = region.y1; 785 if (startCol < 0 || startCol >= numCols || 786 startRow < 0 || startRow >= numRows || 787 endCol < 0 || endCol >= numCols || 788 endRow < 0 || endRow >= numRows) { 789 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 790 PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE, 791 startCol,startRow,endCol,endRow, 792 numCols-1,numRows-1); 793 psFree(out); 794 return NULL; 795 } 796 */ 616 797 617 798 if (mode < PS_INTERPOLATE_FLAT ) { -
trunk/psLib/src/imageops/psImageStats.c
r6346 r6750 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1.9 0$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-0 2-07 23:14:21$11 * @version $Revision: 1.91 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-04-01 02:43:57 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 267 267 // We scale the pixel positions to values 268 268 // between -1.0 and 1.0 269 rScalingFactors = calcScaleFactors(input->numRows); 270 cScalingFactors = calcScaleFactors(input->numCols); 269 // rScalingFactors = calcScaleFactors(input->numRows); 270 // cScalingFactors = calcScaleFactors(input->numCols); 271 rScalingFactors = calcScaleFactors(input->row0 + input->numRows); 272 cScalingFactors = calcScaleFactors(input->col0 + input->numCols); 271 273 272 274 // Determine how many Chebyshev polynomials … … 283 285 for (j = 0; j < (1 + coeffs->nY); j++) { 284 286 sums[i][j] = 0.0; 285 for (x = 0; x < input->numRows; x++) { 286 for (y = 0; y < input->numCols; y++) { 287 // for (x = 0; x < input->numRows; x++) { 288 // for (y = 0; y < input->numCols; y++) { 289 for (x = input->row0; x < (input->row0 + input->numRows); x++) { 290 for (y = input->col0; y < (input->col0 + input->numCols); y++) { 287 291 double pixel = 0.0; 288 292 if (input->type.type == PS_TYPE_S8) { … … 399 403 // nodes->data.F64[x][y] = psImagePixelInterpolate(input, yNode, xNode, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 400 404 // nodes->data.F64[x][y] = psImagePixelInterpolate(input, yTmp, xTmp, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 401 nodes->data.F64[x][y] = psImagePixelInterpolate(input, yOrig, xOrig, NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 405 nodes->data.F64[x][y] = psImagePixelInterpolate(input, yOrig, xOrig, NULL, 406 0, 0.0, PS_INTERPOLATE_BILINEAR); 402 407 } 403 408 } … … 505 510 // We scale the pixel positions to values between -1.0 and 1.0 506 511 // Use static data structures here. 507 rScalingFactors = calcScaleFactors(input->numRows); 508 cScalingFactors = calcScaleFactors(input->numCols); 512 // rScalingFactors = calcScaleFactors(input->numRows); 513 // cScalingFactors = calcScaleFactors(input->numCols); 514 rScalingFactors = calcScaleFactors(input->numRows+input->row0); 515 cScalingFactors = calcScaleFactors(input->numCols+input->col0); 509 516 510 517 // Determine how many Chebyshev polynomials … … 517 524 chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1); 518 525 519 for (x = 0; x < input->numRows; x++) { 520 for (y = 0; y < input->numCols; y++) { 526 // for (x = 0; x < input->numRows; x++) { 527 // for (y = 0; y < input->numCols; y++) { 528 for (x = input->row0; x < (input->row0 + input->numRows); x++) { 529 for (y = input->col0; y < (input->col0 + input->numCols); y++) { 521 530 polySum = 0.0; 522 531 for (i = 0; i < (1 + coeffs->nX); i++) { … … 563 572 for (int col = 0; col < input->numCols ; col++) { 564 573 if (input->type.type == PS_TYPE_S8) { 565 input->data.S8[row][col] = (psS8) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col); 574 input->data.S8[row][col] = (psS8) psPolynomial2DEval(coeffs, 575 (psF32) (row + input->row0), (psF32) (col + input->col0)); 566 576 } else if (input->type.type == PS_TYPE_U16) { 567 input->data.U16[row][col] = (psS16) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col); 577 input->data.U16[row][col] = (psS16) psPolynomial2DEval(coeffs, 578 (psF32) (row + input->row0), (psF32) (col + input->col0)); 568 579 } else if (input->type.type == PS_TYPE_F32) { 569 input->data.F32[row][col] = psPolynomial2DEval(coeffs, (psF32) row, (psF32) col); 580 input->data.F32[row][col] = psPolynomial2DEval(coeffs, 581 (psF32) (row + input->row0), (psF32) (col + input->col0)); 570 582 } else if (input->type.type == PS_TYPE_F64) { 571 input->data.F64[row][col] = (psF64) psPolynomial2DEval(coeffs, (psF32) row, (psF32) col); 583 input->data.F64[row][col] = (psF64) psPolynomial2DEval(coeffs, 584 (psF32) (row + input->row0), (psF32) (col + input->col0)); 572 585 } 573 586 } … … 617 630 int y1 = 0; 618 631 psElemType type; 619 if (mask == NULL) {620 psError(PS_ERR_BAD_PARAMETER_NULL, true,621 PS_ERRORTEXT_psImage_IMAGE_NULL);622 return -1;623 }624 632 625 633 // this is not a valid error: a psRegion with ranges outside the valid pixels … … 641 649 642 650 // rationalize the region 643 region = psRegionForImage(mask, region); 644 645 if (region.x0 == region.x1 || region.y0 == region.y1) { 646 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 647 "psRegion input contains 0 pixels\n"); 651 652 /* 653 if (mask == NULL) { 654 psError(PS_ERR_BAD_PARAMETER_NULL, true, 655 PS_ERRORTEXT_psImage_IMAGE_NULL); 656 return -1; 657 } 658 region = psRegionForImage(mask, region); 659 660 if (region.x0 == region.x1 || region.y0 == region.y1) { 661 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 662 "psRegion input contains 0 pixels\n"); 663 return -1; 664 } 665 */ 666 PS_ASSERT_IMAGE_NON_NULL(mask, -1); 667 PS_ASSERT_INT_NONNEGATIVE(mask->col0, -1); 668 PS_ASSERT_INT_NONNEGATIVE(mask->row0, -1); 669 PS_ASSERT_INT_POSITIVE(mask->numCols, -1); 670 PS_ASSERT_INT_POSITIVE(mask->numRows, -1); 671 672 /* x0 = (int)(roundf(region.x0)); 673 x1 = (int)(roundf(region.x1)); 674 y0 = (int)(roundf(region.y0)); 675 y1 = (int)(roundf(region.y1)); 676 */ 677 int col0 = (int)(roundf(region.x0)); 678 int col1 = (int)(roundf(region.x1)); 679 int row0 = (int)(roundf(region.y0)); 680 int row1 = (int)(roundf(region.y1)); 681 //If (0,0,0,0) specified, the whole image is to be used. 682 if (col0 == 0 && col1 == 0 && row0 == 0 && row1 == 0) { 683 col0 = mask->col0; 684 col1 = mask->col0 + mask->numCols - 1; 685 row0 = mask->row0; 686 row1 = mask->row0 + mask->numRows - 1; 687 } 688 689 //Make sure x0 of region is inside image. If so, set col0 to corresponding index number. 690 if (col0 >= mask->col0 && col0 < (mask->col0 + mask->numCols) ) { 691 col0 -= mask->col0; 692 } else { 693 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 694 "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n", 695 region.x0, mask->col0, mask->col0+mask->numCols-1); 648 696 return -1; 649 697 } 650 651 x0 = (int)(roundf(region.x0)); 652 x1 = (int)(roundf(region.x1)); 653 y0 = (int)(roundf(region.y0)); 654 y1 = (int)(roundf(region.y1)); 698 //Make sure y0 of region is inside image. If so, set row0 to corresponding index number. 699 if (row0 >= mask->row0 && row0 < (mask->row0 + mask->numRows) ) { 700 row0 -= mask->row0; 701 } else { 702 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 703 "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n", 704 region.y0, mask->row0, mask->row0+mask->numRows-1); 705 return -1; 706 } 707 708 //Make sure x1 of region is valid. If negative, index from tail (if valid). 709 if (col1 < 0) { 710 col1 += mask->numCols; 711 if (col1 < 0) { 712 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 713 "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n", 714 region.x1, col1+mask->col0, mask->col0, mask->col0+mask->numCols-1); 715 return -1; 716 } 717 } else if (col1 >= mask->col0 && col1 < (mask->col0 + mask->numCols) ) { 718 col1 -= mask->col0; 719 } else { 720 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 721 "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n", 722 region.x1, col1, mask->col0, mask->col0+mask->numCols-1); 723 return -1; 724 } 725 //Make sure y1 of region is valid. If negative, index from tail (if valid). 726 if (row1 < 0) { 727 row1 += mask->numRows; 728 if (row1 < 0) { 729 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 730 "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n", 731 region.y1, row1+mask->row0, mask->row0, mask->row0+mask->numRows-1); 732 return -1; 733 } 734 } else if (row1 >= mask->row0 && row1 < (mask->row0 + mask->numRows) ) { 735 row1 -= mask->row0; 736 } else { 737 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 738 "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n", 739 region.y1, row1, mask->row0, mask->row0+mask->numRows-1); 740 return -1; 741 } 742 //Now make sure that the region makes sense. 743 if (col0 > col1 || row0 > row1) { 744 if (col0 > col1) { 745 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 746 "Invalid psRegion specified. x0=%f=%d is greater than x1=%f=%d.\n", 747 region.x0, col0, region.x1, col1); 748 } else { 749 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 750 "Invalid psRegion specified. y0=%f=%d is greater than y1=%f=%d.\n", 751 region.y0, row0, region.y1, row1); 752 } 753 return -1; 754 }/* else if (col0 == col1 && row0 == row1) { 755 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 756 "Invalid psRegion specified. Region contains only 1 pixel.\n"); 757 return -1; 758 } 759 */ 760 x0 = col0; 761 x1 = col1; 762 y0 = row0; 763 y1 = row1; 655 764 656 765 type = mask->type.type; … … 664 773 case PS_TYPE_U8: 665 774 case PS_TYPE_U16: 666 for (long j = y0; j < y1; j++) {667 for (long i = x0; i < x1; i++) {775 for (long j = y0; j <= y1; j++) { 776 for (long i = x0; i <= x1; i++) { 668 777 if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) { 669 778 Npixels ++;
Note:
See TracChangeset
for help on using the changeset viewer.
