Changeset 692
- Timestamp:
- May 14, 2004, 12:39:58 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
image/psImage.c (modified) (4 diffs)
-
image/psImage.h (modified) (5 diffs)
-
mathtypes/psImage.c (modified) (4 diffs)
-
mathtypes/psImage.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r664 r692 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 3 20:03:35$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-14 22:39:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include "psMemory.h" 19 19 #include "psError.h" 20 #include "psVector.h"21 20 #include "psImage.h" 22 21 23 /******************************************************************************/ 24 /* DEFINE STATEMENTS */ 25 /******************************************************************************/ 26 27 // None 28 29 /******************************************************************************/ 30 /* TYPE DEFINITIONS */ 31 /******************************************************************************/ 32 33 // None 34 35 /*****************************************************************************/ 36 /* GLOBAL VARIABLES */ 37 /*****************************************************************************/ 38 39 // None 40 41 /*****************************************************************************/ 42 /* FILE STATIC VARIABLES */ 43 /*****************************************************************************/ 44 45 // None 46 47 /*****************************************************************************/ 48 /* FUNCTION IMPLEMENTATION - LOCAL */ 49 /*****************************************************************************/ 50 51 // None 22 #include <string.h> 52 23 53 24 /*****************************************************************************/ … … 55 26 /*****************************************************************************/ 56 27 57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type)28 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type) 58 29 { 59 30 int area = 0; 60 psElemType imageType = 0; 61 psDimen imageDim = 0; 62 int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes 31 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 63 32 int rowSize = numCols*elementSize; // row size in bytes. 64 33 65 imageType = type.type;66 imageDim = type.dimen;67 34 area = numCols*numRows; 68 69 if(imageDim != PS_DIMEN_IMAGE) {70 psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n",71 imageDim);72 return NULL;73 } else if(area <= 0) {74 psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n",75 numRows, numCols);76 return NULL;77 }78 35 79 36 psImage *image = (psImage *)psAlloc(sizeof(psImage)); 80 37 81 image->data.v[0] = psAlloc(area*elementSize); 38 if(area < 1) { 39 image->data.v[0] = NULL; 40 } else { 41 image->data.v[0] = psAlloc(area*elementSize); 82 42 83 for(int i = 1; i < numRows; i++) { 84 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 43 for(int i = 1; i < numRows; i++) { 44 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 45 } 85 46 } 86 47 87 image->col0 = 0; 88 image->row0 = 0; 89 image->numCols = numCols; 90 image->numRows = numRows; 91 image->type = type; 48 *(int*)&image->col0 = 0; 49 *(int*)&image->row0 = 0; 50 *(unsigned int*)&image->numCols = numCols; 51 *(unsigned int*)&image->numRows = numRows; 52 *(psDimen*)&image->type.dimen = PS_DIMEN_IMAGE; 53 *(psElemType*)&image->type.type = type; 92 54 image->parent = NULL; 93 55 image->nChildren = 0; … … 101 63 int i = 0; 102 64 int nChildren = 0; 103 psElemType imageType = 0; 104 psImage *children = NULL; 65 psImage **children = NULL; 105 66 106 67 if(image != NULL) { 107 imageType = image->type.type;108 68 nChildren = image->nChildren; 109 69 children = image->children; 70 71 for(i=0; i<nChildren; i++) { 72 psImageFree(children[i]); 73 } 110 74 111 75 psFree(image->data.v[0]); 112 76 psFree(image->data.v); 113 77 114 for(i=0; i<nChildren; i++) {115 psImageFree(&children[i]);116 }117 78 } 118 79 } 80 81 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols, 82 unsigned int numRows, unsigned int col0, unsigned int row0) 83 { 84 psElemType type; 85 unsigned int elementSize; // size of image element in bytes 86 unsigned int outputRowSize; // output row size in bytes 87 unsigned int inputColOffset; // offset in bytes to first subset pixel in input row 88 89 if (image == NULL) { 90 psError(__func__,"Can not subset image because input image is NULL."); 91 return NULL; 92 } 93 94 if (image->type.dimen != PS_DIMEN_IMAGE) { 95 psError(__func__,"Can not subset image because input image is not an image."); 96 return NULL; 97 } 98 99 /* validate subimage size */ 100 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) { 101 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, " 102 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0, 103 image->col0+numCols, image->row0, image->row0+numRows); 104 return NULL; 105 } 106 107 type = image->type.type; 108 elementSize = PSELEMTYPE_SIZEOF(type); 109 110 if (out == NULL) { 111 out = psImageAlloc(numCols,numRows,image->type.type); 112 } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) { 113 // sizes/type different, can't reuse the given image buffer 114 psImageFree(out); 115 out = psImageAlloc(numCols,numRows,image->type.type); 116 } 117 118 // set the parent information into the child output image 119 *(int*)&out->row0 = row0; 120 *(int*)&out->col0 = col0; 121 *(psImage**)&out->parent = (psImage*)image; 122 123 // add output image as a child of the input image. 124 image->nChildren++; 125 image->children = (psImage **) psRealloc(image->children,image->nChildren*sizeof(psImage *)); 126 image->children[image->nChildren-1] = out; 127 128 inputColOffset = elementSize*col0; 129 outputRowSize = elementSize*numCols; 130 131 for (int row = 0; row < numRows; row++) { 132 memcpy(out->data.v[row],image->data.i8[row0+row] + inputColOffset,outputRowSize); 133 } 134 135 return (out); 136 } -
trunk/psLib/src/image/psImage.h
r664 r692 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 3 20:03:35$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-14 22:39:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 16 17 17 #include <complex.h> 18 19 #include "psType.h" 18 20 19 21 /******************************************************************************/ … … 35 37 typedef struct psImage 36 38 { 37 psType type;///< Image data type and dimension.38 unsigned int numCols; ///< Number of rows in image39 unsigned int numRows; ///< Number of columns in image.40 int col0; ///< Rowposition relative to parent.41 int row0; ///< Columnposition relative to parent.39 const psType type; ///< Image data type and dimension. 40 const unsigned int numCols; ///< Number of columns in image 41 const unsigned int numRows; ///< Number of rows in image. 42 const int col0; ///< Column position relative to parent. 43 const int row0; ///< Row position relative to parent. 42 44 43 45 union { 44 void **v; ///< void pointer to data 45 uint8_t **ui8; ///< Pointers to char integer data. 46 int16_t **i16; ///< Pointers to short integer data. 47 int32_t **i32; ///< Pointers to integer data. 48 float **f32; ///< Pointers to floating point data. 49 complex float **c32; ///< Pointers to complex floating point data. 46 uint8_t **ui8; ///< unsigned 8-bit integer data. 47 uint16_t **ui16; ///< unsigned 16-bit integer data. 48 uint32_t **ui32; ///< unsigned 32-bit integer data. 49 int8_t **i8; ///< signed 8-bit integer data. 50 int16_t **i16; ///< signed 16-bit integer data. 51 int32_t **i32; ///< signed 32-bit integer data. 52 float **f32; ///< single-precision float data. 53 double **f64; ///< double-precision float data. 54 complex float **c32; ///< single-precision complex data. 55 void **v; ///< void pointers to data 50 56 } data; ///< Union for data types. 51 struct psImage *parent;///< Parent, if a subimage.57 const struct psImage *parent; ///< Parent, if a subimage. 52 58 int nChildren; ///< Number of subimages. 53 struct psImage *children;///< Children of this region.59 struct psImage** children; ///< Children of this region. 54 60 } 55 61 psImage; … … 70 76 unsigned int numCols, ///< Number of rows in image. 71 77 unsigned int numRows, ///< Number of columns in image. 72 psType type///< Type of data for image.78 const psElemType type ///< Type of data for image. 73 79 ); 74 80 … … 82 88 psImage *psImageSubset( 83 89 psImage *out, ///< Subimage to return, or NULL. 84 const psImage *image,///< Parent image.90 psImage *image, ///< Parent image. 85 91 unsigned int numCols, ///< Subimage width (<= image.nCols - col0). 86 92 unsigned int numRows, ///< Subimage height (<= image.nRows - row0). 87 int col0,///< Subimage col-offset (0 <= col0 < nCol).88 int row0///< Subimage row-offset (0 <= row0 < nCol).93 unsigned int col0, ///< Subimage col-offset (0 <= col0 < nCol). 94 unsigned int row0 ///< Subimage row-offset (0 <= row0 < nCol). 89 95 ); 90 96 -
trunk/psLib/src/mathtypes/psImage.c
r664 r692 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 3 20:03:35$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-14 22:39:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include "psMemory.h" 19 19 #include "psError.h" 20 #include "psVector.h"21 20 #include "psImage.h" 22 21 23 /******************************************************************************/ 24 /* DEFINE STATEMENTS */ 25 /******************************************************************************/ 26 27 // None 28 29 /******************************************************************************/ 30 /* TYPE DEFINITIONS */ 31 /******************************************************************************/ 32 33 // None 34 35 /*****************************************************************************/ 36 /* GLOBAL VARIABLES */ 37 /*****************************************************************************/ 38 39 // None 40 41 /*****************************************************************************/ 42 /* FILE STATIC VARIABLES */ 43 /*****************************************************************************/ 44 45 // None 46 47 /*****************************************************************************/ 48 /* FUNCTION IMPLEMENTATION - LOCAL */ 49 /*****************************************************************************/ 50 51 // None 22 #include <string.h> 52 23 53 24 /*****************************************************************************/ … … 55 26 /*****************************************************************************/ 56 27 57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type)28 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type) 58 29 { 59 30 int area = 0; 60 psElemType imageType = 0; 61 psDimen imageDim = 0; 62 int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes 31 int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes 63 32 int rowSize = numCols*elementSize; // row size in bytes. 64 33 65 imageType = type.type;66 imageDim = type.dimen;67 34 area = numCols*numRows; 68 69 if(imageDim != PS_DIMEN_IMAGE) {70 psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n",71 imageDim);72 return NULL;73 } else if(area <= 0) {74 psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n",75 numRows, numCols);76 return NULL;77 }78 35 79 36 psImage *image = (psImage *)psAlloc(sizeof(psImage)); 80 37 81 image->data.v[0] = psAlloc(area*elementSize); 38 if(area < 1) { 39 image->data.v[0] = NULL; 40 } else { 41 image->data.v[0] = psAlloc(area*elementSize); 82 42 83 for(int i = 1; i < numRows; i++) { 84 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 43 for(int i = 1; i < numRows; i++) { 44 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 45 } 85 46 } 86 47 87 image->col0 = 0; 88 image->row0 = 0; 89 image->numCols = numCols; 90 image->numRows = numRows; 91 image->type = type; 48 *(int*)&image->col0 = 0; 49 *(int*)&image->row0 = 0; 50 *(unsigned int*)&image->numCols = numCols; 51 *(unsigned int*)&image->numRows = numRows; 52 *(psDimen*)&image->type.dimen = PS_DIMEN_IMAGE; 53 *(psElemType*)&image->type.type = type; 92 54 image->parent = NULL; 93 55 image->nChildren = 0; … … 101 63 int i = 0; 102 64 int nChildren = 0; 103 psElemType imageType = 0; 104 psImage *children = NULL; 65 psImage **children = NULL; 105 66 106 67 if(image != NULL) { 107 imageType = image->type.type;108 68 nChildren = image->nChildren; 109 69 children = image->children; 70 71 for(i=0; i<nChildren; i++) { 72 psImageFree(children[i]); 73 } 110 74 111 75 psFree(image->data.v[0]); 112 76 psFree(image->data.v); 113 77 114 for(i=0; i<nChildren; i++) {115 psImageFree(&children[i]);116 }117 78 } 118 79 } 80 81 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols, 82 unsigned int numRows, unsigned int col0, unsigned int row0) 83 { 84 psElemType type; 85 unsigned int elementSize; // size of image element in bytes 86 unsigned int outputRowSize; // output row size in bytes 87 unsigned int inputColOffset; // offset in bytes to first subset pixel in input row 88 89 if (image == NULL) { 90 psError(__func__,"Can not subset image because input image is NULL."); 91 return NULL; 92 } 93 94 if (image->type.dimen != PS_DIMEN_IMAGE) { 95 psError(__func__,"Can not subset image because input image is not an image."); 96 return NULL; 97 } 98 99 /* validate subimage size */ 100 if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) { 101 psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, " 102 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0, 103 image->col0+numCols, image->row0, image->row0+numRows); 104 return NULL; 105 } 106 107 type = image->type.type; 108 elementSize = PSELEMTYPE_SIZEOF(type); 109 110 if (out == NULL) { 111 out = psImageAlloc(numCols,numRows,image->type.type); 112 } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) { 113 // sizes/type different, can't reuse the given image buffer 114 psImageFree(out); 115 out = psImageAlloc(numCols,numRows,image->type.type); 116 } 117 118 // set the parent information into the child output image 119 *(int*)&out->row0 = row0; 120 *(int*)&out->col0 = col0; 121 *(psImage**)&out->parent = (psImage*)image; 122 123 // add output image as a child of the input image. 124 image->nChildren++; 125 image->children = (psImage **) psRealloc(image->children,image->nChildren*sizeof(psImage *)); 126 image->children[image->nChildren-1] = out; 127 128 inputColOffset = elementSize*col0; 129 outputRowSize = elementSize*numCols; 130 131 for (int row = 0; row < numRows; row++) { 132 memcpy(out->data.v[row],image->data.i8[row0+row] + inputColOffset,outputRowSize); 133 } 134 135 return (out); 136 } -
trunk/psLib/src/mathtypes/psImage.h
r664 r692 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 3 20:03:35$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-14 22:39:58 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 16 17 17 #include <complex.h> 18 19 #include "psType.h" 18 20 19 21 /******************************************************************************/ … … 35 37 typedef struct psImage 36 38 { 37 psType type;///< Image data type and dimension.38 unsigned int numCols; ///< Number of rows in image39 unsigned int numRows; ///< Number of columns in image.40 int col0; ///< Rowposition relative to parent.41 int row0; ///< Columnposition relative to parent.39 const psType type; ///< Image data type and dimension. 40 const unsigned int numCols; ///< Number of columns in image 41 const unsigned int numRows; ///< Number of rows in image. 42 const int col0; ///< Column position relative to parent. 43 const int row0; ///< Row position relative to parent. 42 44 43 45 union { 44 void **v; ///< void pointer to data 45 uint8_t **ui8; ///< Pointers to char integer data. 46 int16_t **i16; ///< Pointers to short integer data. 47 int32_t **i32; ///< Pointers to integer data. 48 float **f32; ///< Pointers to floating point data. 49 complex float **c32; ///< Pointers to complex floating point data. 46 uint8_t **ui8; ///< unsigned 8-bit integer data. 47 uint16_t **ui16; ///< unsigned 16-bit integer data. 48 uint32_t **ui32; ///< unsigned 32-bit integer data. 49 int8_t **i8; ///< signed 8-bit integer data. 50 int16_t **i16; ///< signed 16-bit integer data. 51 int32_t **i32; ///< signed 32-bit integer data. 52 float **f32; ///< single-precision float data. 53 double **f64; ///< double-precision float data. 54 complex float **c32; ///< single-precision complex data. 55 void **v; ///< void pointers to data 50 56 } data; ///< Union for data types. 51 struct psImage *parent;///< Parent, if a subimage.57 const struct psImage *parent; ///< Parent, if a subimage. 52 58 int nChildren; ///< Number of subimages. 53 struct psImage *children;///< Children of this region.59 struct psImage** children; ///< Children of this region. 54 60 } 55 61 psImage; … … 70 76 unsigned int numCols, ///< Number of rows in image. 71 77 unsigned int numRows, ///< Number of columns in image. 72 psType type///< Type of data for image.78 const psElemType type ///< Type of data for image. 73 79 ); 74 80 … … 82 88 psImage *psImageSubset( 83 89 psImage *out, ///< Subimage to return, or NULL. 84 const psImage *image,///< Parent image.90 psImage *image, ///< Parent image. 85 91 unsigned int numCols, ///< Subimage width (<= image.nCols - col0). 86 92 unsigned int numRows, ///< Subimage height (<= image.nRows - row0). 87 int col0,///< Subimage col-offset (0 <= col0 < nCol).88 int row0///< Subimage row-offset (0 <= row0 < nCol).93 unsigned int col0, ///< Subimage col-offset (0 <= col0 < nCol). 94 unsigned int row0 ///< Subimage row-offset (0 <= row0 < nCol). 89 95 ); 90 96
Note:
See TracChangeset
for help on using the changeset viewer.
