Index: trunk/psLib/test/image/tst_psImageFFT.c
===================================================================
--- trunk/psLib/test/image/tst_psImageFFT.c	(revision 2273)
+++ trunk/psLib/test/image/tst_psImageFFT.c	(revision 2714)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-04 01:05:00 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-15 03:57:03 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,22 +34,10 @@
 
 testDescription tests[] = {
-                              {
-                                  testImageFFT,632,"psImageFFT",0,false
-                              },
-                              {
-                                  testImageRealImaginary,633,"psImageRealImaginary",0,false
-                              },
-                              {
-                                  testImageComplex,634,"psImageComplex",0,false
-                              },
-                              {
-                                  testImageConjugate,635,"psImageConjugate",0,false
-                              },
-                              {
-                                  testImagePowerSpectrum,636,"psImagePowerSpectrum",0,false
-                              },
-                              {
-                                  NULL
-                              }
+                              {testImageFFT,632,"psImageFFT",0,false},
+                              {testImageRealImaginary,633,"psImageRealImaginary",0,false},
+                              {testImageComplex,634,"psImageComplex",0,false},
+                              {testImageConjugate,635,"psImageConjugate",0,false},
+                              {testImagePowerSpectrum,636,"psImagePowerSpectrum",0,false},
+                              {NULL}
                           };
 
@@ -214,4 +202,11 @@
     psImage* img2 = NULL;
     psImage* img3 = NULL;
+    psImage* c64Img = NULL;
+    psImage* c64Img2 = NULL;
+    psImage* c64Img3 = NULL;
+    psImage* ncImg = NULL;
+    psImage* ncImg2 = NULL;
+    psImage* ncImg3 = NULL;
+
     psU32 m = 128;
     psU32 n = 64;
@@ -271,4 +266,107 @@
     psFree(img3);
 
+    /*
+    1. create a C64 complex vector with distinctly different real and imaginary parts.
+    2. call psImageReal and psImageImaginary
+    3. compare results to the real/imaginary components of input
+    */
+
+    // 1. create a C64 complex vector with distinctly different real and imaginary parts.
+    GENIMAGE(c64Img,m,n,C64, row + I * col);
+
+    // 2. call psImageReal and psImageImaginary
+    c64Img2 = psImageReal(c64Img2,c64Img);
+    if (c64Img2 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,"psImageReal returned a NULL?");
+        return 1;
+    }
+    if (c64Img2->type.type != PS_TYPE_F64) {
+        psError(PS_ERR_UNKNOWN, true,"psImageReal returned a wrong type (%d)?",
+                img2->type.type);
+        return 2;
+    }
+
+    c64Img3 = psImageImaginary(c64Img3,c64Img);
+    if (c64Img3 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,"psImageImaginary returned a NULL?");
+        return 3;
+    }
+    if (c64Img3->type.type != PS_TYPE_F64) {
+        psError(PS_ERR_UNKNOWN, true,"psImageImaginary returned a wrong type (%d)?",
+                c64Img3->type.type);
+        return 4;
+    }
+
+    // 3. compare results to the real/imaginary components of input
+    for (psU32 row=0;row<n;row++) {
+        psF64* img2Row = c64Img2->data.F64[row];
+        psF64* img3Row = c64Img3->data.F64[row];
+        for (psU32 col=0;col<m;col++) {
+            if (fabsf(img2Row[col] - row) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN, true,"psImageReal didn't return the real portion at n=%d",
+                        n);
+                return 5;
+            }
+            if (fabsf(img3Row[col] - col) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN, true,"psImageImaginary didn't return the imag portion at n=%d",
+                        n);
+                return 6;
+            }
+        }
+    }
+
+    GENIMAGE(ncImg,m,n,F32,row+col);
+    ncImg2 = psImageReal(ncImg2,ncImg);
+    ncImg3 = psImageImaginary(ncImg3,ncImg);
+    if(ncImg2 == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"psImageReal returned NULL");
+        return 40;
+    }
+    if(ncImg2->type.type != PS_TYPE_F32) {
+        psError(PS_ERR_UNKNOWN,true,"psImageReal returned a wrong type");
+        return 41;
+    }
+    if(ncImg3 == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"psImageImaginary returned NULL");
+        return 42;
+    }
+    if(ncImg3->type.type != PS_TYPE_F32) {
+        psError(PS_ERR_UNKNOWN,true,"psImageImaginary returned NULL");
+        return 43;
+    }
+    for(psU32 row=0; row<n; row++) {
+        psF32* ncImg2Row = ncImg2->data.F32[row];
+        psF32* ncImg3Row = ncImg3->data.F32[row];
+        for(psU32 col=0; col<m; col++) {
+            if(fabsf(ncImg2Row[col] - (row+col)) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImageReal didn't return the real portion");
+                return 45;
+            }
+            if(fabsf(ncImg3Row[col] - 0) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImageImaginary didn't return the imaginary portion");
+                return 46;
+            }
+        }
+    }
+    psFree(ncImg);
+    psFree(ncImg2);
+    psFree(ncImg3);
+
+    psFree(c64Img);
+    psFree(c64Img2);
+    psFree(c64Img3);
+
+    // Perform psImageReal with null input
+    if(psImageReal(NULL,NULL) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImageReal did not return null with null input");
+        return 10;
+    }
+
+    // Perform psImageImaginary with null input
+    if(psImageImaginary(NULL,NULL) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImageImaginary did not return null with null input");
+        return 10;
+    }
+
     return 0;
 }
