Changeset 3959 for trunk/psLib/src/collections/psPixels.c
- Timestamp:
- May 18, 2005, 11:38:19 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psPixels.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psPixels.c
r3761 r3959 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-0 4-23 00:10:19 $9 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-05-18 21:38:19 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include "psPixels.h" 19 19 #include "psMemory.h" 20 21 #include "psError.h" 22 #include "psCollectionsErrors.h" 20 23 21 24 typedef int(*qsortCompareFcn)(const void *, const void *); … … 66 69 psMemSetDeallocator(out, (psFreeFcn)pixelsFree); 67 70 68 return NULL;71 return out; 69 72 } 70 73 … … 75 78 } 76 79 77 pixels->data = psRealloc(pixels->data, sizeof(psPixelCoord)*size); 80 if (size > 0) { 81 pixels->data = psRealloc(pixels->data, sizeof(psPixelCoord)*size); 82 } else { 83 psFree(pixels->data); 84 pixels->data = NULL; 85 } 78 86 79 87 pixels->nalloc = size; … … 88 96 { 89 97 if (in == NULL) { 98 psFree(out); 90 99 return NULL; 91 100 } … … 93 102 out = psPixelsRealloc(out, in->n); 94 103 95 memcpy( in->data,out->data, in->n*sizeof(psPixelCoord));104 memcpy(out->data,in->data, in->n*sizeof(psPixelCoord)); 96 105 out->n = in->n; 97 106 … … 99 108 } 100 109 101 psImage *psPixelsToMask(psImage *out, const psPixels *pixels, const psRegion *region, unsigned int maskVal)110 psImage *psPixelsToMask(psImage *out, const psPixels *pixels, const psRegion region, unsigned int maskVal) 102 111 { 103 112 // check that the input pixel vector is valid 104 113 if (pixels == NULL) { 105 // XXX: Error message 114 psError(PS_ERR_BAD_PARAMETER_NULL, true, 115 PS_ERRORTEXT_psPixels_NULL); 106 116 psFree(out); 107 117 return NULL; … … 109 119 psPixelCoord* data = pixels->data; 110 120 if (data == NULL) { 111 // XXX: Error message 112 psFree(out); 113 return NULL; 114 } 115 116 // check if the input region is valid 117 if (region == NULL) { 118 // XXX: Error message 119 psFree(out); 120 return NULL; 121 } 122 int x0 = region->x0; 123 int x1 = region->x1; 124 int y0 = region->y0; 125 int y1 = region->y1; 121 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 122 PS_ERRORTEXT_psPixels_DATA_NULL); 123 psFree(out); 124 return NULL; 125 } 126 127 int x0 = region.x0; 128 int x1 = region.x1; 129 int y0 = region.y0; 130 int y1 = region.y1; 126 131 127 132 // determine the output image size … … 129 134 int numCols = y1-y0; 130 135 if (numRows < 1 || numCols < 1) { 131 // XXX: Error message 136 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 137 PS_ERRORTEXT_psPixels_REGION_INVALID, 138 x0,x1,y0,y1); 132 139 psFree(out); 133 140 return NULL; … … 137 144 out = psImageRecycle(out, numCols, numRows, PS_TYPE_MASK); 138 145 if (out == NULL) { 139 // XXX: Error message 146 psError(PS_ERR_UNKNOWN, false, 147 PS_ERRORTEXT_psPixels_FAILED_IMAGE_CREATE, 148 numCols, numRows); 140 149 return NULL; 141 150 } … … 144 153 145 154 // initialize image to all zeros 146 int columnByteSize = sizeof( PS_TYPE_MASK)*numCols;155 int columnByteSize = sizeof(psMaskType)*numCols; 147 156 for (int row = 0; row < numRows; row++) { 148 157 memset(out->data.U8[row],0,columnByteSize); … … 166 175 } 167 176 168 psPixels *psMaskToPixels(psPixels *out, const psImage *mask, unsigned int maskVal)177 psPixels* psPixelsFromMask(psPixels* out, const psImage* mask, unsigned int maskVal) 169 178 { 170 179 if (mask == NULL) { 171 // XXX: Error message 180 psError(PS_ERR_BAD_PARAMETER_NULL, true, 181 PS_ERRORTEXT_psPixels_MASK_NULL); 172 182 psFree(out); 173 183 return NULL; 174 184 } 175 185 if (mask->type.type != PS_TYPE_MASK) { 176 // XXX: Error message 186 char* typeStr; 187 PS_TYPE_NAME(typeStr,mask->type.type); 188 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 189 PS_ERRORTEXT_psPixels_MASK_TYPE, 190 typeStr); 177 191 psFree(out); 178 192 return NULL; … … 204 218 psMaskType* maskRow = mask->data.PS_TYPE_MASK_DATA[row]; 205 219 for (int col=0; col<numCols; col++) { 206 if ( (maskRow[col] |maskVal) != 0 ) {220 if ( (maskRow[col] & maskVal) != 0 ) { 207 221 // check the vector sizes, and expand if necessary 208 if (nalloc >= numPixels) {222 if (nalloc <= numPixels) { 209 223 out = psPixelsRealloc(out, 2*nalloc); 210 224 nalloc = out->nalloc; … … 218 232 } 219 233 } 234 out->n = numPixels; 220 235 221 236 return out; … … 225 240 { 226 241 if (pixels == NULL) { 227 // XXX: Error message 228 return NULL; 229 } 242 psError(PS_ERR_BAD_PARAMETER_NULL, true, 243 PS_ERRORTEXT_psPixels_NULL); 244 return out; 245 } 246 230 247 int pixelsN = pixels->n; 231 248 psPixelCoord* pixelsData = pixels->data; … … 243 260 244 261 // sort the OUT array to help in searching for duplicates later 245 qsort(outData, sizeof(psPixelCoord), outN,262 qsort(outData, outN, sizeof(psPixelCoord), 246 263 (qsortCompareFcn)comparePixelCoord); 247 264 … … 251 268 for (int n = 0; n < pixelsN; n++) { 252 269 pCoord = pixelsData[n]; 253 if (bsearch(&pCoord, outData, sizeof(psPixelCoord), outN,270 if (bsearch(&pCoord, outData, outN, sizeof(psPixelCoord), 254 271 (qsortCompareFcn)comparePixelCoord) == NULL) { 255 272 // no match in OUT array of this value … … 261 278 return out; 262 279 } 280 281 bool p_psPixelsPrint (FILE *fd, psPixels* pixels, const char *name) 282 { 283 284 fprintf (fd, "psPixels: %s\n", name); 285 286 if (pixels == NULL) { 287 fprintf(fd,"NULL\n\n"); 288 return true; 289 } 290 291 int n = pixels->n; 292 psPixelCoord* data = pixels->data; 293 294 if (data == NULL || n == 0) { 295 fprintf(fd,"EMPTY\n\n"); 296 return true; 297 } 298 299 for (int i = 0; i < n; i++) { 300 fprintf (fd, "(%d,%d)\n", data[i].x, data[i].y); 301 } 302 fprintf (fd, "\n"); 303 return (true); 304 }
Note:
See TracChangeset
for help on using the changeset viewer.
