Changeset 664
- Timestamp:
- May 13, 2004, 10:03:35 AM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
image/psImage.c (modified) (5 diffs)
-
image/psImage.h (modified) (6 diffs)
-
mathtypes/psImage.c (modified) (5 diffs)
-
mathtypes/psImage.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r649 r664 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 2 19:46:52$9 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-13 20:03:35 $ 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 "ps Array.h"20 #include "psVector.h" 21 21 #include "psImage.h" 22 22 … … 55 55 /*****************************************************************************/ 56 56 57 psImage *psImageAlloc( int nCols, int nRows, psType type)57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type) 58 58 { 59 59 int area = 0; 60 60 psElemType imageType = 0; 61 61 psDimen imageDim = 0; 62 int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes 63 int rowSize = numCols*elementSize; // row size in bytes. 62 64 63 65 imageType = type.type; 64 66 imageDim = type.dimen; 65 area = n Cols*nRows;67 area = numCols*numRows; 66 68 67 69 if(imageDim != PS_DIMEN_IMAGE) { 68 psError(__func__, " : Line %d - Image dimensionality not PS_DIMEN_IMAGE=3. Dimensionality: %d\n",69 __LINE__,imageDim);70 psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n", 71 imageDim); 70 72 return NULL; 71 73 } else if(area <= 0) { 72 psError(__func__, " : Line %d - Invalid value for number of rows or columns. nRows: %d nCols: %d\n",73 __LINE__, nRows, nCols);74 psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n", 75 numRows, numCols); 74 76 return NULL; 75 77 } … … 77 79 psImage *image = (psImage *)psAlloc(sizeof(psImage)); 78 80 79 switch (type.type) { 80 case PS_TYPE_CHAR: 81 image->rows.rows_c = (char **)psAlloc(ny*sizeof(char *)); 82 image->rows.rows_c[0] = (char *)psAlloc(area*sizeof(char)); 83 for(int i = 1; i < ny; i++) { 84 image->rows.rows_c[i] = &image->rows.rows_c[0][i*nx]; 85 } 86 break; 87 case PS_TYPE_SHORT: 88 image->rows.rows_s = (short **)psAlloc(ny*sizeof(short *)); 89 image->rows.rows_s[0] = (short *)psAlloc(area*sizeof(short)); 90 for(int i = 1; i < ny; i++) { 91 image->rows.rows_s[i] = &image->rows.rows_s[0][i*nx]; 92 } 93 break; 94 case PS_TYPE_INT: 95 image->rows.rows_i = (int **)psAlloc(ny*sizeof(int *)); 96 image->rows.rows_i[0] = (int *)psAlloc(area*sizeof(int)); 97 for(int i = 1; i < ny; i++) { 98 image->rows.rows_i[i] = &image->rows.rows_i[0][i*nx]; 99 } 100 break; 101 case PS_TYPE_LONG: 102 image->rows.rows_l = (long **)psAlloc(ny*sizeof(long *)); 103 image->rows.rows_l[0] = (long *)psAlloc(area*sizeof(long)); 104 for(int i = 1; i < ny; i++) { 105 image->rows.rows_l[i] = &image->rows.rows_l[0][i*nx]; 106 } 107 break; 108 case PS_TYPE_UCHAR: 109 image->rows.rows_uc = (unsigned char **)psAlloc(ny*sizeof(unsigned char *)); 110 image->rows.rows_uc[0] = (unsigned char *)psAlloc(area*sizeof(unsigned char)); 111 for(int i = 1; i < ny; i++) { 112 image->rows.rows_uc[i] = &image->rows.rows_uc[0][i*nx]; 113 } 114 break; 115 case PS_TYPE_USHORT: 116 image->rows.rows_us = (unsigned short **)psAlloc(ny*sizeof(unsigned short *)); 117 image->rows.rows_us[0] = (unsigned short *)psAlloc(area*sizeof(unsigned short)); 118 for(int i = 1; i < ny; i++) { 119 image->rows.rows_us[i] = &image->rows.rows_us[0][i*nx]; 120 } 121 break; 122 case PS_TYPE_UINT: 123 image->rows.rows_ui = (unsigned int **)psAlloc(ny*sizeof(unsigned int *)); 124 image->rows.rows_ui[0] = (unsigned int *)psAlloc(area*sizeof(unsigned int)); 125 for(int i = 1; i < ny; i++) { 126 image->rows.rows_ui[i] = &image->rows.rows_ui[0][i*nx]; 127 } 128 break; 129 case PS_TYPE_ULONG: 130 image->rows.rows_ul = (unsigned long **)psAlloc(ny*sizeof(unsigned long *)); 131 image->rows.rows_ul[0] = (unsigned long *)psAlloc(area*sizeof(unsigned long)); 132 for(int i = 1; i < ny; i++) { 133 image->rows.rows_ul[i] = &image->rows.rows_ul[0][i*nx]; 134 } 135 break; 81 image->data.v[0] = psAlloc(area*elementSize); 82 83 for(int i = 1; i < numRows; i++) { 84 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 136 85 } 137 86 138 image->col s0 = 0;139 image->row s0 = 0;140 image->n Cols = nCols;141 image->n Rows = nRows;87 image->col0 = 0; 88 image->row0 = 0; 89 image->numCols = numCols; 90 image->numRows = numRows; 142 91 image->type = type; 143 92 image->parent = NULL; … … 160 109 children = image->children; 161 110 162 switch(imageType) { 163 case PS_TYPE_SHORT: 164 psFree(image->rows.rows_s); 165 break; 166 case PS_TYPE_INT: 167 psFree(image->rows.rows_i); 168 break; 169 case PS_TYPE_LONG: 170 psFree(image->rows.rows_l); 171 break; 172 case PS_TYPE_USHORT: 173 psFree(image->rows.rows_us); 174 break; 175 case PS_TYPE_UINT: 176 psFree(image->rows.rows_ui); 177 break; 178 case PS_TYPE_ULONG: 179 psFree(image->rows.rows_ul); 180 break; 181 case PS_TYPE_FLOAT: 182 psFree(image->rows.rows_f); 183 break; 184 case PS_TYPE_DOUBLE: 185 psFree(image->rows.rows_d); 186 break; 187 case PS_TYPE_COMPLEX: 188 psFree(image->rows.rows_cf); 189 break; 190 case PS_TYPE_OTHER: 191 psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__); 192 break; 193 default: 194 psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType); 195 } 111 psFree(image->data.v[0]); 112 psFree(image->data.v); 196 113 197 114 for(i=0; i<nChildren; i++) { -
trunk/psLib/src/image/psImage.h
r649 r664 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 2 19:46:52$9 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-13 20:03:35 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 typedef struct psImage 36 36 { 37 psType type; ///< Image data type and dimension.38 int nCols;///< Number of rows in image39 int nRows;///< Number of columns in image.40 int col0; ///< Row position relative to parent.41 int row0; ///< Column position relative to parent.37 psType type; ///< Image data type and dimension. 38 unsigned int numCols; ///< Number of rows in image 39 unsigned int numRows; ///< Number of columns in image. 40 int col0; ///< Row position relative to parent. 41 int row0; ///< Column position relative to parent. 42 42 43 43 union { 44 char **rowsC ///< Pointers to char integer data. 45 short **rowsS; ///< Pointers to short integer data. 46 int **rowsI; ///< Pointers to integer data. 47 long **rowsL ; ///< Pointers to long integer data. 48 unsigned char **rowsUC; ///< Pointers to unsigned char integer data. 49 unsigned short **rowsUS; ///< Pointers to unsigned short integer data. 50 unsigned int **rowsUI; ///< Pointers to unsigned integer data. 51 unsigned long **rowsUL; ///< Pointers to unsigned long integer data. 52 float **rowsF; ///< Pointers to floating point data. 53 double **rowsD; ///< Pointers to double precision data. 54 complex float **rowsCF; ///< Pointers to complex floating point data. 55 } rows; ///< Union for data types. 56 struct psImage *parent; ///< Parent, if a subimage. 57 int nChildren; ///< Number of subimages. 58 struct psImage *children; ///< Children of this region. 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. 50 } data; ///< Union for data types. 51 struct psImage *parent; ///< Parent, if a subimage. 52 int nChildren; ///< Number of subimages. 53 struct psImage *children; ///< Children of this region. 59 54 } 60 55 psImage; … … 67 62 /** Create an image of the specified size and type. 68 63 * 69 * Uses psLib memory allocation functions to create an image struct of the specified size and type. 64 * Uses psLib memory allocation functions to create an image struct of the specified size and type. 70 65 * 71 66 * @return psImage*: Pointer to psImage. … … 73 68 */ 74 69 psImage *psImageAlloc( 75 int nCols,///< Number of rows in image.76 int nRows,///< Number of columns in image.77 psType type ///< Type of data for image.70 unsigned int numCols, ///< Number of rows in image. 71 unsigned int numRows, ///< Number of columns in image. 72 psType type ///< Type of data for image. 78 73 ); 79 74 80 75 /** Create a subimage of the specified area. 81 76 * 82 * Uses psLib memory allocation functions to create an image based on a larger one. 77 * Uses psLib memory allocation functions to create an image based on a larger one. 83 78 * 84 79 * @return psImage*: Pointer to psImage. … … 86 81 */ 87 82 psImage *psImageSubset( 88 psImage *out, ///< Subimage to return, or NULL.89 const psImage *image, ///< Parent image.90 int nCols,///< Subimage width (<= image.nCols - col0).91 int nRows,///< Subimage height (<= image.nRows - row0).92 int col0, ///< Subimage col-offset (0 <= col0 < nCol).93 int row0 ///< Subimage row-offset (0 <= row0 < nCol).83 psImage *out, ///< Subimage to return, or NULL. 84 const psImage *image, ///< Parent image. 85 unsigned int numCols, ///< Subimage width (<= image.nCols - col0). 86 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). 94 89 ); 95 90 96 91 /** Destroy the specified image. 97 92 * 98 * Uses psLib memory deallocation functions to free an image and any existing children. 93 * Uses psLib memory deallocation functions to free an image and any existing children. 99 94 * 100 95 * @return psImage*: Pointer to psImage. … … 102 97 */ 103 98 void psImageFree( 104 psImage *restrict image ///< Free psImage99 psImage *restrict image ///< Free psImage 105 100 ); 106 101 -
trunk/psLib/src/mathtypes/psImage.c
r649 r664 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 2 19:46:52$9 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-13 20:03:35 $ 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 "ps Array.h"20 #include "psVector.h" 21 21 #include "psImage.h" 22 22 … … 55 55 /*****************************************************************************/ 56 56 57 psImage *psImageAlloc( int nCols, int nRows, psType type)57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type) 58 58 { 59 59 int area = 0; 60 60 psElemType imageType = 0; 61 61 psDimen imageDim = 0; 62 int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes 63 int rowSize = numCols*elementSize; // row size in bytes. 62 64 63 65 imageType = type.type; 64 66 imageDim = type.dimen; 65 area = n Cols*nRows;67 area = numCols*numRows; 66 68 67 69 if(imageDim != PS_DIMEN_IMAGE) { 68 psError(__func__, " : Line %d - Image dimensionality not PS_DIMEN_IMAGE=3. Dimensionality: %d\n",69 __LINE__,imageDim);70 psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n", 71 imageDim); 70 72 return NULL; 71 73 } else if(area <= 0) { 72 psError(__func__, " : Line %d - Invalid value for number of rows or columns. nRows: %d nCols: %d\n",73 __LINE__, nRows, nCols);74 psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n", 75 numRows, numCols); 74 76 return NULL; 75 77 } … … 77 79 psImage *image = (psImage *)psAlloc(sizeof(psImage)); 78 80 79 switch (type.type) { 80 case PS_TYPE_CHAR: 81 image->rows.rows_c = (char **)psAlloc(ny*sizeof(char *)); 82 image->rows.rows_c[0] = (char *)psAlloc(area*sizeof(char)); 83 for(int i = 1; i < ny; i++) { 84 image->rows.rows_c[i] = &image->rows.rows_c[0][i*nx]; 85 } 86 break; 87 case PS_TYPE_SHORT: 88 image->rows.rows_s = (short **)psAlloc(ny*sizeof(short *)); 89 image->rows.rows_s[0] = (short *)psAlloc(area*sizeof(short)); 90 for(int i = 1; i < ny; i++) { 91 image->rows.rows_s[i] = &image->rows.rows_s[0][i*nx]; 92 } 93 break; 94 case PS_TYPE_INT: 95 image->rows.rows_i = (int **)psAlloc(ny*sizeof(int *)); 96 image->rows.rows_i[0] = (int *)psAlloc(area*sizeof(int)); 97 for(int i = 1; i < ny; i++) { 98 image->rows.rows_i[i] = &image->rows.rows_i[0][i*nx]; 99 } 100 break; 101 case PS_TYPE_LONG: 102 image->rows.rows_l = (long **)psAlloc(ny*sizeof(long *)); 103 image->rows.rows_l[0] = (long *)psAlloc(area*sizeof(long)); 104 for(int i = 1; i < ny; i++) { 105 image->rows.rows_l[i] = &image->rows.rows_l[0][i*nx]; 106 } 107 break; 108 case PS_TYPE_UCHAR: 109 image->rows.rows_uc = (unsigned char **)psAlloc(ny*sizeof(unsigned char *)); 110 image->rows.rows_uc[0] = (unsigned char *)psAlloc(area*sizeof(unsigned char)); 111 for(int i = 1; i < ny; i++) { 112 image->rows.rows_uc[i] = &image->rows.rows_uc[0][i*nx]; 113 } 114 break; 115 case PS_TYPE_USHORT: 116 image->rows.rows_us = (unsigned short **)psAlloc(ny*sizeof(unsigned short *)); 117 image->rows.rows_us[0] = (unsigned short *)psAlloc(area*sizeof(unsigned short)); 118 for(int i = 1; i < ny; i++) { 119 image->rows.rows_us[i] = &image->rows.rows_us[0][i*nx]; 120 } 121 break; 122 case PS_TYPE_UINT: 123 image->rows.rows_ui = (unsigned int **)psAlloc(ny*sizeof(unsigned int *)); 124 image->rows.rows_ui[0] = (unsigned int *)psAlloc(area*sizeof(unsigned int)); 125 for(int i = 1; i < ny; i++) { 126 image->rows.rows_ui[i] = &image->rows.rows_ui[0][i*nx]; 127 } 128 break; 129 case PS_TYPE_ULONG: 130 image->rows.rows_ul = (unsigned long **)psAlloc(ny*sizeof(unsigned long *)); 131 image->rows.rows_ul[0] = (unsigned long *)psAlloc(area*sizeof(unsigned long)); 132 for(int i = 1; i < ny; i++) { 133 image->rows.rows_ul[i] = &image->rows.rows_ul[0][i*nx]; 134 } 135 break; 81 image->data.v[0] = psAlloc(area*elementSize); 82 83 for(int i = 1; i < numRows; i++) { 84 image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize); 136 85 } 137 86 138 image->col s0 = 0;139 image->row s0 = 0;140 image->n Cols = nCols;141 image->n Rows = nRows;87 image->col0 = 0; 88 image->row0 = 0; 89 image->numCols = numCols; 90 image->numRows = numRows; 142 91 image->type = type; 143 92 image->parent = NULL; … … 160 109 children = image->children; 161 110 162 switch(imageType) { 163 case PS_TYPE_SHORT: 164 psFree(image->rows.rows_s); 165 break; 166 case PS_TYPE_INT: 167 psFree(image->rows.rows_i); 168 break; 169 case PS_TYPE_LONG: 170 psFree(image->rows.rows_l); 171 break; 172 case PS_TYPE_USHORT: 173 psFree(image->rows.rows_us); 174 break; 175 case PS_TYPE_UINT: 176 psFree(image->rows.rows_ui); 177 break; 178 case PS_TYPE_ULONG: 179 psFree(image->rows.rows_ul); 180 break; 181 case PS_TYPE_FLOAT: 182 psFree(image->rows.rows_f); 183 break; 184 case PS_TYPE_DOUBLE: 185 psFree(image->rows.rows_d); 186 break; 187 case PS_TYPE_COMPLEX: 188 psFree(image->rows.rows_cf); 189 break; 190 case PS_TYPE_OTHER: 191 psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__); 192 break; 193 default: 194 psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType); 195 } 111 psFree(image->data.v[0]); 112 psFree(image->data.v); 196 113 197 114 for(i=0; i<nChildren; i++) { -
trunk/psLib/src/mathtypes/psImage.h
r649 r664 7 7 * @author Ross Harman, MHPCC 8 8 * 9 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $10 * @date $Date: 2004-05-1 2 19:46:52$9 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2004-05-13 20:03:35 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 35 35 typedef struct psImage 36 36 { 37 psType type; ///< Image data type and dimension.38 int nCols;///< Number of rows in image39 int nRows;///< Number of columns in image.40 int col0; ///< Row position relative to parent.41 int row0; ///< Column position relative to parent.37 psType type; ///< Image data type and dimension. 38 unsigned int numCols; ///< Number of rows in image 39 unsigned int numRows; ///< Number of columns in image. 40 int col0; ///< Row position relative to parent. 41 int row0; ///< Column position relative to parent. 42 42 43 43 union { 44 char **rowsC ///< Pointers to char integer data. 45 short **rowsS; ///< Pointers to short integer data. 46 int **rowsI; ///< Pointers to integer data. 47 long **rowsL ; ///< Pointers to long integer data. 48 unsigned char **rowsUC; ///< Pointers to unsigned char integer data. 49 unsigned short **rowsUS; ///< Pointers to unsigned short integer data. 50 unsigned int **rowsUI; ///< Pointers to unsigned integer data. 51 unsigned long **rowsUL; ///< Pointers to unsigned long integer data. 52 float **rowsF; ///< Pointers to floating point data. 53 double **rowsD; ///< Pointers to double precision data. 54 complex float **rowsCF; ///< Pointers to complex floating point data. 55 } rows; ///< Union for data types. 56 struct psImage *parent; ///< Parent, if a subimage. 57 int nChildren; ///< Number of subimages. 58 struct psImage *children; ///< Children of this region. 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. 50 } data; ///< Union for data types. 51 struct psImage *parent; ///< Parent, if a subimage. 52 int nChildren; ///< Number of subimages. 53 struct psImage *children; ///< Children of this region. 59 54 } 60 55 psImage; … … 67 62 /** Create an image of the specified size and type. 68 63 * 69 * Uses psLib memory allocation functions to create an image struct of the specified size and type. 64 * Uses psLib memory allocation functions to create an image struct of the specified size and type. 70 65 * 71 66 * @return psImage*: Pointer to psImage. … … 73 68 */ 74 69 psImage *psImageAlloc( 75 int nCols,///< Number of rows in image.76 int nRows,///< Number of columns in image.77 psType type ///< Type of data for image.70 unsigned int numCols, ///< Number of rows in image. 71 unsigned int numRows, ///< Number of columns in image. 72 psType type ///< Type of data for image. 78 73 ); 79 74 80 75 /** Create a subimage of the specified area. 81 76 * 82 * Uses psLib memory allocation functions to create an image based on a larger one. 77 * Uses psLib memory allocation functions to create an image based on a larger one. 83 78 * 84 79 * @return psImage*: Pointer to psImage. … … 86 81 */ 87 82 psImage *psImageSubset( 88 psImage *out, ///< Subimage to return, or NULL.89 const psImage *image, ///< Parent image.90 int nCols,///< Subimage width (<= image.nCols - col0).91 int nRows,///< Subimage height (<= image.nRows - row0).92 int col0, ///< Subimage col-offset (0 <= col0 < nCol).93 int row0 ///< Subimage row-offset (0 <= row0 < nCol).83 psImage *out, ///< Subimage to return, or NULL. 84 const psImage *image, ///< Parent image. 85 unsigned int numCols, ///< Subimage width (<= image.nCols - col0). 86 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). 94 89 ); 95 90 96 91 /** Destroy the specified image. 97 92 * 98 * Uses psLib memory deallocation functions to free an image and any existing children. 93 * Uses psLib memory deallocation functions to free an image and any existing children. 99 94 * 100 95 * @return psImage*: Pointer to psImage. … … 102 97 */ 103 98 void psImageFree( 104 psImage *restrict image ///< Free psImage99 psImage *restrict image ///< Free psImage 105 100 ); 106 101
Note:
See TracChangeset
for help on using the changeset viewer.
