IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 26, 2004, 2:57:34 PM (22 years ago)
Author:
desonia
Message:

converted native C types to ps Types, where practical.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageManip.c

    r2105 r2204  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-14 01:22:59 $
     8 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-10-27 00:57:33 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2525#include "psType.h"
    2626
    27 static int testImageClip(void);
    28 static int testImageClipNAN(void);
    29 static int testImageClipComplexRegion(void);
    30 static int testImageOverlay(void);
    31 static int testImageRebin(void);
    32 static int testImageRoll(void);
    33 static int testImageRotate(void);
    34 static int testImageShift(void);
    35 static int testImageShiftCase(int cols, int rows, float colShift,float rowShift);
    36 static int testImageResample(void);
     27static psS32 testImageClip(void);
     28static psS32 testImageClipNAN(void);
     29static psS32 testImageClipComplexRegion(void);
     30static psS32 testImageOverlay(void);
     31static psS32 testImageRebin(void);
     32static psS32 testImageRoll(void);
     33static psS32 testImageRotate(void);
     34static psS32 testImageShift(void);
     35static psS32 testImageShiftCase(psS32 cols, psS32 rows, float colShift,float rowShift);
     36static psS32 testImageResample(void);
    3737
    3838testDescription tests[] = {
     
    4949                          };
    5050
    51 int main(int argc, char* argv[])
     51psS32 main(psS32 argc, char* argv[])
    5252{
    5353    psLogSetLevel(PS_LOG_INFO);
     
    5757
    5858
    59 int testImageClip(void)
     59psS32 testImageClip(void)
    6060{
    6161    psImage* img = NULL;
    62     unsigned int c = 128;
    63     unsigned int r = 256;
     62    psU32 c = 128;
     63    psU32 r = 256;
    6464    psF64 min;
    6565    psF64 max;
    66     int numClipped = 0;
    67     int retVal;
     66    psS32 numClipped = 0;
     67    psS32 retVal;
    6868
    6969    psLogMsg(__func__,PS_LOG_INFO,
     
    9595    #define testImageClipByType(datatype) \
    9696    img = psImageAlloc(c,r,PS_TYPE_##datatype); \
    97     for (unsigned int row=0;row<r;row++) { \
     97    for (psU32 row=0;row<r;row++) { \
    9898        ps##datatype* imgRow = img->data.datatype[row]; \
    99         for (unsigned int col=0;col<c;col++) { \
     99        for (psU32 col=0;col<c;col++) { \
    100100            imgRow[col] = (ps##datatype)(row+col); \
    101101        } \
     
    107107    \
    108108    numClipped = 0; \
    109     for (unsigned int row=0;row<r;row++) { \
     109    for (psU32 row=0;row<r;row++) { \
    110110        ps##datatype* imgRow = img->data.datatype[row]; \
    111         for (unsigned int col=0;col<c;col++) { \
     111        for (psU32 col=0;col<c;col++) { \
    112112            ps##datatype value = (ps##datatype)(row+col); \
    113113            if (value < min) { \
     
    134134    #define testImageClipByComplexType(datatype) \
    135135    img = psImageAlloc(c,r,PS_TYPE_##datatype); \
    136     for (unsigned int row=0;row<r;row++) { \
     136    for (psU32 row=0;row<r;row++) { \
    137137        ps##datatype* imgRow = img->data.datatype[row]; \
    138         for (unsigned int col=0;col<c;col++) { \
     138        for (psU32 col=0;col<c;col++) { \
    139139            imgRow[col] = (ps##datatype)(row+I*col); \
    140140        } \
     
    146146    \
    147147    numClipped = 0; \
    148     for (unsigned int row=0;row<r;row++) { \
     148    for (psU32 row=0;row<r;row++) { \
    149149        ps##datatype* imgRow = img->data.datatype[row]; \
    150         for (unsigned int col=0;col<c;col++) { \
     150        for (psU32 col=0;col<c;col++) { \
    151151            ps##datatype value = row+I*col; \
    152152            if (cabs(value) < min) { \
     
    225225}
    226226
    227 int testImageClipNAN(void)
     227psS32 testImageClipNAN(void)
    228228{
    229229    psImage* img = NULL;
    230     unsigned int c = 128;
    231     unsigned int r = 256;
    232     int numClipped = 0;
    233     int retVal;
     230    psU32 c = 128;
     231    psU32 r = 256;
     232    psS32 numClipped = 0;
     233    psS32 retVal;
    234234
    235235    psLogMsg(__func__,PS_LOG_INFO,
     
    317317}
    318318
    319 int testImageClipComplexRegion(void)
     319psS32 testImageClipComplexRegion(void)
    320320{
    321321    psImage* img = NULL;
    322     unsigned int c = 1024;
    323     unsigned int r = 2048;
    324     int numClipped = 0;
    325     int retVal;
     322    psU32 c = 1024;
     323    psU32 r = 2048;
     324    psS32 numClipped = 0;
     325    psS32 retVal;
    326326
    327327    psLogMsg(__func__,PS_LOG_INFO,
     
    581581}
    582582
    583 int testImageOverlay(void)
     583psS32 testImageOverlay(void)
    584584{
    585585
     
    588588    psImage* img3 = NULL;
    589589    psImage* img4 = NULL;
    590     unsigned int c = 128;
    591     unsigned int r = 256;
    592     int retVal;
     590    psU32 c = 128;
     591    psU32 r = 256;
     592    psS32 retVal;
    593593
    594594    /*
     
    833833}
    834834
    835 static int testImageRebin(void)
     835static psS32 testImageRebin(void)
    836836{
    837837
     
    869869    memset(meanTruthWMask->data.F32[0],0,sizeof(psF32)*4*4); \
    870870    memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6); \
    871     for (int row = 0; row<16; row++) { \
     871    for (psS32 row = 0; row<16; row++) { \
    872872        ps##DATATYPE* inRow = in->data.DATATYPE[row]; \
    873873        psF32* meanTruthRow = meanTruth->data.F32[row/4]; \
     
    875875        psF32* maxTruthRow = maxTruth->data.F32[row/3]; \
    876876        psU8* maskRow = mask->data.U8[row]; \
    877         for (int col = 0; col<16; col++) { \
     877        for (psS32 col = 0; col<16; col++) { \
    878878            if(col != 15) { \
    879879                maskRow[col] = 0; \
     
    891891        } \
    892892    } \
    893     for (int row = 0; row<4; row++) { \
     893    for (psS32 row = 0; row<4; row++) { \
    894894        psF32* meanTruthRow = meanTruth->data.F32[row]; \
    895895        psF32* meanTruthWMaskRow = meanTruthWMask->data.F32[row]; \
    896         for (int col = 0; col<4; col++) { \
     896        for (psS32 col = 0; col<4; col++) { \
    897897            meanTruthRow[col] /= 16; \
    898898            if ( col == 3 ) { \
     
    915915        return 2; \
    916916    } \
    917     for (int row = 0; row<4; row++) { \
     917    for (psS32 row = 0; row<4; row++) { \
    918918        ps##DATATYPE* outRow = out->data.DATATYPE[row]; \
    919919        psF32* truthRow = meanTruth->data.F32[row]; \
    920         for (int col = 0; col<4; col++) { \
     920        for (psS32 col = 0; col<4; col++) { \
    921921            if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \
    922922                psError(__func__,"psImageRebin didn't produce the proper mean " \
     
    929929    stats.options = PS_STAT_SAMPLE_MEAN; \
    930930    out3 = psImageRebin(NULL,in,mask,1,4,&stats); \
    931     for (int row = 0; row<4; row++) { \
     931    for (psS32 row = 0; row<4; row++) { \
    932932        ps##DATATYPE* outRow = out3->data.DATATYPE[row]; \
    933933        psF32* truthRow = meanTruthWMask->data.F32[row]; \
    934         for ( int col = 0; col<4; col++) { \
    935             if(abs((int)outRow[col]-(int)truthRow[col]) > FLT_EPSILON) { \
     934        for ( psS32 col = 0; col<4; col++) { \
     935            if(abs((psS32)outRow[col]-(psS32)truthRow[col]) > FLT_EPSILON) { \
    936936                psError(__func__,"psImageRebin with mask didn't produce the proper mean " \
    937937                        "result at (%d,%d) [%f vs %f].", \
     
    957957        return 5; \
    958958    } \
    959     for (int row = 0; row<6; row++) { \
     959    for (psS32 row = 0; row<6; row++) { \
    960960        ps##DATATYPE* outRow = out->data.DATATYPE[row]; \
    961961        psF32* truthRow = maxTruth->data.F32[row]; \
    962         for (int col = 0; col<6; col++) { \
     962        for (psS32 col = 0; col<6; col++) { \
    963963            if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \
    964964                psError(__func__,"psImageRebin didn't produce the proper " \
     
    10821082}
    10831083
    1084 static int testImageRoll(void)
     1084static psS32 testImageRoll(void)
    10851085{
    10861086
     
    10881088    psImage* out;
    10891089    psImage* out2;
    1090     int rows = 64;
    1091     int cols = 64;
    1092     int rows1 = 8;
    1093     int cols1 = 8;
     1090    psS32 rows = 64;
     1091    psS32 cols = 64;
     1092    psS32 rows1 = 8;
     1093    psS32 cols1 = 8;
    10941094
    10951095    /*
     
    11081108
    11091109    in = psImageAlloc(cols,rows,PS_TYPE_F32);
    1110     for (int row=0;row<rows;row++) {
     1110    for (psS32 row=0;row<rows;row++) {
    11111111        psF32* inRow = in->data.F32[row];
    1112         for (int col=0;col<cols;col++) {
     1112        for (psS32 col=0;col<cols;col++) {
    11131113            inRow[col] = (psF32)row+(psF32)col/1000.0f;
    11141114        }
     
    11161116
    11171117    out = psImageRoll(NULL,in,0,0);
    1118     for (int row=0;row<rows;row++) {
     1118    for (psS32 row=0;row<rows;row++) {
    11191119        psF32* inRow = in->data.F32[row];
    11201120        psF32* outRow = out->data.F32[row];
    1121         for (int col=0;col<cols;col++) {
     1121        for (psS32 col=0;col<cols;col++) {
    11221122            if (inRow[col] != outRow[col]) {
    11231123                psError(__func__,"psImageRoll didn't produce expected result "
     
    11301130
    11311131    out2 = psImageRoll(out,in,cols/4,0);
    1132     for (int row=0;row<rows;row++) {
     1132    for (psS32 row=0;row<rows;row++) {
    11331133        psF32* inRow = in->data.F32[row];
    11341134        psF32* outRow = out->data.F32[row];
    1135         for (int col=0;col<cols;col++) {
     1135        for (psS32 col=0;col<cols;col++) {
    11361136            if (inRow[(col+cols/4) % cols] != outRow[col]) {
    11371137                psError(__func__,"psImageRoll didn't produce expected result "
     
    11511151
    11521152    out = psImageRoll(out,in,0,rows/4);
    1153     for (int row=0;row<rows;row++) {
     1153    for (psS32 row=0;row<rows;row++) {
    11541154        psF32* inRow = in->data.F32[(row+rows/4)%rows];
    11551155        psF32* outRow = out->data.F32[row];
    1156         for (int col=0;col<cols;col++) {
     1156        for (psS32 col=0;col<cols;col++) {
    11571157            if (inRow[col] != outRow[col]) {
    11581158                psError(__func__,"psImageRoll didn't produce expected result "
     
    11651165
    11661166    out = psImageRoll(out,in,cols/4,rows/4);
    1167     for (int row=0;row<rows;row++) {
     1167    for (psS32 row=0;row<rows;row++) {
    11681168        psF32* inRow = in->data.F32[(row+rows/4)%rows];
    11691169        psF32* outRow = out->data.F32[row];
    1170         for (int col=0;col<cols;col++) {
     1170        for (psS32 col=0;col<cols;col++) {
    11711171            if (inRow[(col+cols/4) % cols] != outRow[col]) {
    11721172                psError(__func__,"psImageRoll didn't produce expected result "
     
    11791179
    11801180    out = psImageRoll(out,in,-cols/4,0);
    1181     for (int row=0;row<rows;row++) {
     1181    for (psS32 row=0;row<rows;row++) {
    11821182        psF32* inRow = in->data.F32[row];
    11831183        psF32* outRow = out->data.F32[row];
    1184         for (int col=0;col<cols;col++) {
     1184        for (psS32 col=0;col<cols;col++) {
    11851185            if (inRow[(col+(cols-cols/4)) % cols] != outRow[col]) {
    11861186                psError(__func__,"psImageRoll didn't produce expected result "
     
    11931193
    11941194    out = psImageRoll(out,in,0,-rows/4);
    1195     for (int row=0;row<rows;row++) {
     1195    for (psS32 row=0;row<rows;row++) {
    11961196        psF32* inRow = in->data.F32[(row+rows-rows/4)%rows];
    11971197        psF32* outRow = out->data.F32[row];
    1198         for (int col=0;col<cols;col++) {
     1198        for (psS32 col=0;col<cols;col++) {
    11991199            if (inRow[col] != outRow[col]) {
    12001200                psError(__func__,"psImageRoll didn't produce expected result "
     
    12071207
    12081208    out = psImageRoll(out,in,-cols/4,-rows/4);
    1209     for (int row=0;row<rows;row++) {
     1209    for (psS32 row=0;row<rows;row++) {
    12101210        psF32* inRow = in->data.F32[(row+rows-rows/4)%rows];
    12111211        psF32* outRow = out->data.F32[row];
    1212         for (int col=0;col<cols;col++) {
     1212        for (psS32 col=0;col<cols;col++) {
    12131213            if (inRow[(col+cols-cols/4) % cols] != outRow[col]) {
    12141214                psError(__func__,"psImageRoll didn't produce expected result "
     
    12361236    in = psImageAlloc(rows1,cols1,PS_TYPE_##DATATYPE); \
    12371237    \
    1238     for (int row=0;row<rows1;row++) { \
     1238    for (psS32 row=0;row<rows1;row++) { \
    12391239        ps##DATATYPE* inRow = in->data.DATATYPE[row]; \
    1240         for (int col=0;col<cols1;col++) { \
     1240        for (psS32 col=0;col<cols1;col++) { \
    12411241            inRow[col] = (ps##DATATYPE)row+(ps##DATATYPE)col; \
    12421242        } \
     
    12441244    \
    12451245    out = psImageRoll(NULL,in,rows1/4,cols1/4); \
    1246     for (int row=0;row<rows1;row++) { \
     1246    for (psS32 row=0;row<rows1;row++) { \
    12471247        ps##DATATYPE* inRow = in->data.DATATYPE[(row+rows1/4)%rows1]; \
    12481248        ps##DATATYPE* outRow = out->data.DATATYPE[row]; \
    1249         for (int col=0;col<cols1;col++) { \
     1249        for (psS32 col=0;col<cols1;col++) { \
    12501250            if (inRow[(col+cols1/4)%cols1] != outRow[col]) { \
    12511251                psError(__func__,"psImageRoll didn't produce expected result " \
     
    12701270}
    12711271
    1272 int testImageRotate(void)
     1272psS32 testImageRotate(void)
    12731273{
    12741274    /*
     
    13001300    psImage* fBiTruth = NULL;
    13011301    psImage* sBiTruth = NULL;
    1302     int rows = 64;
    1303     int cols = 64;
     1302    psS32 rows = 64;
     1303    psS32 cols = 64;
    13041304    psImage* fImg = psImageAlloc(cols,rows,PS_TYPE_F32);
    13051305    psImage* sImg = psImageAlloc(cols,rows,PS_TYPE_S16);
    13061306    psImage* s32Img = psImageAlloc(cols,rows,PS_TYPE_S32);
    13071307
    1308     for(int row=0;row<rows;row++) {
     1308    for(psS32 row=0;row<rows;row++) {
    13091309        psF32* fRow = fImg->data.F32[row];
    13101310        psS16* sRow = sImg->data.S16[row];
    13111311        psS32* s32Row = s32Img->data.S32[row];
    1312         for (int col=0;col<cols;col++) {
     1312        for (psS32 col=0;col<cols;col++) {
    13131313            fRow[col] = (psF32)(row)+(psF32)(col)/100.0f;
    13141314            sRow[col] = row-2*col;
     
    13361336        ("temp/sBiOut.fits");
    13371337    ;
    1338     int index = 0;
    1339     bool fail = false;
    1340     for (int rot=-180;rot<=180;rot+=45) {
     1338    psS32 index = 0;
     1339    psBool fail = false;
     1340    for (psS32 rot=-180;rot<=180;rot+=45) {
    13411341        psImage* oldOut = fOut;
    13421342        psImage* oldBiOut = fBiOut;
     
    13881388                fail = true;
    13891389            } else {
    1390                 for (int row=0;row<fTruth->numRows;row++) {
     1390                for (psS32 row=0;row<fTruth->numRows;row++) {
    13911391                    psF32* truthRow = fTruth->data.F32[row];
    13921392                    psF32* outRow = fOut->data.F32[row];
    1393                     for (int col=0;col<fTruth->numCols;col++) {
     1393                    for (psS32 col=0;col<fTruth->numCols;col++) {
    13941394                        if (fabsf(truthRow[col]-outRow[col]) > 1) {
    13951395                            psError(__func__,"Float Image mismatch (%f vs %f) at %d,%d.",
     
    14091409            if (sTruth->numRows != sOut->numRows ||
    14101410                    sTruth->numCols != sOut->numCols) {
    1411                 psError(__func__,"Rotated short image size did not match truth "
     1411                psError(__func__,"Rotated psS16 image size did not match truth "
    14121412                        "image for %d deg rotation.",rot);
    14131413                fail = true;
    14141414            } else {
    1415                 for (int row=0;row<sTruth->numRows;row++) {
     1415                for (psS32 row=0;row<sTruth->numRows;row++) {
    14161416                    psS16* truthRow = sTruth->data.S16[row];
    14171417                    psS16* outRow = sOut->data.S16[row];
    1418                     for (int col=0;col<sTruth->numCols;col++) {
     1418                    for (psS32 col=0;col<sTruth->numCols;col++) {
    14191419                        if (fabsf(truthRow[col]-outRow[col]) > 1) {
    14201420                            psError(__func__,"Short Image mismatch (%d vs %d) "
     
    14401440                fail = true;
    14411441            } else {
    1442                 for (int row=0;row<fBiTruth->numRows;row++) {
     1442                for (psS32 row=0;row<fBiTruth->numRows;row++) {
    14431443                    psF32* truthRow = fBiTruth->data.F32[row];
    14441444                    psF32* outRow = fBiOut->data.F32[row];
    1445                     for (int col=0;col<fBiTruth->numCols;col++) {
     1445                    for (psS32 col=0;col<fBiTruth->numCols;col++) {
    14461446                        if (fabsf(truthRow[col]-outRow[col]) > 1) {
    14471447                            psError(__func__,"Float Image mismatch (%f vs %f) at %d,%d. BILINEAR",
     
    14611461            if (sBiTruth->numRows != sBiOut->numRows ||
    14621462                    sBiTruth->numCols != sBiOut->numCols) {
    1463                 psError(__func__,"Rotated short image size did not match truth "
     1463                psError(__func__,"Rotated psS16 image size did not match truth "
    14641464                        "image for %d deg rotation. BILINEAR",rot);
    14651465                fail = true;
    14661466            } else {
    1467                 for (int row=0;row<sBiTruth->numRows;row++) {
     1467                for (psS32 row=0;row<sBiTruth->numRows;row++) {
    14681468                    psS16* truthRow = sBiTruth->data.S16[row];
    14691469                    psS16* outRow = sBiOut->data.S16[row];
    1470                     for (int col=0;col<sBiTruth->numCols;col++) {
     1470                    for (psS32 col=0;col<sBiTruth->numCols;col++) {
    14711471                        if (fabsf(truthRow[col]-outRow[col]) > 1) {
    14721472                            psError(__func__,"Short Image mismatch (%d vs %d) "
     
    15371537}
    15381538
    1539 static int testImageShift(void)
     1539static psS32 testImageShift(void)
    15401540{
    15411541    /* psImageShift:
     
    15581558    */
    15591559
    1560     int retVal=0;
     1560    psS32 retVal=0;
    15611561
    15621562    // integer shift
     
    16271627}
    16281628
    1629 static int testImageShiftCase(int cols,
    1630                               int rows,
    1631                               float colShift,
    1632                               float rowShift)
     1629static psS32 testImageShiftCase(psS32 cols,
     1630                                psS32 rows,
     1631                                float colShift,
     1632                                float rowShift)
    16331633{
    16341634    psImage* fOut = NULL;
     
    16431643    psImage* sBiOut = psImageAlloc(cols,rows,PS_TYPE_S16);
    16441644
    1645     for(int row=0;row<rows;row++) {
     1645    for(psS32 row=0;row<rows;row++) {
    16461646        psF32* fRow = fImg->data.F32[row];
    16471647        psS16* sRow = sImg->data.S16[row];
    1648         for (int col=0;col<cols;col++) {
     1648        for (psS32 col=0;col<cols;col++) {
    16491649            fRow[col] = (psF32)(row)+(psF32)(col)/100.0f;
    16501650            sRow[col] = row-2*col;
     
    16571657    sBiOut = psImageShift(sBiOut, sImg, colShift, rowShift, -1, PS_INTERPOLATE_BILINEAR);
    16581658
    1659     for(int row=0;row<rows;row++) {
     1659    for(psS32 row=0;row<rows;row++) {
    16601660        psF32* fRow = fOut->data.F32[row];
    16611661        psS16* sRow = sOut->data.S16[row];
     
    16631663        psS16* sBiRow = sBiOut->data.S16[row];
    16641664
    1665         for (int col=0;col<cols;col++) {
     1665        for (psS32 col=0;col<cols;col++) {
    16661666            psF32 fValue = psImagePixelInterpolate(fImg,col+colShift,
    16671667                                                   row+rowShift,NULL,0,NAN,PS_INTERPOLATE_FLAT);
     
    17071707}
    17081708
    1709 static int testImageResample(void)
     1709static psS32 testImageResample(void)
    17101710{
    17111711
    1712     int rows = 60;
    1713     int cols = 80;
     1712    psS32 rows = 60;
     1713    psS32 cols = 80;
    17141714    psImage* result = NULL;
    1715     int scale = 4;
     1715    psS32 scale = 4;
    17161716    psErr* err;
    17171717
    17181718    psImage* image = psImageAlloc(cols,rows,PS_TYPE_F32);
    1719     for(int row=0;row<rows;row++) {
     1719    for(psS32 row=0;row<rows;row++) {
    17201720        psF32* imageRow = image->data.F32[row];
    1721         for (int col=0;col<cols;col++) {
     1721        for (psS32 col=0;col<cols;col++) {
    17221722            imageRow[col] = row+2*col;
    17231723        }
     
    17531753
    17541754    psF32 truthValue;
    1755     for(int row=0;row<result->numRows;row++) {
    1756         for (int col=0;col<result->numCols;col++) {
     1755    for(psS32 row=0;row<result->numRows;row++) {
     1756        for (psS32 col=0;col<result->numCols;col++) {
    17571757            truthValue = psImagePixelInterpolate(image,
    17581758                                                 (float)col/(float)scale,(float)row/(float)scale,
Note: See TracChangeset for help on using the changeset viewer.