IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16873


Ignore:
Timestamp:
Mar 7, 2008, 12:16:38 PM (18 years ago)
Author:
Paul Price
Message:

Rework psPixelsConcatenate so that duplicates don't expand the size of the output unnecessarily.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psPixels.c

    r16679 r16873  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-02-27 02:18:14 $
     9 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-03-07 22:16:38 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    251251    PS_ASSERT_PIXELS_NON_NULL(pixels, NULL);
    252252
    253     long pixelsN = pixels->n;
    254     psPixelCoord* pixelsData = pixels->data;
    255 
    256     if (out == NULL) {
    257         // simple copy pixels
    258         out = psPixelsCopy(out,pixels);
     253    long pixelsN = pixels->n;           // Size of input
     254    psPixelCoord* pixelsData = pixels->data; // Dereference input
     255
     256    if (!out) {
     257        // Simply copy pixels
     258        out = psPixelsCopy(out, pixels);
    259259        return out;
    260260    }
    261261
    262     // make sure the out is large enough to fit the result
    263     long outN = out->n;
    264     out = psPixelsRealloc(out,outN + pixelsN);
    265     psPixelCoord* outData = out->data;
     262    long outN = out->n;                 // Size of output
     263    psPixelCoord* outData = out->data;  // Dereference output
    266264
    267265    // sort the OUT array to help in searching for duplicates later
    268     qsort(outData, outN, sizeof(psPixelCoord),
    269           (qsortCompareFunc)comparePixelCoord);
     266    qsort(outData, outN, sizeof(psPixelCoord), (qsortCompareFunc)comparePixelCoord);
    270267
    271268    // add non-duplicate values in pixels to out
    272     psPixelCoord pCoord;
    273     long end = outN;
    274269    for (long n = 0; n < pixelsN; n++) {
    275         pCoord = pixelsData[n];
    276         if (bsearch(&pCoord, outData, outN, sizeof(psPixelCoord),
    277                     (qsortCompareFunc)comparePixelCoord) == NULL) {
     270        psPixelCoord pCoord = pixelsData[n]; // Coordinate of interest
     271        if (!bsearch(&pCoord, outData, outN, sizeof(psPixelCoord), (qsortCompareFunc)comparePixelCoord)) {
    278272            // no match in OUT array of this value
    279             outData[end++] = pCoord;
     273            psPixelsAdd(out, 0, pCoord.x, pCoord.y);
    280274        }
    281275    }
    282     out->n = end; // set number of elements to reflect added data
    283276
    284277    return out;
Note: See TracChangeset for help on using the changeset viewer.