IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 2, 2004, 9:43:23 AM (22 years ago)
Author:
desonia
Message:

adjusted output precision to allow tests to pass on x86_64, etc.

File:
1 edited

Legend:

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

    r1073 r1365  
    11/*****************************************************************************
    2     This routine must ensure that the psHistogram structure is correctly
    3     allocated and populated by the psImageHistogram() function.
    4  *****************************************************************************/
     2   This routine must ensure that the psHistogram structure is correctly
     3   allocated and populated by the psImageHistogram() function.
     4*****************************************************************************/
    55#include <stdio.h>
    66#include "pslib.h"
     
    1616int main()
    1717{
    18     psHistogram *myHist = NULL;
    19     psHistogram *myHist2= NULL;
    20     psImage *tmpImage   = NULL;
    21     psImage *tmpMask    = NULL;
    22     int testStatus      = true;
    23     int memLeaks        = 0;
    24     int nb              = 0;
    25     int i               = 0;
    26     int j               = 0;
    27     int IMAGE_X_SIZE    = 0;
    28     int IMAGE_Y_SIZE    = 0;
    29     int currentId       = 0;
    30 
    31     currentId       = psMemGetId();
    32     for (nb=0;nb<6;nb++) {
    33         if (nb == 0) {
    34             IMAGE_X_SIZE = 1;
    35             IMAGE_Y_SIZE = 1;
     18    psHistogram * myHist = NULL;
     19    psHistogram *myHist2 = NULL;
     20    psImage *tmpImage = NULL;
     21    psImage *tmpMask = NULL;
     22    int testStatus = true;
     23    int memLeaks = 0;
     24    int nb = 0;
     25    int i = 0;
     26    int j = 0;
     27    int IMAGE_X_SIZE = 0;
     28    int IMAGE_Y_SIZE = 0;
     29    int currentId = 0;
     30   
     31    currentId = psMemGetId();
     32    for ( nb = 0;nb < 6;nb++ ) {
     33            if ( nb == 0 ) {
     34                    IMAGE_X_SIZE = 1;
     35                    IMAGE_Y_SIZE = 1;
     36                }
     37            if ( nb == 1 ) {
     38                    IMAGE_X_SIZE = 1;
     39                    IMAGE_Y_SIZE = N;
     40                }
     41            if ( nb == 2 ) {
     42                    IMAGE_X_SIZE = N;
     43                    IMAGE_Y_SIZE = 1;
     44                }
     45            if ( nb == 3 ) {
     46                    IMAGE_X_SIZE = N;
     47                    IMAGE_Y_SIZE = N;
     48                }
     49            if ( nb == 4 ) {
     50                    IMAGE_X_SIZE = N;
     51                    IMAGE_Y_SIZE = M;
     52                }
     53            if ( nb == 5 ) {
     54                    IMAGE_X_SIZE = M;
     55                    IMAGE_Y_SIZE = N;
     56                }
     57            printf( "*******************************\n" );
     58            printf( "* IMAGE SIZE is (%d by %d)\n", IMAGE_X_SIZE, IMAGE_Y_SIZE );
     59            printf( "*******************************\n" );
     60            /*********************************************************************/
     61            /*  Allocate and initialize data structures                      */
     62            /*********************************************************************/
     63            tmpImage = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32 );
     64           
     65            for ( i = 0;i < tmpImage->numRows;i++ ) {
     66                    for ( j = 0;j < tmpImage->numCols;j++ ) {
     67                            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j + 0.1 );
     68                        }
     69                }
     70            tmpMask = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8 );
     71            for ( i = 0;i < tmpMask->numRows;i++ ) {
     72                    for ( j = 0;j < tmpMask->numCols;j++ ) {
     73                            if ( ( i > ( tmpMask->numRows / 2 ) ) &&
     74                                    ( j > ( tmpMask->numCols / 2 ) ) ) {
     75                                    tmpMask->data.U8[ i ][ j ] = 1;
     76                                } else {
     77                                    tmpMask->data.U8[ i ][ j ] = 0;
     78                                }
     79                        }
     80                }
     81               
     82            /*************************************************************************/
     83            /*  Calculate Histogram with no mask                             */
     84            /*************************************************************************/
     85            printPositiveTestHeader( stdout,
     86                                     "psImageStats functions",
     87                                     "Calculate Histogram, no mask" );
     88                                     
     89            myHist = psHistogramAlloc( 0.0, ( float ) ( IMAGE_X_SIZE + IMAGE_Y_SIZE ),
     90                                       NUM_BINS );
     91            myHist = psImageHistogram( myHist, tmpImage, NULL, 0 );
     92            for ( i = 0;i < NUM_BINS;i++ ) {
     93                    printf( "Bin number %d bounds: (%.1f - %.1f) data (%d)\n", i,
     94                            myHist->bounds->data.F32[ i ],
     95                            myHist->bounds->data.F32[ i + 1 ],
     96                            myHist->nums->data.S32[ i ] );
     97                }
     98            psFree( myHist );
     99           
     100            psMemCheckCorruption( 1 );
     101            printFooter( stdout,
     102                         "psImageStats functions",
     103                         "Calculate Histogram, no mask",
     104                         testStatus );
     105                         
     106            /*************************************************************************/
     107            /*  Calculate Histogram with mask                                */
     108            /*************************************************************************/
     109            printPositiveTestHeader( stdout,
     110                                     "psImageStats functions",
     111                                     "Calculate Histogram with mask" );
     112                                     
     113            myHist = psHistogramAlloc( 0.0, ( float ) ( IMAGE_X_SIZE + IMAGE_Y_SIZE ),
     114                                       NUM_BINS );
     115            myHist = psImageHistogram( myHist, tmpImage, tmpMask, 1 );
     116            for ( i = 0;i < NUM_BINS;i++ ) {
     117                    printf( "Bin number %d bounds: (%.2f - %.2f) data (%d)\n", i,
     118                            myHist->bounds->data.F32[ i ],
     119                            myHist->bounds->data.F32[ i + 1 ],
     120                            myHist->nums->data.S32[ i ] );
     121                }
     122               
     123            psMemCheckCorruption( 1 );
     124            printFooter( stdout,
     125                         "psImageStats functions",
     126                         "Calculate Histogram with mask",
     127                         testStatus );
     128                         
     129            /*************************************************************************/
     130            /*  Deallocate data structures                                   */
     131            /*************************************************************************/
     132            printPositiveTestHeader( stdout,
     133                                     "psImageStats functions",
     134                                     "Deallocate the psHistogram/psImage structure." );
     135            psFree( myHist );
     136            psFree( tmpImage );
     137            psFree( tmpMask );
     138           
     139            psMemCheckCorruption( 1 );
     140            memLeaks = psMemCheckLeaks( currentId, NULL, NULL );
     141            if ( 0 != memLeaks ) {
     142                    psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );
     143                }
     144               
     145            printFooter( stdout,
     146                         "psImageStats functions",
     147                         "Deallocate the psHistogram/psImage structure.",
     148                         testStatus );
    36149        }
    37         if (nb == 1) {
    38             IMAGE_X_SIZE = 1;
    39             IMAGE_Y_SIZE = N;
     150    printPositiveTestHeader( stdout,
     151                             "psImageStats functions",
     152                             "Calling psImageHistogram() with NULL parameters" );
     153                             
     154    tmpImage = psImageAlloc( IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32 );
     155    myHist = psHistogramAlloc( 0.0, ( float ) ( IMAGE_X_SIZE + IMAGE_Y_SIZE ),
     156                               NUM_BINS );
     157    myHist2 = psImageHistogram( NULL, tmpImage, NULL, 0 );
     158    if ( myHist2 != NULL ) {
     159            printf( "ERROR: myHist2 not equal to NULL\n" );
    40160        }
    41         if (nb == 2) {
    42             IMAGE_X_SIZE = N;
    43             IMAGE_Y_SIZE = 1;
     161       
     162    myHist2 = psImageHistogram( myHist, NULL, NULL, 0 );
     163    myHist2 = psImageHistogram( NULL, tmpImage, NULL, 0 );
     164    if ( myHist2 != NULL ) {
     165            printf( "ERROR: myHist2 not equal to NULL\n" );
    44166        }
    45         if (nb == 3) {
    46             IMAGE_X_SIZE = N;
    47             IMAGE_Y_SIZE = N;
     167       
     168    psMemCheckCorruption( 1 );
     169    psFree( myHist );
     170    psFree( tmpImage );
     171    psMemCheckCorruption( 1 );
     172    memLeaks = psMemCheckLeaks( currentId, NULL, NULL );
     173    if ( 0 != memLeaks ) {
     174            psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );
    48175        }
    49         if (nb == 4) {
    50             IMAGE_X_SIZE = N;
    51             IMAGE_Y_SIZE = M;
    52         }
    53         if (nb == 5) {
    54             IMAGE_X_SIZE = M;
    55             IMAGE_Y_SIZE = N;
    56         }
    57         printf("*******************************\n");
    58         printf("* IMAGE SIZE is (%d by %d)\n", IMAGE_X_SIZE, IMAGE_Y_SIZE);
    59         printf("*******************************\n");
    60         /*********************************************************************/
    61         /*  Allocate and initialize data structures                      */
    62         /*********************************************************************/
    63         tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32);
    64 
    65         for (i=0;i<tmpImage->numRows;i++) {
    66             for (j=0;j<tmpImage->numCols;j++) {
    67                 tmpImage->data.F32[i][j] = (float) (i + j + 0.1);
    68             }
    69         }
    70         tmpMask = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_U8);
    71         for (i=0;i<tmpMask->numRows;i++) {
    72             for (j=0;j<tmpMask->numCols;j++) {
    73                 if ((i > (tmpMask->numRows/2)) &&
    74                         (j > (tmpMask->numCols/2))) {
    75                     tmpMask->data.U8[i][j] = 1;
    76                 } else {
    77                     tmpMask->data.U8[i][j] = 0;
    78                 }
    79             }
    80         }
    81 
    82         /*************************************************************************/
    83         /*  Calculate Histogram with no mask                             */
    84         /*************************************************************************/
    85         printPositiveTestHeader(stdout,
    86                                 "psImageStats functions",
    87                                 "Calculate Histogram, no mask");
    88 
    89         myHist = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE),
    90                                   NUM_BINS);
    91         myHist = psImageHistogram(myHist, tmpImage, NULL, 0);
    92         for (i=0;i<NUM_BINS;i++) {
    93             printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
    94                    myHist->bounds->data.F32[i],
    95                    myHist->bounds->data.F32[i+1],
    96                    myHist->nums->data.S32[i]);
    97         }
    98         psFree(myHist);
    99 
    100         psMemCheckCorruption(1);
    101         printFooter(stdout,
    102                     "psImageStats functions",
    103                     "Calculate Histogram, no mask",
    104                     testStatus);
    105 
    106         /*************************************************************************/
    107         /*  Calculate Histogram with mask                                */
    108         /*************************************************************************/
    109         printPositiveTestHeader(stdout,
    110                                 "psImageStats functions",
    111                                 "Calculate Histogram with mask");
    112 
    113         myHist = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE),
    114                                   NUM_BINS);
    115         myHist = psImageHistogram(myHist, tmpImage, tmpMask, 1);
    116         for (i=0;i<NUM_BINS;i++) {
    117             printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
    118                    myHist->bounds->data.F32[i],
    119                    myHist->bounds->data.F32[i+1],
    120                    myHist->nums->data.S32[i]);
    121         }
    122 
    123         psMemCheckCorruption(1);
    124         printFooter(stdout,
    125                     "psImageStats functions",
    126                     "Calculate Histogram with mask",
    127                     testStatus);
    128 
    129         /*************************************************************************/
    130         /*  Deallocate data structures                                   */
    131         /*************************************************************************/
    132         printPositiveTestHeader(stdout,
    133                                 "psImageStats functions",
    134                                 "Deallocate the psHistogram/psImage structure.");
    135         psFree(myHist);
    136         psFree(tmpImage);
    137         psFree(tmpMask);
    138 
    139         psMemCheckCorruption(1);
    140         memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    141         if (0 != memLeaks) {
    142             psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    143         }
    144 
    145         printFooter(stdout,
    146                     "psImageStats functions",
    147                     "Deallocate the psHistogram/psImage structure.",
    148                     testStatus);
    149     }
    150     printPositiveTestHeader(stdout,
    151                             "psImageStats functions",
    152                             "Calling psImageHistogram() with NULL parameters");
    153 
    154     tmpImage = psImageAlloc(IMAGE_X_SIZE, IMAGE_Y_SIZE, PS_TYPE_F32);
    155     myHist  = psHistogramAlloc(0.0, (float) (IMAGE_X_SIZE + IMAGE_Y_SIZE),
    156                                NUM_BINS);
    157     myHist2 = psImageHistogram(NULL, tmpImage, NULL, 0);
    158     if (myHist2 != NULL) {
    159         printf("ERROR: myHist2 not equal to NULL\n");
    160     }
    161 
    162     myHist2 = psImageHistogram(myHist, NULL, NULL, 0);
    163     myHist2 = psImageHistogram(NULL, tmpImage, NULL, 0);
    164     if (myHist2 != NULL) {
    165         printf("ERROR: myHist2 not equal to NULL\n");
    166     }
    167 
    168     psMemCheckCorruption(1);
    169     psFree(myHist);
    170     psFree(tmpImage);
    171     psMemCheckCorruption(1);
    172     memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
    173     if (0 != memLeaks) {
    174         psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    175     }
    176 
    177     printFooter(stdout,
    178                 "psImageStats functions",
    179                 "Calling psImageHistogram() with NULL parameters",
    180                 testStatus);
    181 
    182     return (!testStatus);
     176       
     177    printFooter( stdout,
     178                 "psImageStats functions",
     179                 "Calling psImageHistogram() with NULL parameters",
     180                 testStatus );
     181                 
     182    return ( !testStatus );
    183183}
Note: See TracChangeset for help on using the changeset viewer.