Changeset 1263
- Timestamp:
- Jul 22, 2004, 10:42:22 AM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 10 edited
-
image/psImage.c (modified) (3 diffs)
-
image/psImage.d (modified) (1 diff)
-
image/psImage.h (modified) (3 diffs)
-
image/psImageIO.d (modified) (1 diff)
-
image/psImageManip.c (modified) (2 diffs)
-
image/psImageManip.d (modified) (1 diff)
-
image/psImageManip.h (modified) (2 diffs)
-
image/psImageStats.d (modified) (1 diff)
-
mathtypes/psImage.c (modified) (3 diffs)
-
mathtypes/psImage.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r1261 r1263 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-07-22 20: 09:04$11 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-07-22 20:42:22 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 167 167 } 168 168 169 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,170 unsigned int numRows, unsigned int col0,171 unsigned int row0)172 {173 unsigned int elementSize; // size of image element in bytes174 unsigned int outputRowSize; // output row size in bytes175 unsigned int inputColOffset; // offset in bytes to first subset pixel in input row176 177 if (image == NULL || image->data.V == NULL) {178 psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");179 return NULL;180 }181 182 if (image->type.dimen != PS_DIMEN_IMAGE) {183 psError(__func__,"Can not subset image because input image is not an image.");184 return NULL;185 }186 187 if (numCols < 1 || numRows < 1) {188 psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",189 numCols, numRows);190 return NULL;191 }192 193 if (col0 >= image->numCols || row0 >= image->numRows) {194 psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel location.",195 col0,row0);196 return NULL;197 }198 199 /* validate subimage size */200 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {201 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "202 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,203 col0+numCols, row0, row0+numRows);204 return NULL;205 }206 207 208 elementSize = PSELEMTYPE_SIZEOF(image->type.type);209 210 out = psImageRecycle(out,numCols,numRows,image->type.type);211 212 // set the parent information into the child output image213 *(int*)&out->row0 = row0;214 *(int*)&out->col0 = col0;215 *(psImage**)&out->parent = (psImage*)image;216 217 // add output image as a child of the input image.218 image->nChildren++;219 image->children = (psImage **) psRealloc(image->children,220 image->nChildren * sizeof(psImage*) );221 image->children[image->nChildren-1] = out;222 223 inputColOffset = elementSize*col0;224 outputRowSize = elementSize*numCols;225 226 for (int row = 0; row < numRows; row++) {227 memcpy(out->data.V[row],image->data.U8[row0+row] + inputColOffset,228 outputRowSize);229 }230 231 return (out);232 }233 234 169 int psImageFreeChildren(psImage* image) 235 170 { … … 259 194 260 195 return numFreed; 261 }262 263 264 265 psImage *psImageCopy(psImage* restrict output, const psImage *input,266 psElemType type)267 {268 psElemType inDatatype;269 int elementSize;270 int elements;271 int numRows;272 int numCols;273 274 if (input == NULL || input->data.V == NULL) {275 psError(__func__,"Can not copy image because input image or its pixel buffer is NULL.");276 return NULL;277 }278 279 if (input == output) {280 psError(__func__,"Can not copy image because given input and output "281 "parameter reference the same psImage struct.");282 return NULL;283 }284 285 if (input->type.dimen != PS_DIMEN_IMAGE) {286 psError(__func__,"Can not copy image because input image is not actually an image.");287 return NULL;288 }289 290 inDatatype = input->type.type;291 numRows = input->numRows;292 numCols = input->numCols;293 elements = numRows*numCols;294 elementSize = PSELEMTYPE_SIZEOF(inDatatype);295 296 if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) {297 psError(__func__,"Can not copy image to/from a void* matrix");298 return NULL;299 }300 301 output = psImageRecycle(output,numCols,numRows,type);302 303 // cover the trival case of copy of the same datatype.304 if (type == inDatatype) {305 memcpy(output->data.V[0],input->data.V[0],elementSize*elements);306 return output;307 }308 309 #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \310 ps##INTYPE *in = IN->data.INTYPE[0]; \311 ps##OUTTYPE *out = OUT->data.OUTTYPE[0]; \312 for (int e=0;e<ELEMENTS;e++) { \313 *(out++) = *(in++); \314 } \315 }316 317 #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \318 switch (inDatatype) { \319 case PS_TYPE_S8: \320 PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \321 break; \322 case PS_TYPE_S16: \323 PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \324 break; \325 case PS_TYPE_S32: \326 PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \327 break; \328 case PS_TYPE_S64: \329 PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \330 break; \331 case PS_TYPE_U8: \332 PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \333 break; \334 case PS_TYPE_U16: \335 PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \336 break; \337 case PS_TYPE_U32: \338 PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \339 break; \340 case PS_TYPE_U64: \341 PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \342 break; \343 case PS_TYPE_F32: \344 PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \345 break; \346 case PS_TYPE_F64: \347 PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \348 break; \349 case PS_TYPE_C32: \350 PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \351 break; \352 case PS_TYPE_C64: \353 PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \354 break; \355 default: \356 break; \357 }358 359 switch (type) {360 case PS_TYPE_S8:361 PSIMAGE_COPY_CASE(output,S8);362 break;363 case PS_TYPE_S16:364 PSIMAGE_COPY_CASE(output,S16);365 break;366 case PS_TYPE_S32:367 PSIMAGE_COPY_CASE(output,S32);368 break;369 case PS_TYPE_S64:370 PSIMAGE_COPY_CASE(output,S64);371 break;372 case PS_TYPE_U8:373 PSIMAGE_COPY_CASE(output,U8);374 break;375 case PS_TYPE_U16:376 PSIMAGE_COPY_CASE(output,U16);377 break;378 case PS_TYPE_U32:379 PSIMAGE_COPY_CASE(output,U32);380 break;381 case PS_TYPE_U64:382 PSIMAGE_COPY_CASE(output,U64);383 break;384 case PS_TYPE_F32:385 PSIMAGE_COPY_CASE(output,F32);386 break;387 case PS_TYPE_F64:388 PSIMAGE_COPY_CASE(output,F64);389 break;390 case PS_TYPE_C32:391 PSIMAGE_COPY_CASE(output,C32);392 break;393 case PS_TYPE_C64:394 PSIMAGE_COPY_CASE(output,C64);395 break;396 default:397 break;398 }399 return output;400 196 } 401 197 -
trunk/psLib/src/image/psImage.d
r1193 r1263 1 1 psImage.o psImage.d : psImage.c ../sysUtils/psMemory.h ../sysUtils/psAbort.h \ 2 ../sysUtils/psError.h psImage.h psType.h2 ../sysUtils/psError.h psImage.h ../collections/psType.h -
trunk/psLib/src/image/psImage.h
r1261 r1263 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-07-22 20: 09:04$13 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-07-22 20:42:22 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 98 98 ); 99 99 100 /** Create a subimage of the specified area.101 *102 * Uses psLib memory allocation functions to create an image based on a larger103 * one.104 *105 * @return psImage*: Pointer to psImage.106 *107 */108 psImage *psImageSubset(109 psImage *out, ///< Subimage to return, or NULL.110 psImage *image, ///< Parent image.111 unsigned int numCols, ///< Subimage width (<= image.nCols - col0).112 unsigned int numRows, ///< Subimage height (<= image.nRows - row0).113 unsigned int col0, ///< Subimage col-offset (0 <= col0 < nCol).114 unsigned int row0 ///< Subimage row-offset (0 <= row0 < nCol).115 );116 100 117 101 /** Frees all children of a psImage. … … 123 107 psImage* image 124 108 /**< psImage in which all children shall be deallocated */ 125 );126 127 /** Makes a copy of a psImage128 *129 * @return psImage* Copy of the input psImage. This may not be equal to the130 * output parameter131 *132 */133 psImage *psImageCopy(134 psImage* restrict output,135 /**< if not NULL, a psImage that could be recycled. If it can not be used,136 * it will be freed via psImageFree137 */138 const psImage *input,139 /**< the psImage to copy */140 psElemType type141 /**< the desired datatype of the returned copy */142 109 ); 143 110 -
trunk/psLib/src/image/psImageIO.d
r1073 r1263 1 psImageIO.o psImageIO.d : psImageIO.c psImageIO.h ../collections/psImage.h \2 ../ collections/psType.h ../sysUtils/psError.h ../sysUtils/psMemory.h1 psImageIO.o psImageIO.d : psImageIO.c psImageIO.h psImage.h ../collections/psType.h \ 2 ../sysUtils/psError.h ../sysUtils/psMemory.h -
trunk/psLib/src/image/psImageManip.c
r1260 r1263 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-07-22 20: 02:56$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-07-22 20:42:22 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include "psStats.h" 25 25 #include "psMemory.h" 26 #include "psImage Stats.h"26 #include "psImageExtraction.h" 27 27 28 28 bool getSpecifiedStatValue(const psStats* stats, double* value); -
trunk/psLib/src/image/psImageManip.d
r1252 r1263 1 psImageManip.o psImageManip.d : psImageManip.c ../sysUtils/psError.h \ 2 ../collections/psImage.h ../collections/psType.h psStats.h \ 3 ../collections/psVector.h ../sysUtils/psMemory.h psImageStats.h \ 4 psFunctions.h 1 psImageManip.o psImageManip.d : psImageManip.c ../sysUtils/psError.h psImage.h \ 2 ../collections/psType.h ../dataManip/psStats.h \ 3 ../collections/psVector.h ../sysUtils/psMemory.h psImageExtraction.h -
trunk/psLib/src/image/psImageManip.h
r1260 r1263 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-07-22 20: 02:56$12 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-07-22 20:42:22 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 20 20 #include "psImage.h" 21 #include "psImageStats.h"22 21 23 22 /// @addtogroup Image -
trunk/psLib/src/image/psImageStats.d
r1252 r1263 1 1 psImageStats.o psImageStats.d : psImageStats.c ../sysUtils/psMemory.h \ 2 2 ../collections/psVector.h ../collections/psType.h ../sysUtils/psTrace.h \ 3 ../sysUtils/psError.h ../sysUtils/psAbort.h psStats.h \4 ../collections/psImage.hpsFunctions.h psImageStats.h3 ../sysUtils/psError.h ../sysUtils/psAbort.h ../dataManip/psStats.h \ 4 psImage.h ../dataManip/psFunctions.h psImageStats.h -
trunk/psLib/src/mathtypes/psImage.c
r1261 r1263 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-07-22 20: 09:04$11 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-07-22 20:42:22 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 167 167 } 168 168 169 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,170 unsigned int numRows, unsigned int col0,171 unsigned int row0)172 {173 unsigned int elementSize; // size of image element in bytes174 unsigned int outputRowSize; // output row size in bytes175 unsigned int inputColOffset; // offset in bytes to first subset pixel in input row176 177 if (image == NULL || image->data.V == NULL) {178 psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");179 return NULL;180 }181 182 if (image->type.dimen != PS_DIMEN_IMAGE) {183 psError(__func__,"Can not subset image because input image is not an image.");184 return NULL;185 }186 187 if (numCols < 1 || numRows < 1) {188 psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",189 numCols, numRows);190 return NULL;191 }192 193 if (col0 >= image->numCols || row0 >= image->numRows) {194 psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel location.",195 col0,row0);196 return NULL;197 }198 199 /* validate subimage size */200 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {201 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "202 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,203 col0+numCols, row0, row0+numRows);204 return NULL;205 }206 207 208 elementSize = PSELEMTYPE_SIZEOF(image->type.type);209 210 out = psImageRecycle(out,numCols,numRows,image->type.type);211 212 // set the parent information into the child output image213 *(int*)&out->row0 = row0;214 *(int*)&out->col0 = col0;215 *(psImage**)&out->parent = (psImage*)image;216 217 // add output image as a child of the input image.218 image->nChildren++;219 image->children = (psImage **) psRealloc(image->children,220 image->nChildren * sizeof(psImage*) );221 image->children[image->nChildren-1] = out;222 223 inputColOffset = elementSize*col0;224 outputRowSize = elementSize*numCols;225 226 for (int row = 0; row < numRows; row++) {227 memcpy(out->data.V[row],image->data.U8[row0+row] + inputColOffset,228 outputRowSize);229 }230 231 return (out);232 }233 234 169 int psImageFreeChildren(psImage* image) 235 170 { … … 259 194 260 195 return numFreed; 261 }262 263 264 265 psImage *psImageCopy(psImage* restrict output, const psImage *input,266 psElemType type)267 {268 psElemType inDatatype;269 int elementSize;270 int elements;271 int numRows;272 int numCols;273 274 if (input == NULL || input->data.V == NULL) {275 psError(__func__,"Can not copy image because input image or its pixel buffer is NULL.");276 return NULL;277 }278 279 if (input == output) {280 psError(__func__,"Can not copy image because given input and output "281 "parameter reference the same psImage struct.");282 return NULL;283 }284 285 if (input->type.dimen != PS_DIMEN_IMAGE) {286 psError(__func__,"Can not copy image because input image is not actually an image.");287 return NULL;288 }289 290 inDatatype = input->type.type;291 numRows = input->numRows;292 numCols = input->numCols;293 elements = numRows*numCols;294 elementSize = PSELEMTYPE_SIZEOF(inDatatype);295 296 if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) {297 psError(__func__,"Can not copy image to/from a void* matrix");298 return NULL;299 }300 301 output = psImageRecycle(output,numCols,numRows,type);302 303 // cover the trival case of copy of the same datatype.304 if (type == inDatatype) {305 memcpy(output->data.V[0],input->data.V[0],elementSize*elements);306 return output;307 }308 309 #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \310 ps##INTYPE *in = IN->data.INTYPE[0]; \311 ps##OUTTYPE *out = OUT->data.OUTTYPE[0]; \312 for (int e=0;e<ELEMENTS;e++) { \313 *(out++) = *(in++); \314 } \315 }316 317 #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \318 switch (inDatatype) { \319 case PS_TYPE_S8: \320 PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \321 break; \322 case PS_TYPE_S16: \323 PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \324 break; \325 case PS_TYPE_S32: \326 PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \327 break; \328 case PS_TYPE_S64: \329 PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \330 break; \331 case PS_TYPE_U8: \332 PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \333 break; \334 case PS_TYPE_U16: \335 PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \336 break; \337 case PS_TYPE_U32: \338 PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \339 break; \340 case PS_TYPE_U64: \341 PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \342 break; \343 case PS_TYPE_F32: \344 PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \345 break; \346 case PS_TYPE_F64: \347 PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \348 break; \349 case PS_TYPE_C32: \350 PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \351 break; \352 case PS_TYPE_C64: \353 PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \354 break; \355 default: \356 break; \357 }358 359 switch (type) {360 case PS_TYPE_S8:361 PSIMAGE_COPY_CASE(output,S8);362 break;363 case PS_TYPE_S16:364 PSIMAGE_COPY_CASE(output,S16);365 break;366 case PS_TYPE_S32:367 PSIMAGE_COPY_CASE(output,S32);368 break;369 case PS_TYPE_S64:370 PSIMAGE_COPY_CASE(output,S64);371 break;372 case PS_TYPE_U8:373 PSIMAGE_COPY_CASE(output,U8);374 break;375 case PS_TYPE_U16:376 PSIMAGE_COPY_CASE(output,U16);377 break;378 case PS_TYPE_U32:379 PSIMAGE_COPY_CASE(output,U32);380 break;381 case PS_TYPE_U64:382 PSIMAGE_COPY_CASE(output,U64);383 break;384 case PS_TYPE_F32:385 PSIMAGE_COPY_CASE(output,F32);386 break;387 case PS_TYPE_F64:388 PSIMAGE_COPY_CASE(output,F64);389 break;390 case PS_TYPE_C32:391 PSIMAGE_COPY_CASE(output,C32);392 break;393 case PS_TYPE_C64:394 PSIMAGE_COPY_CASE(output,C64);395 break;396 default:397 break;398 }399 return output;400 196 } 401 197 -
trunk/psLib/src/mathtypes/psImage.h
r1261 r1263 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-07-22 20: 09:04$13 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-07-22 20:42:22 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 98 98 ); 99 99 100 /** Create a subimage of the specified area.101 *102 * Uses psLib memory allocation functions to create an image based on a larger103 * one.104 *105 * @return psImage*: Pointer to psImage.106 *107 */108 psImage *psImageSubset(109 psImage *out, ///< Subimage to return, or NULL.110 psImage *image, ///< Parent image.111 unsigned int numCols, ///< Subimage width (<= image.nCols - col0).112 unsigned int numRows, ///< Subimage height (<= image.nRows - row0).113 unsigned int col0, ///< Subimage col-offset (0 <= col0 < nCol).114 unsigned int row0 ///< Subimage row-offset (0 <= row0 < nCol).115 );116 100 117 101 /** Frees all children of a psImage. … … 123 107 psImage* image 124 108 /**< psImage in which all children shall be deallocated */ 125 );126 127 /** Makes a copy of a psImage128 *129 * @return psImage* Copy of the input psImage. This may not be equal to the130 * output parameter131 *132 */133 psImage *psImageCopy(134 psImage* restrict output,135 /**< if not NULL, a psImage that could be recycled. If it can not be used,136 * it will be freed via psImageFree137 */138 const psImage *input,139 /**< the psImage to copy */140 psElemType type141 /**< the desired datatype of the returned copy */142 109 ); 143 110
Note:
See TracChangeset
for help on using the changeset viewer.
