Changeset 1920 for trunk/psLib/src/image
- Timestamp:
- Sep 28, 2004, 1:26:49 PM (22 years ago)
- Location:
- trunk/psLib/src/image
- Files:
-
- 4 edited
-
psImage.c (modified) (6 diffs)
-
psImage.h (modified) (3 diffs)
-
psImageExtraction.c (modified) (8 diffs)
-
psImageExtraction.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImage.c
r1897 r1920 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.4 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-09-2 5 02:06:12$12 * @version $Revision: 1.47 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-28 23:26:48 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 68 68 *(psElemType* ) & image->type.type = type; 69 69 image->parent = NULL; 70 image->nChildren = 0;71 70 image->children = NULL; 72 71 … … 81 80 82 81 if (image->type.type == PS_TYPE_PTR) { 83 // 2-D array of pointers -- must 84 // dereference 82 // 2-D array of pointers -- must dereference elements 85 83 unsigned int oldNumRows = image->numRows; 86 84 unsigned int oldNumCols = image->numCols; … … 95 93 } 96 94 95 if (image->parent != NULL) { 96 psArrayRemove(image->parent->children,image); 97 image->parent = NULL; 98 } 99 97 100 psImageFreeChildren(image); 98 101 99 102 psFree(image->rawDataBuffer); 100 103 psFree(image->data.V); 101 image->data.V = NULL;102 104 } 103 105 … … 164 166 int psImageFreeChildren(psImage* image) 165 167 { 166 int i = 0;167 int nChildren = 0;168 psImage* *children = NULL;169 168 int numFreed = 0; 170 169 … … 173 172 } 174 173 175 nChildren = image->nChildren; 176 children = image->children; 177 178 for (i = 0; i < nChildren; i++) { 179 if (children[i] != NULL) { 180 numFreed++; 181 psFree(children[i]); 174 if (image->children != NULL) { 175 psImage** children = (psImage**)image->children->data; 176 numFreed = image->children->n; 177 178 // orphan the children first 179 // (so psFree doesn't try to modify the parent's children array while I'm using it) 180 for (int i=0;i<numFreed;i++) { 181 children[i]->parent = NULL; 182 182 } 183 } 184 psFree(children); 185 186 image->nChildren = 0; 187 image->children = NULL; 183 184 psFree(image->children); 185 image->children = NULL; 186 } 188 187 189 188 return numFreed; -
trunk/psLib/src/image/psImage.h
r1897 r1920 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.3 7$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-09-2 5 02:06:12$13 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-09-28 23:26:48 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 22 22 23 23 #include "psType.h" 24 #include "psArray.h" 24 25 25 26 /// @addtogroup Image … … 67 68 } data; ///< Union for data types. 68 69 const struct psImage* parent; ///< Parent, if a subimage. 69 int nChildren; ///< Number of subimages. 70 struct psImage* *children; ///< Children of this region. 70 psArray* children; ///< Children of this region. 71 71 72 72 void* rawDataBuffer; -
trunk/psLib/src/image/psImageExtraction.c
r1918 r1920 1 2 1 /** @file psImageExtraction.c 3 *4 * @brief Contains basic image extraction operations, as specified in the5 * PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure6 * Manipulation".7 *8 * @ingroup Image9 *10 * @author Robert DeSonia, MHPCC11 *12 * @version $Revision: 1.16$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-09-28 02:27:58 $14 *15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii16 *17 */2 * 3 * @brief Contains basic image extraction operations, as specified in the 4 * PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure 5 * Manipulation". 6 * 7 * @ingroup Image 8 * 9 * @author Robert DeSonia, MHPCC 10 * 11 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-28 23:26:48 $ 13 * 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii 15 * 16 */ 18 17 19 18 #include <string.h> … … 25 24 #include "psImageErrors.h" 26 25 27 psImage* psImageSubset(psImage* image, 28 int col0, 29 int row0, 30 int col1, 31 int row1) 26 27 psImage* imageSubset(psImage* out, 28 psImage* image, 29 int col0, 30 int row0, 31 int col1, 32 int row1) 32 33 { 33 psImage* out;34 34 unsigned int elementSize; // size of image element in bytes 35 35 unsigned int inputColOffset; // offset in bytes to first subset pixel in input row … … 70 70 } 71 71 int numRows = row1-row0; 72 int numCols = col1- row0;72 int numCols = col1-col0; 73 73 74 74 elementSize = PSELEMTYPE_SIZEOF(image->type.type); 75 75 76 out = psAlloc(sizeof(psImage)); 76 if (image->parent != NULL) { // if this is a child, we need to start working with parent. 77 col0 += image->col0; 78 col1 += image->col0; 79 row0 += image->row0; 80 row1 += image->row0; 81 image = (psImage*)image->parent; 82 } 83 84 // increment the raw data buffer before freeing anything in the 'out' 85 void* rawData = psMemIncrRefCounter(image->rawDataBuffer); 86 87 if (out != NULL) { 88 // if a child, need to orphan (disassociate from parent) first 89 if (out->parent != NULL) { 90 psArrayRemove(out->parent->children,out); // remove from parent's knowledge 91 out->parent = NULL; // break link to parent 92 } 93 94 psFree(out->rawDataBuffer); // free the previous data reference 95 } else { 96 out = psAlloc(sizeof(psImage)); 97 out->data.V = NULL; 98 } 99 100 out->data.V = psRealloc(out->data.V,sizeof(void*)*numRows); // resize row pointer array 77 101 *(psType*)&out->type = image->type; 78 102 *(unsigned int*)&out->numCols = numCols; … … 81 105 *(int*)&out->col0 = col0; 82 106 out->parent = image; 83 out->nChildren = 0;84 107 out->children = NULL; 85 out->rawDataBuffer = psMemIncrRefCounter(image->rawDataBuffer); 86 out->data.V = psAlloc(sizeof(void*)*numRows); 108 out->rawDataBuffer = rawData; 87 109 88 110 // set the new psImage's deallocator to the same as the input image … … 94 116 } 95 117 96 // add output image as a child of the input 97 // image. 98 image->nChildren++; 99 image->children = (psImage**) psRealloc(image->children, image->nChildren * sizeof(psImage* )); 100 image->children[image->nChildren - 1] = out; 118 // add output image as a child of the input image. 119 int n = 0; 120 psArray* children = image->children; 121 if (children == NULL) { 122 children = psArrayAlloc(16); // start with a reasonable size for growth 123 } else if (children->nalloc == children->n) { // full? 124 n = children->n; 125 children = psArrayRealloc(children,n*2); // double the array size 126 } else { 127 n = children->n; 128 } 129 children->data[n] = out; 130 children->n = n+1; 131 image->children = children; // push back any change (esp. if children==NULL before) 101 132 102 133 return (out); 134 } 135 136 psImage* psImageSubset(psImage* image, 137 int col0, 138 int row0, 139 int col1, 140 int row1) 141 { 142 return imageSubset(NULL,image,col0,row0,col1,row1); 103 143 } 104 144 … … 126 166 return NULL; 127 167 } 128 return psImageSubset(image,x1,y1,x2,y2);168 return imageSubset(NULL,image,x1,y1,x2,y2); 129 169 } 130 170 131 psImage* psImageTrim(psImage* image, int x0, int x1, int y0, int y1)171 psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1) 132 172 { 133 173 if (image == NULL || image->data.V == NULL) { … … 139 179 140 180 if (image->parent != NULL) { 141 psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim", 142 PS_ERR_BAD_PARAMETER_NULL, true, 143 PS_ERRORTEXT_psImage_NOT_PARENT); 144 return NULL; 181 return imageSubset(image, 182 (psImage*)image->parent, 183 x0+image->col0, 184 y0+image->row0, 185 x1+image->col0, 186 y1+image->row0); 145 187 } 146 188 … … 904 946 int n = buffer[r]->n; 905 947 if (n == buffer[r]->nalloc) { // in case buffers already full, expand 906 buffer[r] = psVectorRealloc( n*2, buffer[r]);948 buffer[r] = psVectorRealloc(buffer[r], n*2); 907 949 if (bufferMask[r] != NULL) { 908 bufferMask[r] = psVectorRealloc( n*2, bufferMask[r]);950 bufferMask[r] = psVectorRealloc(bufferMask[r], n*2); 909 951 } 910 952 } -
trunk/psLib/src/image/psImageExtraction.h
r1918 r1920 10 10 * @author Robert DeSonia, MHPCC 11 11 * 12 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-09-28 02:27:58 $12 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-09-28 23:26:48 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 76 76 * 77 77 * Trim the specified image in-place, which involves shuffling the pixels 78 * around in memory. The pixels in the region [x0:x1,y0:y1] (inclusive) 79 * shall consist the output image. 80 * 81 * N.b., An image that has a parent image will be orphaned from the parent 82 * upon trimming. Any children of the trimmed image will also be obliterated, 78 * around in memory. The pixels in the region [col0:col1,row0:row1] shall consist 79 * the output image. The column col1 and row row1 are NOT included in the range. 80 * In the event that x1 or y1 are non-positive, they shall be interpreted as 81 * being relative to the size of the parent image in that dimension. 82 * 83 * If the entire specified subimage is not contained within the parent 84 * image, an error results and the return value will be NULL. 85 * 86 * N.B. If the input psImage is a child of another psImage, no pixel data 87 * will be trimmed, rather it equivalent to calling psImageSubset. If the input 88 * psImage is, however, a parent psImage, any children will be obliterated, 83 89 * i.e., freed from memory. 84 90 * … … 87 93 psImage* psImageTrim( 88 94 psImage* image, ///< image to trim 89 int x0,///< column of trim region's left boundary90 int x1, ///< column of trim region's rightboundary91 int y0, ///< row of trim region's lowerboundary92 int y1///< row of trim region's upper boundary95 int col0, ///< column of trim region's left boundary 96 int row0, ///< row of trim region's lower boundary 97 int col1, ///< column of trim region's right boundary 98 int row1 ///< row of trim region's upper boundary 93 99 ); 94 100
Note:
See TracChangeset
for help on using the changeset viewer.
