Changeset 1920 for trunk/psLib/src/image/psImageExtraction.c
- Timestamp:
- Sep 28, 2004, 1:26:49 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageExtraction.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
