diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2009-04-09 19:56:54 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2009-04-09 19:56:54 (GMT) |
commit | c8f6207556a42f2408eb075d5c037699751fef8d (patch) | |
tree | 0e1c929e392902c99a9d95acca87d087c1aa0b62 /hl/test/test_image.c | |
parent | 16985151d7332580d8100187b757b107c323a063 (diff) | |
download | hdf5-c8f6207556a42f2408eb075d5c037699751fef8d.zip hdf5-c8f6207556a42f2408eb075d5c037699751fef8d.tar.gz hdf5-c8f6207556a42f2408eb075d5c037699751fef8d.tar.bz2 |
[svn-r16719] clean linux warnings
tested: linux
Diffstat (limited to 'hl/test/test_image.c')
-rw-r--r-- | hl/test/test_image.c | 463 |
1 files changed, 232 insertions, 231 deletions
diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 2a365e2..426ae1d 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdlib.h> #include <string.h> @@ -61,9 +61,9 @@ static int read_palette(const char* file_name, rgb_t *palette, size_t palette_si unsigned char *image_data = NULL; /*------------------------------------------------------------------------- - * the main program - *------------------------------------------------------------------------- - */ +* the main program +*------------------------------------------------------------------------- +*/ int main(void) { @@ -83,9 +83,9 @@ error: } /*------------------------------------------------------------------------- - * a simple test that generates images and palettes - *------------------------------------------------------------------------- - */ +* a simple test that generates images and palettes +*------------------------------------------------------------------------- +*/ static int test_simple(void) { @@ -94,6 +94,7 @@ static int test_simple(void) hsize_t planes; hid_t fid; int i, j, n, space; + hsize_t u; char interlace[20]; hssize_t npals; @@ -142,7 +143,7 @@ static int test_simple(void) } } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * define a palette, blue to red tones *------------------------------------------------------------------------- */ @@ -156,7 +157,7 @@ static int test_simple(void) /* Create a new HDF5 file using default properties. */ fid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * Indexed image test *------------------------------------------------------------------------- */ @@ -182,9 +183,9 @@ static int test_simple(void) if ( H5IMread_image( fid, IMAGE1_NAME, buf1_out ) < 0 ) goto out; - for (i = 0; i < height*width*planes; i++) + for (u = 0; u < height*width*planes; u++) { - if ( buf1[i] != buf1_out[i] ) + if ( buf1[u] != buf1_out[u] ) goto out; } @@ -192,7 +193,7 @@ static int test_simple(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * True color image test *------------------------------------------------------------------------- */ @@ -210,16 +211,16 @@ static int test_simple(void) if ( H5IMread_image( fid, IMAGE2_NAME, buf2_out ) < 0 ) goto out; - for (i = 0; i < height*width*planes; i++) + for (u = 0; u < height*width*planes; u++) { - if ( buf2[i] != buf2_out[i] ) + if ( buf2[u] != buf2_out[u] ) goto out; } PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_npalettes test *------------------------------------------------------------------------- */ @@ -229,7 +230,7 @@ static int test_simple(void) if ( H5IMget_npalettes( fid, IMAGE1_NAME, &npals ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_palette_info test *------------------------------------------------------------------------- */ @@ -243,7 +244,7 @@ static int test_simple(void) goto out; } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_palette test *------------------------------------------------------------------------- */ @@ -257,7 +258,7 @@ static int test_simple(void) goto out; } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMis_image test *------------------------------------------------------------------------- */ @@ -268,7 +269,7 @@ static int test_simple(void) if ( H5IMis_image( fid, IMAGE2_NAME ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMis_palette test *------------------------------------------------------------------------- */ @@ -276,7 +277,7 @@ static int test_simple(void) if ( H5IMis_palette( fid, PAL_NAME ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- */ @@ -301,9 +302,9 @@ out: /*------------------------------------------------------------------------- - * read sample realistic image data from ASCII files - *------------------------------------------------------------------------- - */ +* read sample realistic image data from ASCII files +*------------------------------------------------------------------------- +*/ static int test_data(void) { @@ -321,7 +322,7 @@ static int test_data(void) printf("Testing read ascii image data and generate images\n"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * read 8bit image data *------------------------------------------------------------------------- */ @@ -341,7 +342,7 @@ static int test_data(void) TESTING2("attaching palettes"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #1. rainbow palette. data is contained in "pal_rgb.h" *------------------------------------------------------------------------- */ @@ -358,7 +359,7 @@ static int test_data(void) 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 *------------------------------------------------------------------------- @@ -384,7 +385,7 @@ static int test_data(void) 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 *------------------------------------------------------------------------- @@ -413,7 +414,7 @@ static int test_data(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #4. blue-red * make a palette whith blue to red colors *------------------------------------------------------------------------- @@ -434,7 +435,7 @@ static int test_data(void) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * true color image example with pixel interlace *------------------------------------------------------------------------- */ @@ -469,7 +470,7 @@ static int test_data(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ @@ -488,16 +489,16 @@ out: } - /* - The following test provides an examples of how to generate HDF5 image data from - floating point data. In the example we use real life topographic data - (from the North American hemisphere). In the dataset sea values are represented - as negative numbers and land values are represented as positive numbers. - The example generates 3 HDF5 images, one that generates an image from all the values, - another that generates an image from the land values and another that generates an - image from the sea values. - For the example we used data from MODB, the Mediterranean Oceanic Data Base - http://modb.oce.ulg.ac.be/ +/* +The following test provides an examples of how to generate HDF5 image data from +floating point data. In the example we use real life topographic data +(from the North American hemisphere). In the dataset sea values are represented +as negative numbers and land values are represented as positive numbers. +The example generates 3 HDF5 images, one that generates an image from all the values, +another that generates an image from the land values and another that generates an +image from the sea values. +For the example we used data from MODB, the Mediterranean Oceanic Data Base +http://modb.oce.ulg.ac.be/ */ @@ -519,7 +520,7 @@ static int test_generate(void) printf("Testing read and process data and make indexed images\n"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * compose the name of the file to open, using the srcdir, if appropriate *------------------------------------------------------------------------- */ @@ -543,40 +544,40 @@ static int test_generate(void) return -1; } -/* -!The first line of the ASCII file contains the dimension of the array : -! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5. -!The second line contains the exclusion value, the minimum and the maximum value of this -! file. These numbers are stored with the FORTRAN format E12.5. -! The remaining lines contains the data of the array, with 5 numbers per line -! (except the last line for each I-line). -! The array is stored in horizontal slices from sea surface to sea bottom and from -! north to south. So the indexes go from : -! -! DO K = KMAX to 1 -! DO J = JMAX to 1 -! DO I = 1 to IMAX -! read -! OD -! OD -! OD -! -! ____________________________ -! / /| (imax,jmax,kmax) -! / sea surface / | -! / / | -! /__________________________ / | -! | | | -! | | | (imax,jmax,1) n -! | | / / -! | | / / -! ^ j | | / w <-----o-----> e -! k | / |__________________________|/ / -! | / (imax,1,1) / -! |----------> s -! i -! -*/ + /* + !The first line of the ASCII file contains the dimension of the array : + ! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5. + !The second line contains the exclusion value, the minimum and the maximum value of this + ! file. These numbers are stored with the FORTRAN format E12.5. + ! The remaining lines contains the data of the array, with 5 numbers per line + ! (except the last line for each I-line). + ! The array is stored in horizontal slices from sea surface to sea bottom and from + ! north to south. So the indexes go from : + ! + ! DO K = KMAX to 1 + ! DO J = JMAX to 1 + ! DO I = 1 to IMAX + ! read + ! OD + ! OD + ! OD + ! + ! ____________________________ + ! / /| (imax,jmax,kmax) + ! / sea surface / | + ! / / | + ! /__________________________ / | + ! | | | + ! | | | (imax,jmax,1) n + ! | | / / + ! | | / / + ! ^ j | | / w <-----o-----> e + ! k | / |__________________________|/ / + ! | / (imax,1,1) / + ! |----------> s + ! i + ! + */ fscanf( f, "%d %d %d", &imax, &jmax, &kmax ); @@ -592,7 +593,7 @@ static int test_generate(void) } fclose( f ); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * we are processing all the data here *------------------------------------------------------------------------- @@ -611,7 +612,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the land data *------------------------------------------------------------------------- @@ -633,7 +634,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the sea data *------------------------------------------------------------------------- @@ -655,7 +656,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * make a palette and attach it to the datasets *------------------------------------------------------------------------- */ @@ -677,7 +678,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ @@ -697,25 +698,25 @@ out: /*------------------------------------------------------------------------- - * read_data - * utility function to read ASCII image data - * the files have a header of the type - * - * components - * n - * height - * n - * width - * n - * - * followed by the image data - * - *------------------------------------------------------------------------- - */ +* read_data +* utility function to read ASCII image data +* the files have a header of the type +* +* components +* n +* height +* n +* width +* n +* +* followed by the image data +* +*------------------------------------------------------------------------- +*/ static int read_data( const char* fname, /*IN*/ - hsize_t *width, /*OUT*/ - hsize_t *height /*OUT*/ ) + hsize_t *width, /*OUT*/ + hsize_t *height /*OUT*/ ) { int i, n; int color_planes; @@ -725,7 +726,7 @@ static int read_data( const char* fname, /*IN*/ 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 *------------------------------------------------------------------------- */ @@ -737,7 +738,7 @@ static int read_data( const char* fname, /*IN*/ } strcat(data_file,fname); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ @@ -781,17 +782,17 @@ static int read_data( const char* fname, /*IN*/ /*------------------------------------------------------------------------- - * read_palette - * Read an ASCII palette file .PAL into an array - * the files have a header of the type - * - * Parameters: - * fname - name of file to read. - * palette - array of rgb_t to store the read palette. - * palette_size - number of elements in 'palette' array - * - *------------------------------------------------------------------------- - */ +* read_palette +* Read an ASCII palette file .PAL into an array +* the files have a header of the type +* +* Parameters: +* fname - name of file to read. +* palette - array of rgb_t to store the read palette. +* palette_size - number of elements in 'palette' array +* +*------------------------------------------------------------------------- +*/ #define STRING_JASC "JASC-PAL" @@ -803,118 +804,118 @@ static int read_palette(const char* fname, rgb_t *palette, size_t palette_size) { - FILE *file; - char buffer[80]; - unsigned u; - unsigned int red; - unsigned int green; - unsigned int blue; - unsigned nentries; - char *srcdir = getenv("srcdir"); /* the source directory */ - char data_file[512]; /* buffer to hold name of existing data file */ + FILE *file; + char buffer[80]; + unsigned u; + unsigned int red; + unsigned int green; + unsigned int blue; + unsigned nentries; + 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 - *------------------------------------------------------------------------- - */ - strcpy(data_file, ""); - if (srcdir) - { - strcpy(data_file, srcdir); - strcat(data_file, "/"); - } - strcat(data_file,fname); - - /* ensure the given palette is valid */ - if (!palette) - return -1; - - /* open the input file */ - if (!(file = fopen(data_file, "r"))) - { - printf( "Could not open file %s. Try set $srcdir \n", data_file ); - return -1; - } - - /* read the file ident string */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - /* ensure it matches the palette file ident string */ - if ( strncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && - strncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) - { - fclose(file); - return -1; - } - - /* read the version string */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - /* ensure it matches the palette file version string */ - if ( strncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && - strncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) - { - fclose(file); - return -1; - } - - /* read the number of colors */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - - /* extract the number of colors. + /*------------------------------------------------------------------------- + * compose the name of the file to open, using "srcdir", if appropriate + *------------------------------------------------------------------------- + */ + strcpy(data_file, ""); + if (srcdir) + { + strcpy(data_file, srcdir); + strcat(data_file, "/"); + } + strcat(data_file,fname); + + /* ensure the given palette is valid */ + if (!palette) + return -1; + + /* open the input file */ + if (!(file = fopen(data_file, "r"))) + { + printf( "Could not open file %s. Try set $srcdir \n", data_file ); + return -1; + } + + /* read the file ident string */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + /* ensure it matches the palette file ident string */ + if ( strncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && + strncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) + { + fclose(file); + return -1; + } + + /* read the version string */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + /* ensure it matches the palette file version string */ + if ( strncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && + strncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) + { + fclose(file); + return -1; + } + + /* read the number of colors */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + + /* extract the number of colors. check for missing version or number of colors in this case it reads the first entry */ - if ( strlen( buffer ) > 4 ) - { - fclose(file); - return -1; - } - - if (sscanf(buffer, "%u", &nentries) != 1) - { - fclose(file); - return -1; - } - - /* ensure there are a sensible number of colors in the palette */ - if ((nentries > 256) || (nentries > palette_size)) - { - fclose(file); - return(-1); - } - - /* read the palette entries */ - for (u = 0; u < nentries; u++) - { - /* extract the red, green and blue color components. */ - if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) - { - fclose(file); - return -1; - } - /* store this palette entry */ - palette[u].r = (unsigned char)red; - palette[u].g = (unsigned char)green; - palette[u].b = (unsigned char)blue; - } - - /* close file */ - fclose(file); - - return nentries; + if ( strlen( buffer ) > 4 ) + { + fclose(file); + return -1; + } + + if (sscanf(buffer, "%u", &nentries) != 1) + { + fclose(file); + return -1; + } + + /* ensure there are a sensible number of colors in the palette */ + if ((nentries > 256) || (nentries > palette_size)) + { + fclose(file); + return(-1); + } + + /* read the palette entries */ + for (u = 0; u < nentries; u++) + { + /* extract the red, green and blue color components. */ + if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) + { + fclose(file); + return -1; + } + /* store this palette entry */ + palette[u].r = (unsigned char)red; + palette[u].g = (unsigned char)green; + palette[u].b = (unsigned char)blue; + } + + /* close file */ + fclose(file); + + return nentries; } |