Index: /trunk/psLib/test/collections/tst_psPixels.c
===================================================================
--- /trunk/psLib/test/collections/tst_psPixels.c	(revision 3974)
+++ /trunk/psLib/test/collections/tst_psPixels.c	(revision 3974)
@@ -0,0 +1,491 @@
+/** @file  tst_psPixels.c
+ *
+ *  @brief Contains the tests for psPixels.[ch]
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $
+ *           $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-05-19 02:57:03 $
+ *
+ *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include "psTest.h"
+#include "pslib_strict.h"
+
+static psS32 testPixelsAlloc(void);
+static psS32 testPixelsRealloc(void);
+static psS32 testPixelsCopy(void);
+static int testPixelsToMask(void);
+static int testPixelsFromMask(void);
+static int testPixelsConcatenate(void);
+
+testDescription tests[] = {
+                              {testPixelsAlloc,860,"psPixelsAlloc",0,false},
+                              {testPixelsRealloc,861,"psPixelsRealloc",0,false},
+                              {testPixelsCopy,862,"psPixelsCopy",0,false},
+                              {testPixelsToMask,863,"psPixelsToMask",0,false},
+                              {testPixelsFromMask,864,"psPixelsFromMask",0,false},
+                              {testPixelsConcatenate,865,"psPixelsConcatenate",0,false},
+                              {NULL}
+                          };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetLevel(PS_LOG_INFO);
+
+    if ( ! runTestSuite(stderr,"psPixels",tests,argc,argv) ) {
+        psError(PS_ERR_UNKNOWN,true,"One or more tests failed");
+        return 1;
+    }
+    return 0;
+}
+
+psS32 testPixelsAlloc(void)
+{
+
+    psPixels* p0 = psPixelsAlloc(0);
+
+    if (p0 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to allocate a zero-sized psPixels");
+        return 1;
+    }
+    if (p0->data != NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set data to NULL for a zero-sized psPixels");
+        return 2;
+    }
+    if (p0->n != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set n = 0");
+        return 3;
+    }
+    if (p0->nalloc != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set nalloc = 0");
+        return 4;
+    }
+
+    psPixels* p1 = psPixelsAlloc(1);
+
+    if (p1 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to allocate a one-sized psPixels");
+        return 11;
+    }
+    if (p1->data == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to allocate data for a one-sized psPixels");
+        return 12;
+    }
+    p1->data[0].x = 1;
+    p1->data[0].y = 2;
+
+    if (p1->n != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set n = 0");
+        return 13;
+    }
+    if (p1->nalloc != 1) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set nalloc = 1 (%d)",
+                p1->nalloc);
+        return 14;
+    }
+
+    psPixels* p2 = psPixelsAlloc(10);
+
+    if (p2 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to allocate a one-sized psPixels");
+        return 11;
+    }
+    if (p2->data == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to allocate data for a one-sized psPixels");
+        return 12;
+    }
+    for (int i = 0; i < 10; i++) {
+        p2->data[i].x = i;
+        p2->data[i].y = 100+i;
+    }
+
+    if (p2->n != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set n = 0");
+        return 13;
+    }
+    if (p2->nalloc != 10) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsAlloc failed to set nalloc = 1 (%d)",
+                p2->nalloc);
+        return 14;
+    }
+
+
+    psFree(p2);
+    psFree(p1);
+    psFree(p0);
+
+    return 0;
+}
+
+psS32 testPixelsRealloc(void)
+{
+
+    // first, tests that reallocing a NULL just allocates
+    psPixels* p0 = psPixelsRealloc(NULL,10);
+
+    if (p0 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to allocate a zero-sized psPixels");
+        return 1;
+    }
+    if (p0->data == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set data to NULL for a zero-sized psPixels");
+        return 2;
+    }
+    if (p0->n != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set n = 0");
+        return 3;
+    }
+    if (p0->nalloc != 10) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set nalloc = 10");
+        return 4;
+    }
+    for (int i = 0; i < 10; i++) {
+        p0->data[i].x = i;
+        p0->data[i].y = 100+i;
+    }
+    p0->n = 10;
+
+    psPixels* p1 = psPixelsRealloc(p0, 20);
+
+    if (p1 != p0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to return a resized input psPixels");
+        return 11;
+    }
+    if (p1->data == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set data to non-NULL");
+        return 12;
+    }
+    if (p1->n != 10) {
+        psError(PS_ERR_UNKNOWN, true,
+                "resizing up didn't preserve the size");
+        return 13;
+    }
+    if (p1->nalloc != 20) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set nalloc = 0");
+        return 14;
+    }
+    for (int i = 0; i < 10; i++) {
+        if (p0->data[i].x != i || p0->data[i].y != 100+i) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "The value of pixel %d was not preserved (%d,%d) vs (%d,%d).",
+                    i, p0->data[i].x, p0->data[i].y, i, 100+i);
+            return 15;
+        }
+    }
+    for (int i = 10; i < 20; i++) {
+        p1->data[i].x = i;
+        p1->data[i].y = 100+i;
+    }
+    p1->n = 20;
+
+
+    psPixels* p2 = psPixelsRealloc(p1,5);
+
+    if (p2 != p1) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc didn't return input psPixels.");
+        return 21;
+    }
+    if (p2->data == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to allocate data");
+        return 22;
+    }
+
+    if (p2->n != 5) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set n=nalloc after shrinking");
+        return 23;
+    }
+    if (p2->nalloc != 5) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set nalloc properly");
+        return 24;
+    }
+
+    psPixels* p3 = psPixelsRealloc(p2,0);
+
+    if (p3 != p2) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc didn't return input psPixels.");
+        return 31;
+    }
+    if (p3->data != NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to deallocate data when size=0");
+        return 32;
+    }
+
+    if (p3->n != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set n=nalloc after shrinking");
+        return 33;
+    }
+    if (p3->nalloc != 0) {
+        psError(PS_ERR_UNKNOWN, true,
+                "psPixelsRealloc failed to set nalloc properly");
+        return 34;
+    }
+
+    psFree(p3);
+
+    return 0;
+}
+
+psS32 testPixelsCopy(void)
+{
+    psPixels* in1 = psPixelsAlloc(10);
+
+    for (int i = 0; i < 10; i++) {
+        in1->data[i].x = i;
+        in1->data[i].y = 100+i;
+    }
+    in1->n = 10;
+
+    psPixels* out1 = psPixelsCopy(NULL, in1);
+    if (out1 == in1) {
+        psError(PS_ERR_UNKNOWN, true,
+                "output == input?");
+        return 1;
+    }
+    if (out1 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "output == NULL?");
+        return 2;
+    }
+
+    if (out1->n != in1->n) {
+        psError(PS_ERR_UNKNOWN, true,
+                "out->n != in->n");
+        return 3;
+    }
+    for (int i = 0; i < out1->n; i++) {
+        if (out1->data[i].x != in1->data[i].x || out1->data[i].y != in1->data[i].y) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "failed to copy the values correctly at index %d", i);
+            return 4;
+        }
+    }
+
+    // now test what happens when copying a 0-length list.
+    psPixels* in2 = psPixelsAlloc(0);
+    psPixels* out2 = psPixelsCopy(out1, in2);
+    if (out2 != out1) {
+        psError(PS_ERR_UNKNOWN, true,
+                "failed to recycle.");
+        return 10;
+    }
+    if (out2->n != in2->n) {
+        psError(PS_ERR_UNKNOWN, true,
+                "failed to set size when copying 0-length pixel list.");
+        return 11;
+    }
+
+
+    out2 = psPixelsCopy(out2,NULL);
+    if (out2 != NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "Copying a NULL should create a NULL.");
+        return 20;
+    }
+
+    psFree(in1);
+    psFree(in2);
+
+    return 0;
+}
+
+int testPixelsToMask(void)
+{
+    // create a pixel list for
+    psPixels* pixels = psPixelsAlloc(10);
+    for (int i = 0; i < 10; i++) {
+        pixels->data[i].x = i;
+        pixels->data[i].y = i;
+    }
+    pixels->n = 10;
+
+    psImage* mask = psPixelsToMask(NULL,pixels,(psRegion) {
+                                       0,10,0,10
+                                   }
+                                   ,1);
+
+    if (mask == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "Resulting mask was null.");
+        return 1;
+    }
+    if (mask->type.type != PS_TYPE_MASK) {
+        psError(PS_ERR_UNKNOWN, true,
+                "mask type was not PS_TYPE_MASK.");
+        return 2;
+    }
+
+    for (int row=0;row<10;row++) {
+        psMaskType* rowData = mask->data.PS_TYPE_MASK_DATA[row];
+        for (int col=0;col<10;col++) {
+            if ( (col==row && rowData[col] != 1) ||
+                    (col!=row && rowData[col] != 0) ) {
+                psError(PS_ERR_UNKNOWN,true,
+                        "Mask has unexpected value, %d, at (%d,%d)",
+                        rowData[col], col, row);
+                return 10;
+            }
+        }
+    }
+
+    // test when input psPixels is NULL.
+    mask = psPixelsToMask(mask, NULL, (psRegion) {
+                              0,10,0,10
+                          }
+                          ,1);
+    if (mask != NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "Resulting mask was not null though input psPixels was NULL.");
+        return 20;
+    }
+
+
+    psFree(mask);
+    psFree(pixels);
+
+    return 0;
+}
+
+int testPixelsFromMask(void)
+{
+    const int numRows = 10;
+    const int numCols = 20;
+    psImage* mask = psImageAlloc(numCols,numRows,PS_TYPE_MASK);
+    for (int row=0;row<numRows;row++) {
+        for (int col=0;col<numCols;col++) {
+            mask->data.PS_TYPE_MASK_DATA[row][col] = (row*2 == col) ? 1 : 0;
+        }
+    }
+
+    psPixels* pixels = psPixelsFromMask(NULL, mask, 1);
+
+    if (pixels == NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "resulting psPixels was NULL?");
+        return 1;
+    }
+
+    if (pixels->n != numRows) {
+        psError(PS_ERR_UNKNOWN, false,
+                "wrong number of pixels in list.  Got %d, should be %d.",
+                pixels->n, numRows);
+        return 2;
+    }
+
+    for (int i = 0; i < pixels->n; i++) {
+        if (mask->data.PS_TYPE_MASK_DATA[pixels->data[i].y][pixels->data[i].x] != 1) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "Item in psPixels list (%d,%d) didn't coorespond to a masked value in image",
+                    pixels->data[i].x, pixels->data[i].y);
+            return 3;
+        }
+    }
+
+    pixels = psPixelsFromMask(pixels, NULL, 1);
+
+    if (pixels != NULL) {
+        psError(PS_ERR_UNKNOWN, false,
+                "given a NULL image, got a non-NULL mask?");
+        return 4;
+    }
+
+    psFree(mask);
+
+    return 0;
+}
+
+int testPixelsConcatenate(void)
+{
+    // create a pixel list for
+    psPixels* pixels = psPixelsAlloc(10);
+    psPixels* pixels1 = psPixelsAlloc(10);
+    for (int i = 0; i < 10; i++) {
+        pixels->data[i].x = i;
+        pixels->data[i].y = i;
+        if (i%2) {
+            pixels1->data[i].x = -i;
+        } else {
+            pixels1->data[i].x = i;
+        }
+        pixels1->data[i].y = i;
+    }
+    pixels->n = 10;
+    pixels1->n = 10;
+    p_psPixelsPrint(stdout, pixels, "pixels");
+    p_psPixelsPrint(stdout, pixels1, "pixels1");
+
+    psPixels* pixels2 = psPixelsConcatenate(NULL, pixels);
+    p_psPixelsPrint(stdout, pixels2, "pixels2");
+    if (pixels2 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,
+                "pixels2 == NULL?");
+        return 1;
+    }
+    if (pixels == pixels2) {
+        psError(PS_ERR_UNKNOWN, true,
+                "pixels == pixels2?  Should have made a copy.");
+        return 2;
+    }
+    if (pixels2->n != pixels->n) {
+        psError(PS_ERR_UNKNOWN, true,
+                "pixels2->n != pixels->n");
+        return 3;
+    }
+    for (int i = 0; i < pixels2->n; i++) {
+        if (pixels2->data[i].x != pixels->data[i].x || pixels2->data[i].y != pixels->data[i].y) {
+            psError(PS_ERR_UNKNOWN, true,
+                    "failed to copy the values correctly at index %d", i);
+            return 4;
+        }
+    }
+
+    // add pixels that are half unique.
+    psPixels* pixels3 = psPixelsConcatenate(pixels2, pixels1);
+    p_psPixelsPrint(stdout, pixels3, "pixels3");
+    if (pixels3 != pixels2) {
+        psError(PS_ERR_UNKNOWN, true,
+                "return expected to be the out parameter.");
+        return 10;
+    }
+    if (pixels3->n != 15) {
+        psError(PS_ERR_UNKNOWN, true,
+                "pixels3->n != 15, == %d", pixels3->n);
+        return 11;
+    }
+
+
+    psFree(pixels3);
+    psFree(pixels1);
+    psFree(pixels);
+
+    return 0;
+}
+
Index: /trunk/psLib/test/collections/verified/tst_psPixels.stderr
===================================================================
--- /trunk/psLib/test/collections/verified/tst_psPixels.stderr	(revision 3974)
+++ /trunk/psLib/test/collections/verified/tst_psPixels.stderr	(revision 3974)
@@ -0,0 +1,58 @@
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsAlloc}                                    *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psPixels{psPixelsAlloc} | tst_psPixels.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsRealloc}                                  *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psPixels{psPixelsRealloc} | tst_psPixels.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsCopy}                                     *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psPixels{psPixelsCopy} | tst_psPixels.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsToMask}                                   *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|E|psPixelsToMask (FILE:LINENO)
+    Input psPixels can not be NULL.
+
+---> TESTPOINT PASSED (psPixels{psPixelsToMask} | tst_psPixels.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsFromMask}                                 *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|E|psPixelsFromMask (FILE:LINENO)
+    Specified mask can not be NULL.
+
+---> TESTPOINT PASSED (psPixels{psPixelsFromMask} | tst_psPixels.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psPixels.c                                             *
+*            TestPoint: psPixels{psPixelsConcatenate}                              *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psPixels{psPixelsConcatenate} | tst_psPixels.c)
+
