IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2005, 11:38:19 AM (21 years ago)
Author:
desonia
Message:

changes given implementation of tests for the psPixels functions.

File:
1 edited

Legend:

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

    r3761 r3959  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-04-23 00:10:19 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-05-18 21:38:19 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psPixels.h"
    1919#include "psMemory.h"
     20
     21#include "psError.h"
     22#include "psCollectionsErrors.h"
    2023
    2124typedef int(*qsortCompareFcn)(const void *, const void *);
     
    6669    psMemSetDeallocator(out, (psFreeFcn)pixelsFree);
    6770
    68     return NULL;
     71    return out;
    6972}
    7073
     
    7578    }
    7679
    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    }
    7886
    7987    pixels->nalloc = size;
     
    8896{
    8997    if (in == NULL) {
     98        psFree(out);
    9099        return NULL;
    91100    }
     
    93102    out = psPixelsRealloc(out, in->n);
    94103
    95     memcpy(in->data,out->data, in->n*sizeof(psPixelCoord));
     104    memcpy(out->data,in->data, in->n*sizeof(psPixelCoord));
    96105    out->n = in->n;
    97106
     
    99108}
    100109
    101 psImage *psPixelsToMask(psImage *out, const psPixels *pixels, const psRegion *region, unsigned int maskVal)
     110psImage *psPixelsToMask(psImage *out, const psPixels *pixels, const psRegion region, unsigned int maskVal)
    102111{
    103112    // check that the input pixel vector is valid
    104113    if (pixels == NULL) {
    105         // XXX: Error message
     114        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     115                PS_ERRORTEXT_psPixels_NULL);
    106116        psFree(out);
    107117        return NULL;
     
    109119    psPixelCoord* data = pixels->data;
    110120    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;
    126131
    127132    // determine the output image size
     
    129134    int numCols = y1-y0;
    130135    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);
    132139        psFree(out);
    133140        return NULL;
     
    137144    out = psImageRecycle(out, numCols, numRows, PS_TYPE_MASK);
    138145    if (out == NULL) {
    139         // XXX: Error message
     146        psError(PS_ERR_UNKNOWN, false,
     147                PS_ERRORTEXT_psPixels_FAILED_IMAGE_CREATE,
     148                numCols, numRows);
    140149        return NULL;
    141150    }
     
    144153
    145154    // initialize image to all zeros
    146     int columnByteSize = sizeof(PS_TYPE_MASK)*numCols;
     155    int columnByteSize = sizeof(psMaskType)*numCols;
    147156    for (int row = 0; row < numRows; row++) {
    148157        memset(out->data.U8[row],0,columnByteSize);
     
    166175}
    167176
    168 psPixels *psMaskToPixels(psPixels *out, const psImage *mask, unsigned int maskVal)
     177psPixels* psPixelsFromMask(psPixels* out, const psImage* mask, unsigned int maskVal)
    169178{
    170179    if (mask == NULL) {
    171         // XXX: Error message
     180        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     181                PS_ERRORTEXT_psPixels_MASK_NULL);
    172182        psFree(out);
    173183        return NULL;
    174184    }
    175185    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);
    177191        psFree(out);
    178192        return NULL;
     
    204218        psMaskType* maskRow = mask->data.PS_TYPE_MASK_DATA[row];
    205219        for (int col=0; col<numCols; col++) {
    206             if ( (maskRow[col] | maskVal) != 0 ) {
     220            if ( (maskRow[col] & maskVal) != 0 ) {
    207221                // check the vector sizes, and expand if necessary
    208                 if (nalloc >= numPixels) {
     222                if (nalloc <= numPixels) {
    209223                    out = psPixelsRealloc(out, 2*nalloc);
    210224                    nalloc = out->nalloc;
     
    218232        }
    219233    }
     234    out->n = numPixels;
    220235
    221236    return out;
     
    225240{
    226241    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
    230247    int pixelsN = pixels->n;
    231248    psPixelCoord* pixelsData = pixels->data;
     
    243260
    244261    // sort the OUT array to help in searching for duplicates later
    245     qsort(outData, sizeof(psPixelCoord), outN,
     262    qsort(outData, outN, sizeof(psPixelCoord),
    246263          (qsortCompareFcn)comparePixelCoord);
    247264
     
    251268    for (int n = 0; n < pixelsN; n++) {
    252269        pCoord = pixelsData[n];
    253         if (bsearch(&pCoord, outData, sizeof(psPixelCoord), outN,
     270        if (bsearch(&pCoord, outData, outN, sizeof(psPixelCoord),
    254271                    (qsortCompareFcn)comparePixelCoord) == NULL) {
    255272            // no match in OUT array of this value
     
    261278    return out;
    262279}
     280
     281bool 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.