hdf5/hl/test/test_image.c
Quincey Koziol 427ff7da28 [svn-r9727] Purpose:
Bug Fix/Code Cleanup/Doc Cleanup/Optimization/Branch Sync :-)

Description:
    Generally speaking, this is the "signed->unsigned" change to selections.
However, in the process of merging code back, things got stickier and stickier
until I ended up doing a big "sync the two branches up" operation.  So... I
brought back all the "infrastructure" fixes from the development branch to the
release branch (which I think were actually making some improvement in
performance) as well as fixed several bugs which had been fixed in one branch,
but not the other.

    I've also tagged the repository before making this checkin with the label
"before_signed_unsigned_changes".

Platforms tested:
    FreeBSD 4.10 (sleipnir) w/parallel & fphdf5
    FreeBSD 4.10 (sleipnir) w/threadsafe
    FreeBSD 4.10 (sleipnir) w/backward compatibility
    Solaris 2.7 (arabica) w/"purify options"
    Solaris 2.8 (sol) w/FORTRAN & C++
    AIX 5.x (copper) w/parallel & FORTRAN
    IRIX64 6.5 (modi4) w/FORTRAN
    Linux 2.4 (heping) w/FORTRAN & C++


Misc. update:
2004-12-29 09:26:20 -05:00

195 lines
5.3 KiB
C

/****************************************************************************
* NCSA HDF *
* Scientific Data Technologies *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* *
* For conditions of distribution and use, see the accompanying *
* hdf/COPYING f. *
* *
****************************************************************************/
#include "H5IM.h"
#define FILE_NAME "test_image.h5"
#define WIDTH (hsize_t)500
#define HEIGHT (hsize_t)200
unsigned char image_in1 [ WIDTH*HEIGHT ];
unsigned char image_out1[ WIDTH*HEIGHT ];
unsigned char image_in2 [ WIDTH*HEIGHT*3 ];
unsigned char image_out2[ WIDTH*HEIGHT*3 ];
/*-------------------------------------------------------------------------
* the main program
*-------------------------------------------------------------------------
*/
int main( void )
{
hid_t file_id;
hsize_t width, height, planes;
hsize_t pal_dims[] = {9,3};
hsize_t pal_dims_out[2];
hsize_t i;
char interlace[20];
hssize_t npals;
unsigned char pal_data_out[9*3];
/* create a 9 entry grey palette */
unsigned char pal_data_in[9*3] = {0,0,0,
25,25,25,
50,50,50,
75,75,75,
100,100,100,
125,125,125,
150,150,150,
175,175,175,
200,200,200};
for (i = 0; i < WIDTH*HEIGHT; i++ )
image_in1[i] = (unsigned char)i;
for (i = 0; i < WIDTH*HEIGHT*3; i++)
image_in2[i] = (unsigned char)i;
/* Create a new HDF5 file using default properties. */
file_id = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
/*-------------------------------------------------------------------------
* Indexed image test
*-------------------------------------------------------------------------
*/
TESTING("indexed image");
/* Write image */
if ( H5IMmake_image_8bit( file_id, "Image1", WIDTH, HEIGHT, image_in1 ) < 0 )
goto out;
/* Make a palette */
if ( H5IMmake_palette( file_id, "Pallete", pal_dims, pal_data_in ) < 0 )
goto out;
/* Attach a palette to the image dataset */
if ( H5IMlink_palette( file_id, "Image1", "Pallete" ) < 0 )
goto out;
/* Read image */
if ( H5IMget_image_info( file_id, "Image1", &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
if ( H5IMread_image( file_id, "Image1", image_out1 ) < 0 )
goto out;
for (i = 0; i < height*width*planes; i++) {
if ( image_in1[i] != image_out1[i] ) {
goto out;
}
}
PASSED();
/*-------------------------------------------------------------------------
* True color image test
*-------------------------------------------------------------------------
*/
TESTING("true color image");
/* Write image */
if ( H5IMmake_image_24bit( file_id, "Image2", WIDTH, HEIGHT, "INTERLACE_PIXEL", image_in2 ) )
goto out;
/* Read image */
if ( H5IMget_image_info( file_id, "Image2", &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
if ( H5IMread_image( file_id, "Image2", image_out2 ) < 0 )
goto out;
for (i = 0; i < height*width*planes; i++) {
if ( image_in2[i] != image_out2[i] ) {
goto out;
}
}
PASSED();
/*-------------------------------------------------------------------------
* H5IMget_npalettes test
*-------------------------------------------------------------------------
*/
TESTING("pallete functions");
if ( H5IMget_npalettes( file_id, "Image1", &npals ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* H5IMget_palette_info test
*-------------------------------------------------------------------------
*/
if ( H5IMget_palette_info( file_id, "Image1", 0, pal_dims_out ) < 0 )
goto out;
for (i = 0; i < 2; i++) {
if ( pal_dims[i] != pal_dims_out[i] ) {
goto out;
}
}
/*-------------------------------------------------------------------------
* H5IMget_palette test
*-------------------------------------------------------------------------
*/
if ( H5IMget_palette( file_id, "Image1", 0, pal_data_out ) < 0 )
goto out;
for (i = 0; i < 9*3; i++) {
if ( pal_data_in[i] != pal_data_out[i] ) {
goto out;
}
}
/*-------------------------------------------------------------------------
* H5IMis_image test
*-------------------------------------------------------------------------
*/
if ( H5IMis_image( file_id, "Image1" ) < 0 )
goto out;
if ( H5IMis_image( file_id, "Image2" ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* H5IMis_palette test
*-------------------------------------------------------------------------
*/
if ( H5IMis_palette( file_id, "Pallete" ) < 0 )
goto out;
/*-------------------------------------------------------------------------
* end tests
*-------------------------------------------------------------------------
*/
/* Close the file. */
if(H5Fclose( file_id ) < 0) goto out;
PASSED();
return 0;
out:
H5_FAILED();
return 1;
}