@@ -279,4 +377,11 @@
     psImage* img2 = NULL;
     psImage* img3 = NULL;
+    psImage* c64Img = NULL;
+    psImage* c64Img2 = NULL;
+    psImage* c64Img3 = NULL;
+    psImage* pImg = NULL;
+    psImage* pImg2 = NULL;
+    psImage* pImg3 = NULL;
+
     psU32 m = 128;
     psU32 n = 64;
@@ -301,7 +406,12 @@
     GENIMAGE(img,m,n,F32,row);
     GENIMAGE(img2,m,n,F32,col);
+    GENIMAGE(c64Img,m,n,F64,row);
+    GENIMAGE(c64Img2,m,n,F64,col);
+    GENIMAGE(pImg,m,n,S16,row);
+    GENIMAGE(pImg2,m,n,S16,col);
 
     // 2. call psImageComplex
     img3 = psImageComplex(img3,img,img2);
+    c64Img3 = psImageComplex(c64Img3,c64Img,c64Img2);
 
     // 3. verify that the result is a psC32
@@ -311,4 +421,8 @@
         return 1;
     }
+    if (c64Img3->type.type != PS_TYPE_C64) {
+        psError(PS_ERR_UNKNOWN,true,"Image type from psImageComplex is not complex");
+        return 10;
+    }
 
     // 4. call psImageReal and psImageImaginary on step 2 results (not needed, just use crealf/cimagf)
@@ -316,4 +430,5 @@
     for (psU32 row=0;row<n;row++) {
         psC32* img3Row = img3->data.C32[row];
+        psC64* c64Img3Row = c64Img3->data.C64[row];
         for (psU32 col=0;col<m;col++) {
             if (fabsf(crealf(img3Row[col]) - row) > FLT_EPSILON ||
@@ -322,4 +437,9 @@
                         col,row,crealf(img3Row[col]),cimagf(img3Row[col]));
                 return 2;
+            }
+            if (fabsf(crealf(c64Img3Row[col]) - row) > FLT_EPSILON ||
+                    fabsf(cimagf(c64Img3Row[col]) - col) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImageComplex result is invalid");
+                return 3;
             }
         }
@@ -351,7 +471,26 @@
     }
 
+    // Perform psImageComplex with invalid type
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message.");
+    pImg3 = psImageComplex(pImg3,pImg,pImg2);
+    if ( pImg3 != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"psImageComplex did not return NULL");
+        return 50;
+    }
+
     psFree(img);
     psFree(img2);
     psFree(img3);
+    psFree(c64Img);
+    psFree(c64Img2);
+    psFree(c64Img3);
+    psFree(pImg);
+    psFree(pImg2);
+
+    // Perform psImageComplex with null input
+    if(psImageComplex(NULL,NULL,NULL) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImageComplex did not return null with null input");
+        return 20;
+    }
 
     return 0;
@@ -362,4 +501,9 @@
     psImage* img = NULL;
     psImage* img2 = NULL;
+    psImage* c64Img = NULL;
+    psImage* c64Img2 = NULL;
+    psImage* pImg = NULL;
+    psImage* pImg2 = NULL;
+
     psU32 m = 128;
     psU32 n = 64;
@@ -374,7 +518,11 @@
     // 1. create a psC32 with unique real and imaginary values.
     GENIMAGE(img,m,n,C32, row + I * col);
+    GENIMAGE(c64Img,m,n,C64,row + I*col);
+    GENIMAGE(pImg,m,n,F32,row+col);
 
     // 2. call psImageConjugate
     img2 = psImageConjugate(img2,img);
