summaryrefslogtreecommitdiffstats
path: root/tools/h52jpeg
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2008-06-27 19:15:53 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2008-06-27 19:15:53 (GMT)
commite31678c3a2407951de3bca57578a5347abd45cbd (patch)
treee52e8f34eba11a2b9a8731ae2e221ab310b5f76f /tools/h52jpeg
parent8776008f6648362656cf5a9208e67382137cc40b (diff)
downloadhdf5-e31678c3a2407951de3bca57578a5347abd45cbd.zip
hdf5-e31678c3a2407951de3bca57578a5347abd45cbd.tar.gz
hdf5-e31678c3a2407951de3bca57578a5347abd45cbd.tar.bz2
[svn-r15291] Implementation of generating more use cases (datasets of several types) for the test generator program and file
Implementation of transforming 2D datasets with integer and float classes to 8bit acceptable by the jpeg library. tested: windows, linux
Diffstat (limited to 'tools/h52jpeg')
-rw-r--r--tools/h52jpeg/h52jpeg.c68
-rw-r--r--tools/h52jpeg/h52jpegtst.c176
-rw-r--r--tools/h52jpeg/testfiles/h52jpegtst.h5bin227613 -> 947613 bytes
3 files changed, 220 insertions, 24 deletions
diff --git a/tools/h52jpeg/h52jpeg.c b/tools/h52jpeg/h52jpeg.c
index 84fa145..05a3e80 100644
--- a/tools/h52jpeg/h52jpeg.c
+++ b/tools/h52jpeg/h52jpeg.c
@@ -69,7 +69,6 @@ static void make_jpeg_name( const char* template_name, const char* image_name, c
static int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name);
static void write_JPEG_file(char *filename, JSAMPLE *image_buffer, int image_height, int image_width, int planes);
-
/*-------------------------------------------------------------------------
* Function: main
*
@@ -111,7 +110,7 @@ int main(int argc, const char *argv[])
image_type = opt_arg;
- if ( HDstrcmp( image_type, "gray" ) == 0 )
+ if ( HDstrcmp( image_type, "grey" ) == 0 )
{
opt.image_type = 0;
}
@@ -177,7 +176,7 @@ static void usage(const char *prog)
printf("\n");
- printf(" T - is a string, either <gray> or <true>\n");
+ printf(" T - is a string, either <grey> or <true>\n");
}
@@ -309,7 +308,7 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
hsize_t planes;
char interlace[20];
hssize_t npals;
- void *buf=NULL;
+ unsigned char* buf=NULL;
H5T_class_t tclass;
hid_t sid;
hid_t did;
@@ -320,6 +319,7 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
size_t size;
hsize_t nelmts;
const char* name;
+ size_t i;
int j;
int done;
char jpeg_name[1024];
@@ -354,7 +354,6 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
goto out;
/* write the jpeg file */
- /* write the jpeg file */
write_JPEG_file (jpeg_name,
buf,
(int) height,
@@ -370,6 +369,16 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
}
+
+ /*-------------------------------------------------------------------------
+ * HDF5 Image palette, ignore
+ *-------------------------------------------------------------------------
+ */
+
+ else if ( H5IMis_palette( fid, name ) )
+ {
+
+ }
/*-------------------------------------------------------------------------
* regular dataset
@@ -378,6 +387,8 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
else
{
+
+ unsigned char* image_buffer = NULL;
if (( did = H5Dopen2( fid, name, H5P_DEFAULT )) < 0)
goto out;
@@ -416,12 +427,53 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
if ( opt.image_type == 0 )
planes = 1;
else if ( opt.image_type == 1 )
- planes = 3;
+ planes = 3;
+
+
+ if ( NULL == (image_buffer = HDmalloc( (size_t)nelmts * sizeof (unsigned char) )))
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * convert the data to unsigned char
+ *
+ *-------------------------------------------------------------------------
+ */
+
+ {
+ double min = DBL_MAX;
+ double max = -DBL_MAX;
+ double ratio;
+
+ /* search for the minimum and maximum */
+ for ( i = 0; i < nelmts; i++)
+ {
+ if ( buf[i] < min) min = buf[i];
+ if ( buf[i] > max) max = buf[i];
+ }
+ /* converts the data based on the ratio to a 0-255 range */
+ ratio = (min == max) ? 1.0 : (double)(255.0/(max-min));
+ for ( i = 0; i < nelmts; i++)
+ {
+ image_buffer[i] = (unsigned char)ceil( (( buf[i] - min ) / ratio) );
+ }
+
+ }
-
+ /* write the jpeg file */
+ write_JPEG_file (jpeg_name,
+ image_buffer,
+ (int) height,
+ (int) width,
+ (int) planes);
+
+ free( image_buffer );
free( buf );
buf = NULL;
+ image_buffer = NULL;
+ done = 1;
}
@@ -504,6 +556,8 @@ void make_jpeg_name( const char* template_name, const char* image_name, char* jp
}
+
+
/*
* Sample routine for JPEG compression.
*
diff --git a/tools/h52jpeg/h52jpegtst.c b/tools/h52jpeg/h52jpegtst.c
index 3a4b277..b420168 100644
--- a/tools/h52jpeg/h52jpegtst.c
+++ b/tools/h52jpeg/h52jpegtst.c
@@ -15,6 +15,7 @@
#include "hdf5.h"
#include "hdf5_hl.h"
+#include "H5private.h"
#include <stdlib.h>
#include <string.h>
@@ -24,23 +25,72 @@
#define IMAGE2_NAME "image24bitpixel"
#define PAL_NAME "palette"
#define PAL_ENTRIES 256
+#define RANK 2
+#define HEIGHT 200
+#define WIDTH 300
-static int read_data(const char* file_name, hsize_t *width, hsize_t *height );
+
+static int make_datasets( hid_t fid );
+static int make_images( hid_t fid );
+static int read_data(const char* file_name, hsize_t *width, hsize_t *height );
unsigned char *gbuf = 0; /* global buffer for image data */
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: h52jpegtst main program. Generate images and datasets to be used
+ * by h52jpeg tests
+ *
+ * Programmer: Pedro Vicente, pvn@hdfgroup.org
+ *
+ * Date: May 30, 2008
+ *
+ *-------------------------------------------------------------------------
+ */
int main( void )
{
- hid_t fid; /* HDF5 file identifier */
+ hid_t fid; /* HDF5 file identifier */
+
+ /* create a new HDF5 file using default properties. */
+ if (( fid = H5Fcreate( "h52jpegtst.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT )) < 0 )
+ return 1;
+
+ /* make images */
+ if ( make_images( fid ) < 0 )
+ goto out;
+
+ /* make images */
+ if ( make_datasets( fid ) < 0 )
+ goto out;
+
+ /* close the file. */
+ H5Fclose( fid );
+
+ return 0;
+
+out:
+ printf("Error on return function...Exiting\n");
+ H5Fclose( fid );
+ return 1;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: make_images
+ *
+ * Purpose: generate images
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static int make_images( hid_t fid )
+{
hsize_t width; /* width of image */
hsize_t height; /* height of image */
unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */
hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */
int i, n;
- /* create a new HDF5 file using default properties. */
- if (( fid = H5Fcreate( "h52jpegtst.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT )) < 0 )
- return 1;
-
/* read first data file */
if ( read_data( DATA_FILE1, &width, &height ) < 0 )
goto out;
@@ -50,9 +100,9 @@ int main( void )
goto out;
/*-------------------------------------------------------------------------
- * 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++)
{
pal[i] =n; /* red */
@@ -69,9 +119,9 @@ int main( void )
goto out;
/*-------------------------------------------------------------------------
- * true color image example with pixel interlace in RGB type
- *-------------------------------------------------------------------------
- */
+ * true color image example with pixel interlace in RGB type
+ *-------------------------------------------------------------------------
+ */
/* read second data file */
if ( read_data( DATA_FILE2, &width, &height ) < 0 )
@@ -80,16 +130,108 @@ int main( void )
/* make dataset */
if ( H5IMmake_image_24bit( fid, IMAGE2_NAME, width, height, "INTERLACE_PIXEL", gbuf ) < 0 )
goto out;
+
+ return 0;
- /* close the file. */
- H5Fclose( fid );
+out:
+ printf("Error on return function...Exiting\n");
+ return -1;
+}
+
+
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: make_datasets
+ *
+ * Purpose: generate datasets
+ *
+ *-------------------------------------------------------------------------
+ */
+static int make_datasets( hid_t fid )
+{
+ hsize_t width; /* width of image */
+ hsize_t height; /* height of image */
+ hid_t sid;
+ hid_t did;
+ hsize_t dims[2];
+ unsigned char *buf;
+ hsize_t i;
+
+ /* read a data file with 8bit data */
+ if ( read_data( DATA_FILE1, &width, &height ) < 0 )
+ goto out;
+
+ dims[0] = height;
+ dims[1] = width;
+
+ if ((sid = H5Screate_simple(RANK, dims, NULL)) < 0)
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * H5T_NATIVE_SHORT
+ *-------------------------------------------------------------------------
+ */
+ if (NULL == (buf = HDmalloc( (size_t)width * (size_t)height * sizeof(short) )))
+ goto out;
+
+ for ( i = 0; i < height * width; i++)
+ {
+ buf[i] = gbuf[i];
+ }
+
+ if ((did = H5Dcreate2(fid, "short", H5T_NATIVE_SHORT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5Dwrite(did, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ goto out;
+ if (H5Dclose(did)< 0)
+ goto out;
+
+ free( buf );
+
+ /*-------------------------------------------------------------------------
+ * H5T_NATIVE_INT
+ *-------------------------------------------------------------------------
+ */
+ if (NULL == (buf = HDmalloc( (size_t)width * (size_t)height * sizeof(int) )))
+ goto out;
+
+ for ( i = 0; i < height * width; i++)
+ {
+ buf[i] = gbuf[i];
+ }
+
+ if ((did = H5Dcreate2(fid, "int", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto out;
+ if (H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
+ goto out;
+ if (H5Dclose(did)< 0)
+ goto out;
+
+ free( buf );
+
+
+
+
+ /* close */
+ H5Sclose(sid);
return 0;
out:
- printf("Error on return function...Exiting\n");
- H5Fclose( fid );
- return 1;
+ H5E_BEGIN_TRY
+ {
+
+ H5Sclose(sid);
+ H5Dclose(did);
+
+ } H5E_END_TRY;
+
+ return -1;
+
}
diff --git a/tools/h52jpeg/testfiles/h52jpegtst.h5 b/tools/h52jpeg/testfiles/h52jpegtst.h5
index 39bded7..e7ad02f 100644
--- a/tools/h52jpeg/testfiles/h52jpegtst.h5
+++ b/tools/h52jpeg/testfiles/h52jpegtst.h5
Binary files differ