diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2008-09-16 16:22:16 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2008-09-16 16:22:16 (GMT) |
commit | b9be0455961ca1098bc4977bf1138394932b75db (patch) | |
tree | 8bf7377bbda85d614e4e5984c5a1a59ac323310e /hl/test/test_image.c | |
parent | 37a1f87664a1b2026e1d2a1dd5033eb2e8b1f5fc (diff) | |
download | hdf5-b9be0455961ca1098bc4977bf1138394932b75db.zip hdf5-b9be0455961ca1098bc4977bf1138394932b75db.tar.gz hdf5-b9be0455961ca1098bc4977bf1138394932b75db.tar.bz2 |
[svn-r15629] Description:
Remove trailing whitespace from C/C++ source files, with the following
script:
foreach f (*.[ch] *.cpp)
sed 's/[[:blank:]]*$//' $f > sed.out && mv sed.out $f
end
Tested on:
Mac OS X/32 10.5.5 (amazon)
No need for h5committest, just whitespace changes...
Diffstat (limited to 'hl/test/test_image.c')
-rw-r--r-- | hl/test/test_image.c | 286 |
1 files changed, 143 insertions, 143 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 9645bad..2a365e2 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -68,15 +68,15 @@ unsigned char *image_data = NULL; int main(void) { int nerrors=0; - + nerrors += test_simple()<0 ?1:0; nerrors += test_data()<0 ?1:0; nerrors += test_generate()<0 ?1:0; - + if (nerrors) goto error; printf("All image tests passed.\n"); return 0; - + error: printf("***** %d IMAGE TEST%s FAILED! *****\n",nerrors, 1 == nerrors ? "" : "S"); return 1; @@ -96,21 +96,21 @@ static int test_simple(void) int i, j, n, space; char interlace[20]; hssize_t npals; - + /* 8-bit image */ unsigned char buf1 [ WIDTH*HEIGHT ]; unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */ hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */ - + /* 24-bit image */ unsigned char buf2 [ WIDTH*HEIGHT*3 ]; - + /* read data */ unsigned char buf1_out [ WIDTH*HEIGHT ]; unsigned char buf2_out [ WIDTH*HEIGHT*3 ]; unsigned char pal_out[ PAL_ENTRIES * 3 ]; /* palette array */ hsize_t pal_dims_out[2]; /* palette dimensions */ - + /* create an image */ space = WIDTH*HEIGHT / PAL_ENTRIES; for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ ) @@ -121,10 +121,10 @@ static int test_simple(void) n++; j=0; } - + } - - + + /* create an image */ space = WIDTH*HEIGHT / 256; for (i=0, j=0, n=0; i < WIDTH*HEIGHT*3; i+=3, j++ ) @@ -141,9 +141,9 @@ static int test_simple(void) j=0; } } - + /*------------------------------------------------------------------------- - * define a palette, blue to red tones + * define a palette, blue to red tones *------------------------------------------------------------------------- */ for ( i=0, n=0; i<PAL_ENTRIES*3; i+=3, n++) @@ -152,140 +152,140 @@ static int test_simple(void) pal[i+1]=0; /* green */ pal[i+2]=255-n; /* blue */ } - + /* Create a new HDF5 file using default properties. */ fid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); - + /*------------------------------------------------------------------------- * Indexed image test *------------------------------------------------------------------------- */ - + TESTING("indexed image"); - + /* Write image */ if ( H5IMmake_image_8bit( fid, IMAGE1_NAME, width, height, buf1 ) < 0 ) goto out; - + /* Make a palette */ if ( H5IMmake_palette( fid, PAL_NAME, pal_dims, pal ) < 0 ) goto out; - + /* Attach a palette to the image dataset */ if ( H5IMlink_palette( fid, IMAGE1_NAME, PAL_NAME ) < 0 ) goto out; - + /* Read image */ if ( H5IMget_image_info( fid, IMAGE1_NAME, &width, &height, &planes, interlace, &npals ) < 0 ) goto out; - + if ( H5IMread_image( fid, IMAGE1_NAME, buf1_out ) < 0 ) goto out; - - for (i = 0; i < height*width*planes; i++) + + for (i = 0; i < height*width*planes; i++) { - if ( buf1[i] != buf1_out[i] ) + if ( buf1[i] != buf1_out[i] ) goto out; - + } - - + + PASSED(); - + /*------------------------------------------------------------------------- * True color image test *------------------------------------------------------------------------- */ - + TESTING("true color image"); - + /* Write image */ if ( H5IMmake_image_24bit( fid, IMAGE2_NAME, width, height, "INTERLACE_PIXEL", buf2 ) ) goto out; - + /* Read image */ if ( H5IMget_image_info( fid, IMAGE2_NAME, &width, &height, &planes, interlace, &npals ) < 0 ) goto out; - + if ( H5IMread_image( fid, IMAGE2_NAME, buf2_out ) < 0 ) goto out; - - for (i = 0; i < height*width*planes; i++) + + for (i = 0; i < height*width*planes; i++) { - if ( buf2[i] != buf2_out[i] ) + if ( buf2[i] != buf2_out[i] ) goto out; } - - + + PASSED(); - + /*------------------------------------------------------------------------- * H5IMget_npalettes test *------------------------------------------------------------------------- */ - + TESTING("pallete functions"); - + if ( H5IMget_npalettes( fid, IMAGE1_NAME, &npals ) < 0 ) goto out; - + /*------------------------------------------------------------------------- * H5IMget_palette_info test *------------------------------------------------------------------------- */ - + if ( H5IMget_palette_info( fid, IMAGE1_NAME, 0, pal_dims_out ) < 0 ) goto out; - - for (i = 0; i < 2; i++) + + for (i = 0; i < 2; i++) { - if ( pal_dims[i] != pal_dims_out[i] ) + if ( pal_dims[i] != pal_dims_out[i] ) goto out; } - + /*------------------------------------------------------------------------- * H5IMget_palette test *------------------------------------------------------------------------- */ - + if ( H5IMget_palette( fid, IMAGE1_NAME, 0, pal_out ) < 0 ) goto out; - - for (i = 0; i < PAL_ENTRIES * 3; i++) + + for (i = 0; i < PAL_ENTRIES * 3; i++) { - if ( pal[i] != pal_out[i] ) + if ( pal[i] != pal_out[i] ) goto out; } - + /*------------------------------------------------------------------------- * H5IMis_image test *------------------------------------------------------------------------- */ - + if ( H5IMis_image( fid, IMAGE1_NAME ) < 0 ) goto out; - + if ( H5IMis_image( fid, IMAGE2_NAME ) < 0 ) goto out; - + /*------------------------------------------------------------------------- * H5IMis_palette test *------------------------------------------------------------------------- */ - + if ( H5IMis_palette( fid, PAL_NAME ) < 0 ) goto out; - + /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- */ - + /* Close the file. */ - if(H5Fclose( fid ) < 0) + if(H5Fclose( fid ) < 0) goto out; - - + + PASSED(); return 0; @@ -314,60 +314,60 @@ static int test_data(void) unsigned char pal[256*3]; /* buffer to hold an HDF5 palette */ rgb_t rgb[256]; /* buffer to hold a .pal file palette */ int i, n; - + /* create a file using default properties */ if ((fid=H5Fcreate(FILE2,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) goto out; - + printf("Testing read ascii image data and generate images\n"); - + /*------------------------------------------------------------------------- * read 8bit image data *------------------------------------------------------------------------- */ - + TESTING2("make indexed image"); - + /* read first data file */ if (read_data(DATA_FILE1,&width,&height)<0) goto out; - + /* make an image */ if (H5IMmake_image_8bit(fid,IMAGE1_NAME,width,height,image_data)<0) goto out; - + PASSED(); - - + + TESTING2("attaching palettes"); - + /*------------------------------------------------------------------------- * palette #1. rainbow palette. data is contained in "pal_rgb.h" *------------------------------------------------------------------------- */ - + /* initialize the palette data */ pal_dims[0] = 256; pal_dims[1] = 3; - + /* make a palette */ if (H5IMmake_palette(fid,PAL1_NAME,pal_dims,pal_rgb)<0) goto out; - + /* attach a palette to the image dataset */ if (H5IMlink_palette(fid,IMAGE1_NAME,PAL1_NAME)<0) goto out; - + /*------------------------------------------------------------------------- * palette #2. sepia palette. * read a PAL file and attach the palette to the HDF5 file *------------------------------------------------------------------------- */ - + /* read a PAL file */ if (read_palette(PAL2_FILE, rgb, sizeof(rgb))<0) goto out; - + /* transfer to the HDF5 buffer */ for ( i=0, n=0; i<256*3; i+=3, n++) { @@ -375,25 +375,25 @@ static int test_data(void) pal[i+1]=rgb[n].g; pal[i+2]=rgb[n].b; } - + /* make a palette */ if (H5IMmake_palette(fid,PAL2_NAME,pal_dims,pal)<0) goto out; - + /* attach the palette to the image dataset */ if (H5IMlink_palette(fid,IMAGE1_NAME,PAL2_NAME)<0) goto out; - + /*------------------------------------------------------------------------- * palette #3. earth palette. * read a PAL file and attach the palette to the HDF5 file *------------------------------------------------------------------------- */ - + /* read a PAL file */ if (read_palette(PAL3_FILE, rgb, sizeof(rgb))<0) goto out; - + /* transfer to the HDF5 buffer */ for ( i=0, n=0; i<256*3; i+=3, n++) { @@ -401,18 +401,18 @@ static int test_data(void) pal[i+1]=rgb[n].g; pal[i+2]=rgb[n].b; } - + /* make a palette */ if (H5IMmake_palette(fid,PAL3_NAME,pal_dims,pal)<0) goto out; - + /* attach the palette to the image dataset */ if (H5IMlink_palette(fid,IMAGE1_NAME,PAL3_NAME)<0) goto out; - + PASSED(); - - + + /*------------------------------------------------------------------------- * palette #4. blue-red * make a palette whith blue to red colors @@ -424,60 +424,60 @@ static int test_data(void) pal[i+1]=0; pal[i+2]=255-n; } - + /* make a palette */ if (H5IMmake_palette(fid,PAL4_NAME,pal_dims,pal)<0) goto out; - + /* attach the palette to the image dataset */ if (H5IMlink_palette(fid,IMAGE1_NAME,PAL4_NAME)<0) goto out; - - + + /*------------------------------------------------------------------------- * true color image example with pixel interlace *------------------------------------------------------------------------- */ - + TESTING2("make true color image with pixel interlace"); - + /* read second data file */ if ((read_data(DATA_FILE2,&width,&height))<0) goto out; - + /* make image */ if ((H5IMmake_image_24bit(fid,IMAGE2_NAME,width,height,"INTERLACE_PIXEL",image_data))<0) goto out; - + PASSED(); - + /*------------------------------------------------------------------------- * True color image example with plane interlace *------------------------------------------------------------------------- */ - + TESTING2("make true color image with plane interlace"); - + /* read third data file */ if ((read_data(DATA_FILE3,&width,&height))<0) goto out; - + /* make image */ if ((H5IMmake_image_24bit(fid,IMAGE3_NAME,width,height,"INTERLACE_PLANE",image_data))<0) goto out; - + PASSED(); - - + + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if (H5Fclose(fid)<0) goto out; - + return 0; - + /* error zone, gracefully close */ out: H5E_BEGIN_TRY { @@ -512,13 +512,13 @@ static int test_generate(void) char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ int i; - + /* create a file using default properties */ if ((fid=H5Fcreate(FILE3,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) goto out; - + printf("Testing read and process data and make indexed images\n"); - + /*------------------------------------------------------------------------- * compose the name of the file to open, using the srcdir, if appropriate *------------------------------------------------------------------------- @@ -529,12 +529,12 @@ static int test_generate(void) strcat(data_file, "/"); } strcat(data_file,DATA_FILE4); - + /*------------------------------------------------------------------------- * read data; the file data format is described below *------------------------------------------------------------------------- */ - + f = fopen( data_file, "r" ) ; if ( f == NULL ) { @@ -581,44 +581,44 @@ static int test_generate(void) fscanf( f, "%d %d %d", &imax, &jmax, &kmax ); fscanf( f, "%f %f %f", &valex, &xmin, &xmax ); - + data = (float*) malloc ( imax * jmax * kmax * sizeof( float )); image_data = (unsigned char*) malloc ( imax * jmax * kmax * sizeof( unsigned char )); - + for ( i = 0; i < imax * jmax * kmax; i++ ) { fscanf( f, "%f ", &value ); data[i] = value; } fclose( f ); - + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * we are processing all the data here *------------------------------------------------------------------------- */ - + TESTING2("make indexed image from all the data"); - + for ( i = 0; i < imax * jmax * kmax; i++ ) { image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / (xmax - xmin )); } - + /* Make the image */ if ((H5IMmake_image_8bit(fid,"All data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; - + PASSED(); - + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the land data *------------------------------------------------------------------------- */ - + TESTING2("make indexed image from land data"); - + for ( i = 0; i < imax * jmax * kmax; i++ ) { if ( data[i] < 0 ) @@ -626,21 +626,21 @@ static int test_generate(void) else image_data[i] = (unsigned char)(( 255 * (data[i] ) ) / xmax ); } - + /* make the image */ if ((H5IMmake_image_8bit(fid,"Land data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; - + PASSED(); - + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the sea data *------------------------------------------------------------------------- */ - + TESTING2("make indexed image from sea data"); - + for ( i = 0; i < imax * jmax * kmax; i++ ) { if ( data[i] > 0 ) @@ -648,24 +648,24 @@ static int test_generate(void) else image_data[i] = (unsigned char)(( 255 * (data[i] - xmin ) ) / xmin ); } - + /* make the image */ if ((H5IMmake_image_8bit(fid,"Sea data",(hsize_t)imax,(hsize_t)jmax,image_data))<0) goto out; - + PASSED(); - + /*------------------------------------------------------------------------- * make a palette and attach it to the datasets *------------------------------------------------------------------------- */ - + TESTING2("attaching palettes"); - + /* make a palette */ if ((H5IMmake_palette(fid,PAL1_NAME,pal_dims,pal_rgb))<0) goto out; - + /* attach the palette to the image datasets */ if ((H5IMlink_palette(fid,"All data",PAL1_NAME))<0) goto out; @@ -673,19 +673,19 @@ static int test_generate(void) goto out; if ((H5IMlink_palette(fid,"Sea data",PAL1_NAME))<0) goto out; - + PASSED(); - - + + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if (H5Fclose(fid)<0) goto out; - + return 0; - + /* error zone, gracefully close */ out: H5E_BEGIN_TRY { @@ -724,7 +724,7 @@ static int read_data( const char* fname, /*IN*/ int w, h; char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ - + /*------------------------------------------------------------------------- * compose the name of the file to open, using "srcdir", if appropriate *------------------------------------------------------------------------- @@ -736,46 +736,46 @@ static int read_data( const char* fname, /*IN*/ strcat(data_file, "/"); } strcat(data_file,fname); - + /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ - + f = fopen(data_file, "r"); if ( f == NULL ) { printf( "Could not open file %s. Try set $srcdir \n", data_file ); return -1; } - + fscanf( f, "%s", str ); fscanf( f, "%d", &color_planes ); fscanf( f, "%s", str ); fscanf( f, "%d", &h); fscanf( f, "%s", str ); fscanf( f, "%d", &w); - + *width = (hsize_t)w; *height = (hsize_t)h; - + if ( image_data ) { free( image_data ); image_data=NULL; } - + image_data = (unsigned char*) malloc (w * h * color_planes * sizeof( unsigned char )); - + for (i = 0; i < h * w * color_planes ; i++) { fscanf( f, "%d",&n ); image_data[i] = (unsigned char)n; } fclose(f); - + return 1; - + } |