Changeset 12814
- Timestamp:
- Apr 12, 2007, 8:54:51 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/imageops/psImageStructManip.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageStructManip.c
r12431 r12814 8 8 * @author Robert DeSonia, MHPCC 9 9 * 10 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2007-0 3-14 00:39:50$10 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2007-04-12 18:54:51 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 20 20 21 21 #include <string.h> 22 #include <assert.h> 22 23 23 24 #include "psMemory.h" … … 26 27 27 28 28 29 // col0,row0 are the starting pixel in the input image coordinate frame 30 // col1,row1 are the ending pixel in the input image coordinate frame 31 // note that these are relative to the input col0,row0 32 // also note that col0,row0 may not be less than input->col0,row0 29 33 static psImage* imageSubset(psImage* out, 30 34 psImage* image, … … 35 39 { 36 40 psU32 elementSize; // size of image element in bytes 37 psS32 inputColOffset; // offset in bytes to first subset pixel in input row 41 psS32 inputColOffset; // offset in **bytes** to first subset pixel in input row 42 psS32 inputRowOffset; // offset in **rows*** to first input row 38 43 39 44 if (image == NULL || image->data.V == NULL) { … … 44 49 45 50 if ( col0 < image->col0 || row0 < image->row0 ) { 46 // psError(PS_ERR_BAD_PARAMETER_VALUE, true, 47 // _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d].")); 51 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 52 _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."), 53 col0, col1-1, row0, row1-1, image->numCols-1, image->numRows-1); 54 return NULL; 55 } 56 57 if (image->type.dimen != PS_DIMEN_IMAGE) { 58 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 59 _("The input psImage must have a PS_DIMEN_IMAGE dimension type.")); 60 return NULL; 61 } 62 63 if (col1 < 1) { 64 col1 = image->col0 + image->numCols + col1; 65 } 66 if (row1 < 1) { 67 row1 = image->row0 + image->numRows + row1; 68 } 69 70 if (col1 <= col0 || 71 row1 <= row0 || 72 col0 >= image->col0 + image->numCols || 73 row0 >= image->row0 + image->numRows || 74 col1 > image->col0 + image->numCols || 75 row1 > image->row0 + image->numRows ) { 48 76 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 49 77 _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."), … … 53 81 } 54 82 55 if (image->type.dimen != PS_DIMEN_IMAGE) {56 psError(PS_ERR_BAD_PARAMETER_TYPE, true,57 _("The input psImage must have a PS_DIMEN_IMAGE dimension type."));58 return NULL;59 }60 61 if (col1 < 1) {62 col1 = image->col0 + image->numCols + col1;63 }64 if (row1 < 1) {65 row1 = image->row0 + image->numRows + row1;66 }67 68 if ( col1 <= col0 ||69 row1 <= row0 ||70 col0 >= image->col0 + image->numCols ||71 row0 >= image->row0 + image->numRows ||72 col1 > image->col0 + image->numCols ||73 row1 > image->row0 + image->numRows ) {74 psError(PS_ERR_BAD_PARAMETER_VALUE, true,75 _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."),76 col0, col1-1, row0, row1-1,77 image->numCols-1, image->numRows-1);78 return NULL;79 }80 81 82 83 83 psS32 numRows = row1-row0; 84 84 psS32 numCols = col1-col0; … … 86 86 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 87 87 88 if (image->parent != NULL) { // if this is a child, we need to start working with parent. 89 // XXX EAM : we now treat the region as parent coordinates 90 // col0 += image->col0; 91 // col1 += image->col0; 92 // row0 += image->row0; 93 // row1 += image->row0; 88 // if this is a child, we need to start working with parent pixels 89 // the subset region (col0,row0 - col1,row1) is in the parent frame 90 if (image->parent != NULL) { 94 91 image = (psImage*)image->parent; 95 92 } … … 116 113 P_PSIMAGE_SET_NUMCOLS(out, numCols); 117 114 P_PSIMAGE_SET_NUMROWS(out, numRows); 118 119 out->row0 = row0;120 out->col0 = col0; 115 P_PSIMAGE_SET_COL0(out, col0); 116 P_PSIMAGE_SET_ROW0(out, row0); 117 121 118 out->parent = image; 122 119 out->children = NULL; … … 126 123 psMemSetDeallocator(out,psMemGetDeallocator(image)); 127 124 128 inputColOffset = elementSize * col0; 125 inputRowOffset = (row0 - image->row0); 126 inputColOffset = (col0 - image->col0)*elementSize; 127 assert (inputRowOffset >= 0); 128 assert (inputColOffset >= 0); 129 129 for (psS32 row = 0; row < numRows; row++) { 130 out->data.V[row] = image->data.U8[row 0 + row] + inputColOffset;130 out->data.V[row] = image->data.U8[row + inputRowOffset] + inputColOffset; 131 131 } 132 132 … … 183 183 184 184 output = psImageRecycle(output, numCols, numRows, type); 185 output->col0 = input->col0;186 output->row0 = input->row0;185 P_PSIMAGE_SET_COL0(output, input->col0); 186 P_PSIMAGE_SET_ROW0(output, input->row0); 187 187 188 188 // cover the trival case of copy of the same
Note:
See TracChangeset
for help on using the changeset viewer.
