Changeset 2204 for trunk/psLib/src/image/psImageExtraction.c
- Timestamp:
- Oct 26, 2004, 2:57:34 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageExtraction.c (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageExtraction.c
r2105 r2204 9 9 * @author Robert DeSonia, MHPCC 10 10 * 11 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-10- 14 01:22:59$11 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-10-27 00:57:31 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 psImage* imageSubset(psImage* out, 27 27 psImage* image, 28 intcol0,29 introw0,30 intcol1,31 introw1)28 psS32 col0, 29 psS32 row0, 30 psS32 col1, 31 psS32 row1) 32 32 { 33 unsigned intelementSize; // size of image element in bytes34 unsigned intinputColOffset; // offset in bytes to first subset pixel in input row33 psU32 elementSize; // size of image element in bytes 34 psU32 inputColOffset; // offset in bytes to first subset pixel in input row 35 35 36 36 if (image == NULL || image->data.V == NULL) { … … 68 68 return NULL; 69 69 } 70 intnumRows = row1-row0;71 intnumCols = col1-col0;70 psS32 numRows = row1-row0; 71 psS32 numCols = col1-col0; 72 72 73 73 elementSize = PSELEMTYPE_SIZEOF(image->type.type); … … 82 82 83 83 // increment the raw data buffer before freeing anything in the 'out' 84 void*rawData = psMemIncrRefCounter(image->rawDataBuffer);84 psPtr rawData = psMemIncrRefCounter(image->rawDataBuffer); 85 85 86 86 if (out != NULL) { … … 97 97 } 98 98 99 out->data.V = psRealloc(out->data.V,sizeof( void*)*numRows); // resize row pointer array99 out->data.V = psRealloc(out->data.V,sizeof(psPtr)*numRows); // resize row pointer array 100 100 *(psType*)&out->type = image->type; 101 *( unsigned int*)&out->numCols = numCols;102 *( unsigned int*)&out->numRows = numRows;103 *( int*)&out->row0 = row0;104 *( int*)&out->col0 = col0;101 *(psU32*)&out->numCols = numCols; 102 *(psU32*)&out->numRows = numRows; 103 *(psS32*)&out->row0 = row0; 104 *(psS32*)&out->col0 = col0; 105 105 out->parent = image; 106 106 out->children = NULL; … … 111 111 112 112 inputColOffset = elementSize * col0; 113 for ( introw = 0; row < numRows; row++) {113 for (psS32 row = 0; row < numRows; row++) { 114 114 out->data.V[row] = image->data.U8[row0 + row] + inputColOffset; 115 115 } 116 116 117 117 // add output image as a child of the input image. 118 intn = 0;118 psS32 n = 0; 119 119 psArray* children = image->children; 120 120 if (children == NULL) { … … 134 134 135 135 psImage* psImageSubset(psImage* image, 136 intcol0,137 introw0,138 intcol1,139 introw1)136 psS32 col0, 137 psS32 row0, 138 psS32 col1, 139 psS32 row1) 140 140 { 141 141 return imageSubset(NULL,image,col0,row0,col1,row1); … … 145 145 const char* section) 146 146 { 147 intcol0;148 intcol1;149 introw0;150 introw1;147 psS32 col0; 148 psS32 col1; 149 psS32 row0; 150 psS32 row1; 151 151 152 152 // section should be of the form '[col0:col1,row0:row1]' … … 177 177 } 178 178 179 psImage* psImageTrim(psImage* image, int col0, int row0, int col1, introw1)179 psImage* psImageTrim(psImage* image, psS32 col0, psS32 row0, psS32 col1, psS32 row1) 180 180 { 181 181 if (image == NULL || image->data.V == NULL) { … … 220 220 psImageFreeChildren(image); 221 221 222 unsigned intelementSize = PSELEMTYPE_SIZEOF(image->type.type);223 unsigned intnumCols = col1-col0;224 unsigned intnumRows = row1-row0;225 unsigned introwSize = elementSize*numCols;226 unsigned intcolOffset = elementSize * col0;222 psU32 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 223 psU32 numCols = col1-col0; 224 psU32 numRows = row1-row0; 225 psU32 rowSize = elementSize*numCols; 226 psU32 colOffset = elementSize * col0; 227 227 psU8* imageData = image->rawDataBuffer; 228 for ( introw = row0; row < row1; row++) {228 for (psS32 row = row0; row < row1; row++) { 229 229 memmove(imageData,image->data.U8[row] + colOffset,rowSize); 230 230 imageData += rowSize; 231 231 } 232 232 233 *( unsigned int*)&image->numRows = numRows;234 *( unsigned int*)&image->numCols = numCols;233 *(psU32*)&image->numRows = numRows; 234 *(psU32*)&image->numCols = numCols; 235 235 236 236 // XXX: should I really resize the buffers? 237 image->data.V = psRealloc(image->data.V,sizeof( void*)*numRows);237 image->data.V = psRealloc(image->data.V,sizeof(psPtr)*numRows); 238 238 image->rawDataBuffer = psRealloc(image->rawDataBuffer,rowSize*numRows); 239 239 240 240 image->data.V[0] = image->rawDataBuffer; 241 for ( intr = 1; r < numRows; r++) {241 for (psS32 r = 1; r < numRows; r++) { 242 242 image->data.U8[r] = image->data.U8[r-1] + rowSize; 243 243 } … … 250 250 const psImage* restrict in, 251 251 const psImage* restrict mask, 252 unsigned intmaskVal,253 intcol0,254 introw0,255 intcol1,256 introw1,252 psU32 maskVal, 253 psS32 col0, 254 psS32 row0, 255 psS32 col1, 256 psS32 row1, 257 257 psImageCutDirection direction, 258 258 const psStats* stats) … … 261 261 psStats* myStats; 262 262 psElemType type; 263 intinRows;264 intinCols;265 intdelta = 1;263 psS32 inRows; 264 psS32 inCols; 265 psS32 delta = 1; 266 266 psF64* outData; 267 267 … … 349 349 *myStats = *stats; 350 350 351 intnumCols = col1-col0;352 intnumRows = row1-row0;351 psS32 numCols = col1-col0; 352 psS32 numRows = row1-row0; 353 353 354 354 if (direction == PS_CUT_X_POS || direction == PS_CUT_X_NEG) { … … 380 380 case PS_TYPE_##TYPE: { \ 381 381 psMaskType* maskVecData = NULL; \ 382 for ( intc=col0;c<col1;c++) { \382 for (psS32 c=col0;c<col1;c++) { \ 383 383 ps##TYPE *imgData = in->data.TYPE[row0] + c; \ 384 384 ps##TYPE *imgVecData = imgVec->data.TYPE; \ … … 387 387 maskData = (psMaskType* )(mask->data.V[row0]) + c; \ 388 388 } \ 389 for ( intr=row0;r<row1;r++) { \389 for (psS32 r=row0;r<row1;r++) { \ 390 390 *(imgVecData++) = *imgData; \ 391 391 imgData += inCols; \ … … 437 437 psVector* imgVec = NULL; 438 438 psVector* maskVec = NULL; 439 intelementSize = PSELEMTYPE_SIZEOF(type);439 psS32 elementSize = PSELEMTYPE_SIZEOF(type); 440 440 psU32* outPosition = NULL; 441 441 … … 465 465 } 466 466 467 for ( intr = row0; r < row1; r++) {467 for (psS32 r = row0; r < row1; r++) { 468 468 // point the vector struct to the 469 469 // data to calculate the stats 470 imgVec->data.V = ( void *)(in->data.U8[r] + col0 * elementSize);470 imgVec->data.V = (psPtr )(in->data.U8[r] + col0 * elementSize); 471 471 if (maskVec != NULL) { 472 maskVec->data.V = ( void *)(mask->data.U8[r] + col0 * sizeof(psMaskType));472 maskVec->data.V = (psPtr )(mask->data.U8[r] + col0 * sizeof(psMaskType)); 473 473 } 474 474 myStats = psVectorStats(myStats, imgVec, maskVec, maskVal); … … 503 503 const psImage* in, 504 504 const psImage* restrict mask, 505 unsigned intmaskVal,505 psU32 maskVal, 506 506 float startCol, 507 507 float startRow, 508 508 float endCol, 509 509 float endRow, 510 unsigned intnSamples,510 psU32 nSamples, 511 511 psImageInterpolateMode mode) 512 512 { … … 518 518 return NULL; 519 519 } 520 intnumCols = in->numCols;521 intnumRows = in->numRows;520 psS32 numCols = in->numCols; 521 psS32 numRows = in->numRows; 522 522 523 523 if (nSamples < 2) { … … 594 594 case PS_TYPE_##TYPE: { \ 595 595 ps##TYPE* outData = out->data.TYPE; \ 596 for ( inti = 0; i < nSamples; i++) { \596 for (psS32 i = 0; i < nSamples; i++) { \ 597 597 float x = startCol + (float)i*dX; \ 598 598 float y = startRow + (float)i*dY; \ … … 642 642 const psImage* in, 643 643 const psImage* restrict mask, 644 unsigned intmaskVal,644 psU32 maskVal, 645 645 float centerCol, 646 646 float centerRow, … … 659 659 return NULL; 660 660 } 661 intnumCols = in->numCols;662 intnumRows = in->numRows;661 psS32 numCols = in->numCols; 662 psS32 numRows = in->numRows; 663 663 664 664 if (mask != NULL) { … … 734 734 735 735 // size the output vector to proper size. 736 intnumOut = radii->n - 1;736 psS32 numOut = radii->n - 1; 737 737 out = psVectorRecycle(out, numOut, PS_TYPE_F64); 738 738 psF64* outData = out->data.F64; … … 741 741 psF32* rSq = rSqVec->data.F32; 742 742 743 intstartRow = centerRow - rSq[numOut];744 intendRow = centerRow + rSq[numOut];745 intstartCol = centerCol - rSq[numOut];746 intendCol = centerCol + rSq[numOut];743 psS32 startRow = centerRow - rSq[numOut]; 744 psS32 endRow = centerRow + rSq[numOut]; 745 psS32 startCol = centerCol - rSq[numOut]; 746 psS32 endCol = centerCol + rSq[numOut]; 747 747 748 748 if (startRow < 0) { … … 763 763 764 764 // Square the radii data 765 for ( intd = 0; d <= numOut; d++) {765 for (psS32 d = 0; d <= numOut; d++) { 766 766 rSq[d] *= rSq[d]; 767 767 } … … 770 770 psVector** buffer = psAlloc(sizeof(psVector*)*numOut); 771 771 psVector** bufferMask = psAlloc(sizeof(psVector*)*numOut); 772 for ( intlcv = 0; lcv < numOut; lcv++) {772 for (psS32 lcv = 0; lcv < numOut; lcv++) { 773 773 // n.b. alloc enough for the data by making the vectors slightly larger 774 774 // than the area of the region of interest. … … 788 788 float dY; 789 789 float dist; 790 for ( introw=startRow; row <= endRow; row++) {790 for (psS32 row=startRow; row <= endRow; row++) { 791 791 psF32* inRow = in->data.F32[row]; 792 792 psMaskType* maskRow = NULL; … … 794 794 maskRow = mask->data.PS_TYPE_MASK_DATA[row]; 795 795 } 796 for ( intcol=startCol; col <= endCol; col++) {796 for (psS32 col=startCol; col <= endCol; col++) { 797 797 dX = centerCol - (float)col - 0.5f; 798 798 dY = centerRow - (float)row - 0.5f; 799 799 dist = dX*dX+dY*dY; 800 for ( intr = 0; r < numOut; r++) {800 for (psS32 r = 0; r < numOut; r++) { 801 801 if (rSq[r] < dist && dist < rSq[r+1]) { 802 intn = buffer[r]->n;802 psS32 n = buffer[r]->n; 803 803 if (n == buffer[r]->nalloc) { // in case buffers already full, expand 804 804 buffer[r] = psVectorRealloc(buffer[r], n*2); … … 825 825 *myStats = *stats; 826 826 827 for ( intr = 0; r < numOut; r++) {827 for (psS32 r = 0; r < numOut; r++) { 828 828 myStats = psVectorStats(myStats,buffer[r], bufferMask[r],maskVal); 829 829 (void)p_psGetStatValue(myStats,&statVal); … … 833 833 psFree(myStats); 834 834 835 for ( intlcv = 0; lcv < numOut; lcv++) {835 for (psS32 lcv = 0; lcv < numOut; lcv++) { 836 836 psFree(buffer[lcv]); 837 837 psFree(bufferMask[lcv]);
Note:
See TracChangeset
for help on using the changeset viewer.
