Changeset 1613 for trunk/psLib/src/image/psImageExtraction.c
- Timestamp:
- Aug 24, 2004, 2:04:01 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/image/psImageExtraction.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/image/psImageExtraction.c
r1606 r1613 10 10 * @author Robert DeSonia, MHPCC 11 11 * 12 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2004-08-2 3 22:36:03$12 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2004-08-25 00:04:01 $ 14 14 * 15 15 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 93 93 94 94 return (out); 95 } 96 97 psImage* psImageSubsection(psImage* image, const char* section) 98 { 99 int x1; 100 int x2; 101 int y1; 102 int y2; 103 104 // section should be of the form '[x1:x2,y1:y2]' 105 if (section == NULL) { 106 psError(__func__,"The subsection string input can not be NULL."); 107 return NULL; 108 } 109 110 if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) { 111 psError(__func__,"The subsection string (%s) can not be parsed. " 112 "Needs to be of the form '[x1:x2,y1:y2]'", 113 section); 114 return NULL; 115 } 116 return psImageSubset(image,x2-x1+1,y2-y1+1,x1,y1); 117 } 118 119 psImage* psImageTrim(psImage* image, int x0, int x1, int y0, int y1) 120 { 121 if (image == NULL || image->data.V == NULL) { 122 psError(__func__, "Can not subset image because input image or its " 123 "pixel buffer is NULL."); 124 return NULL; 125 } 126 127 if (image->parent != NULL) { 128 psError(__func__, "Can not perform a trim on a child image."); 129 return NULL; 130 } 131 132 if (x0 < 0 || x1 < 0 || y0 < 0 || y1 < 0 || 133 x0 >= image->numCols || x1 >= image->numCols || 134 y0 >= image->numRows || y1 >= image->numRows || 135 x0 > x1 || y0 > y1 ) { 136 psError(__func__, "Can not subset image because specified region " 137 "[%d:%d,%d:%d] is not valid for image of size %dx%d.", 138 x0,x1,y0,y1,image->numCols,image->numRows); 139 return NULL; 140 } 141 142 psImageFreeChildren(image); 143 144 unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type); 145 unsigned int numCols = x1-x0+1; 146 unsigned int numRows = y1-y0+1; 147 unsigned int rowSize = elementSize*numCols; 148 unsigned int colOffset = elementSize * x0; 149 void* imageData = image->rawDataBuffer; 150 for (int row = y0; row < y1; row++) { 151 memmove(imageData,image->data.U8[row] + colOffset,rowSize); 152 imageData = (psU8*)imageData + rowSize; 153 } 154 155 *(unsigned int*)&image->numRows = numRows; 156 *(unsigned int*)&image->numCols = numCols; 157 158 // XXX: should I really resize the buffers? 159 image->data.V = psRealloc(image->data.V,sizeof(void*)*numRows); 160 image->rawDataBuffer = psRealloc(image->rawDataBuffer,rowSize*numRows); 161 162 image->data.V[0] = image->rawDataBuffer; 163 for (int r = 1; r < numRows; r++) { 164 image->data.U8[r] = image->data.U8[r-1] + rowSize; 165 } 166 167 return (image); 95 168 } 96 169
Note:
See TracChangeset
for help on using the changeset viewer.