+    c64Img2 = psImageConjugate(c64Img2,c64Img);
+    pImg2 = psImageConjugate(pImg2,pImg);
 
     // 3. verify result is psC32
@@ -383,8 +531,18 @@
         return 1;
     }
+    if (c64Img2->type.type != PS_TYPE_C64) {
+        psError(PS_ERR_UNKNOWN,true,"psImageConjugate did not return a C64 image");
+        return 10;
+    }
+    if (pImg2->type.type != PS_TYPE_F32) {
+        psError(PS_ERR_UNKNOWN,true,"psImageConjugate did not return a F32 image");
+        return 11;
+    }
 
     // 4. verify each value is conjugate of input (a+bi -> a-bi)
     for (psU32 row=0;row<n;row++) {
         psC32* img2Row = img2->data.C32[row];
+        psC64* c64Img2Row = c64Img2->data.C64[row];
+        psF32* pImg2Row = pImg2->data.F32[row];
         for (psU32 col=0;col<m;col++) {
             if (fabsf(crealf(img2Row[col]) - row) > FLT_EPSILON ||
@@ -394,4 +552,13 @@
                 return 2;
             }
+            if (fabsf(crealf(c64Img2Row[col]) - row) > FLT_EPSILON ||
+                    fabsf(cimagf(c64Img2Row[col]) + col) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImageComplex result is invalid");
+                return 20;
+            }
+            if (fabsf(pImg2Row[col] - (row+col)) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImageComplex result is invalid");
+                return 21;
+            }
         }
     }
@@ -399,4 +566,14 @@
     psFree(img);
     psFree(img2);
+    psFree(c64Img);
+    psFree(c64Img2);
+    psFree(pImg);
+    psFree(pImg2);
+
+    // Perform psImageConjugate with null input
+    if(psImageConjugate(NULL,NULL) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImageConjugate did not return null with null input");
+        return 30;
+    }
 
     return 0;
@@ -407,4 +584,8 @@
     psImage* img = NULL;
     psImage* img2 = NULL;
+    psImage* c64Img = NULL;
+    psImage* c64Img2 = NULL;
+    psImage* pImg = NULL;
+
     psU32 m = 128;
     psU32 n = 64;
@@ -419,7 +600,10 @@
     // 1. create a psC32 vector with unique real and imaginary components
     GENIMAGE(img,m,n,C32, row + I * col);
+    GENIMAGE(c64Img,m,n,C64,row+I*col);
+    GENIMAGE(pImg,m,n,F32,row+col);
 
     // 2. call psImagePowerSpectrum
     img2 = psImagePowerSpectrum(img2,img);
+    c64Img2 = psImagePowerSpectrum(c64Img2, c64Img);
 
     // 3. verify result is psF32
@@ -428,4 +612,8 @@
         return 1;
     }
+    if (c64Img2->type.type != PS_TYPE_F64) {
+        psError(PS_ERR_UNKNOWN,true,"psImagePowerSpectrum did not return PS_TYPE_F64");
+        return 10;
+    }
 
     // 4. verify the values are the square of the absolute values of the original
@@ -433,7 +621,11 @@
         psC32* imgRow = img->data.C32[row];
         psF32* img2Row = img2->data.F32[row];
+        psC64* c64ImgRow = c64Img->data.C64[row];
+        psF64* c64Img2Row = c64Img2->data.F64[row];
         for (psU32 col=0;col<m;col++) {
             psF32 power = cabs(imgRow[col]);
+            psF64 power64 = cabs(c64ImgRow[col]);
             power *= power/n/n/m/m;
+            power64 *= power64/n/n/m/m;
 
             if (fabsf(img2Row[col] - power) > 2.0f*FLT_EPSILON) {
@@ -442,4 +634,8 @@
                 return 2;
             }
+            if (fabsf(c64Img2Row[col] - power64) > 2.0f*FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"psImagePowerSpectrum result is invalid");
+                return 22;
+            }
         }
     }
@@ -447,4 +643,20 @@
     psFree(img);
     psFree(img2);
+    psFree(c64Img);
+    psFree(c64Img2);
+
+    // Perform psImagePowerSpectrum with invalid input
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message.");
+    if(psImagePowerSpectrum(NULL,pImg) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImagePowerSpectrum did not return null with invalid type");
+        return 41;
+    }
+    psFree(pImg);
+
+    // Perform psImagePowerSpectrum with null input
+    if(psImagePowerSpectrum(NULL,NULL) != NULL ) {
+        psError(PS_ERR_UNKNOWN,true,"psImagePowerSpectrum did not return null with null input");
+        return 40;
+    }
 
     return 0;
