Changeset 719
- Timestamp:
- May 18, 2004, 1:26:26 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 1 deleted
- 4 edited
-
image/psImage.c (modified) (4 diffs)
-
image/psImage.h (modified) (2 diffs)
-
mathtypes/psImage.c (modified) (4 diffs)
-
mathtypes/psImage.h (modified) (2 diffs)
-
psLib.h (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r715 r719 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-18 18:39:43$9 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-18 23:26:26 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 70 70 } 71 71 72 psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type) 73 { 74 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 75 int rowSize = numCols*elementSize; // row size in bytes. 76 77 if (old == NULL) { 78 old = psImageAlloc(numCols,numRows,type); 79 return old; 80 } 81 82 if (old->type.dimen != PS_DIMEN_IMAGE) { 83 psError(__func__,"Can not realloc image because image is not an image."); 84 return NULL; 85 } 86 87 /* image already the right size/type? */ 88 if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) { 89 return old; 90 } 91 92 // Resize the image buffer 93 old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize); 94 old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*)); 95 96 // recreate the row pointers 97 for(int i = 1; i < numRows; i++) { 98 old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize); 99 } 100 101 *(unsigned int*)&old->numCols = numCols; 102 *(unsigned int*)&old->numRows = numRows; 103 *(psElemType*)&old->type.type = type; 104 105 return old; 106 } 107 72 108 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols, 73 109 unsigned int numRows, unsigned int col0, unsigned int row0) 74 110 { 75 psElemType type;76 111 unsigned int elementSize; // size of image element in bytes 77 112 unsigned int outputRowSize; // output row size in bytes … … 88 123 } 89 124 125 if (numCols < 1 || numRows < 1) { 126 psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).", 127 numCols, numRows); 128 return NULL; 129 } 130 131 if (col0 >= image->numCols || row0 >= image->numRows) { 132 psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel " 133 "location.", col0,row0); 134 return NULL; 135 } 136 90 137 /* validate subimage size */ 91 138 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) { 92 139 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, " 93 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0, 94 image->col0+numCols, image->row0, image->row0+numRows); 95 return NULL; 96 } 97 98 type = image->type.type; 99 elementSize = PSELEMTYPE_SIZEOF(type); 100 101 if (out == NULL) { 102 out = psImageAlloc(numCols,numRows,image->type.type); 103 } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) { 104 // sizes/type different, can't reuse the given image buffer 105 psImageFree(out); 106 out = psImageAlloc(numCols,numRows,image->type.type); 107 } 140 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0, 141 col0+numCols, row0, row0+numRows); 142 return NULL; 143 } 144 145 146 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 147 148 out = psImageRealloc(out,numCols,numRows,image->type.type); 108 149 109 150 // set the parent information into the child output image … … 199 240 } 200 241 201 202 if (output == NULL) { 203 output = psImageAlloc(numCols,numRows,type); 204 } else if (output->numCols != numCols || output->numRows != numRows || 205 output->type.type != type) { // sizes/type different, can't reuse the given image buffer 206 psImageFree(output); 207 output = psImageAlloc(numCols,numRows,type); 208 } 209 210 // cover the trival case of copy of the same type. 242 output = psImageRealloc(output,numCols,numRows,type); 243 244 // cover the trival case of copy of the same datatype. 211 245 if (type == inDatatype) { 212 246 memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols); -
trunk/psLib/src/image/psImage.h
r714 r719 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-18 02:33:59$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-18 23:26:26 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 138 138 ); 139 139 140 /** Resize a given image to the given size/type. 141 * 142 * return psImage* Resized psImage. 143 * 144 */ 145 psImage* psImageRealloc( 146 psImage* old, ///< the psImage to recycle by resizing image buffer 147 unsigned int numCols, ///< the desired number of columns in image 148 unsigned int numRows, ///< the desired number of rows in image 149 const psElemType type ///< the desired datatype of the image 150 ); 151 140 152 #endif -
trunk/psLib/src/mathtypes/psImage.c
r715 r719 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-18 18:39:43$9 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-18 23:26:26 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 70 70 } 71 71 72 psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type) 73 { 74 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 75 int rowSize = numCols*elementSize; // row size in bytes. 76 77 if (old == NULL) { 78 old = psImageAlloc(numCols,numRows,type); 79 return old; 80 } 81 82 if (old->type.dimen != PS_DIMEN_IMAGE) { 83 psError(__func__,"Can not realloc image because image is not an image."); 84 return NULL; 85 } 86 87 /* image already the right size/type? */ 88 if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) { 89 return old; 90 } 91 92 // Resize the image buffer 93 old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize); 94 old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*)); 95 96 // recreate the row pointers 97 for(int i = 1; i < numRows; i++) { 98 old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize); 99 } 100 101 *(unsigned int*)&old->numCols = numCols; 102 *(unsigned int*)&old->numRows = numRows; 103 *(psElemType*)&old->type.type = type; 104 105 return old; 106 } 107 72 108 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols, 73 109 unsigned int numRows, unsigned int col0, unsigned int row0) 74 110 { 75 psElemType type;76 111 unsigned int elementSize; // size of image element in bytes 77 112 unsigned int outputRowSize; // output row size in bytes … … 88 123 } 89 124 125 if (numCols < 1 || numRows < 1) { 126 psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).", 127 numCols, numRows); 128 return NULL; 129 } 130 131 if (col0 >= image->numCols || row0 >= image->numRows) { 132 psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel " 133 "location.", col0,row0); 134 return NULL; 135 } 136 90 137 /* validate subimage size */ 91 138 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) { 92 139 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, " 93 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0, 94 image->col0+numCols, image->row0, image->row0+numRows); 95 return NULL; 96 } 97 98 type = image->type.type; 99 elementSize = PSELEMTYPE_SIZEOF(type); 100 101 if (out == NULL) { 102 out = psImageAlloc(numCols,numRows,image->type.type); 103 } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) { 104 // sizes/type different, can't reuse the given image buffer 105 psImageFree(out); 106 out = psImageAlloc(numCols,numRows,image->type.type); 107 } 140 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0, 141 col0+numCols, row0, row0+numRows); 142 return NULL; 143 } 144 145 146 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 147 148 out = psImageRealloc(out,numCols,numRows,image->type.type); 108 149 109 150 // set the parent information into the child output image … … 199 240 } 200 241 201 202 if (output == NULL) { 203 output = psImageAlloc(numCols,numRows,type); 204 } else if (output->numCols != numCols || output->numRows != numRows || 205 output->type.type != type) { // sizes/type different, can't reuse the given image buffer 206 psImageFree(output); 207 output = psImageAlloc(numCols,numRows,type); 208 } 209 210 // cover the trival case of copy of the same type. 242 output = psImageRealloc(output,numCols,numRows,type); 243 244 // cover the trival case of copy of the same datatype. 211 245 if (type == inDatatype) { 212 246 memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols); -
trunk/psLib/src/mathtypes/psImage.h
r714 r719 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-18 02:33:59$9 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-18 23:26:26 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 138 138 ); 139 139 140 /** Resize a given image to the given size/type. 141 * 142 * return psImage* Resized psImage. 143 * 144 */ 145 psImage* psImageRealloc( 146 psImage* old, ///< the psImage to recycle by resizing image buffer 147 unsigned int numCols, ///< the desired number of columns in image 148 unsigned int numRows, ///< the desired number of rows in image 149 const psElemType type ///< the desired datatype of the image 150 ); 151 140 152 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
