summaryrefslogtreecommitdiffstats
path: root/hl/tools
diff options
context:
space:
mode:
Diffstat (limited to 'hl/tools')
-rw-r--r--hl/tools/h52jpeg/h52jpeg.c127
-rw-r--r--hl/tools/h52jpeg/h52jpegtst.c213
-rw-r--r--hl/tools/h52jpeg/testfiles/h52jpegtst.h5bin947613 -> 227613 bytes
3 files changed, 61 insertions, 279 deletions
diff --git a/hl/tools/h52jpeg/h52jpeg.c b/hl/tools/h52jpeg/h52jpeg.c
index 05a3e80..785a078 100644
--- a/hl/tools/h52jpeg/h52jpeg.c
+++ b/hl/tools/h52jpeg/h52jpeg.c
@@ -308,22 +308,10 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
hsize_t planes;
char interlace[20];
hssize_t npals;
- unsigned char* buf=NULL;
- H5T_class_t tclass;
- hid_t sid;
- hid_t did;
- hid_t tid;
- int rank;
- hsize_t dims[H5S_MAX_RANK];
- hsize_t maxdim[H5S_MAX_RANK];
- size_t size;
- hsize_t nelmts;
const char* name;
- size_t i;
- int j;
int done;
char jpeg_name[1024];
-
+
name = image_name;
/* build the jpeg file name */
@@ -344,6 +332,8 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
if ( H5IMis_image( fid, name ) )
{
+ unsigned char* buf=NULL;
+
if ( H5IMget_image_info( fid, name, &width, &height, &planes, interlace, &npals ) < 0 )
goto out;
@@ -369,7 +359,7 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
}
-
+
/*-------------------------------------------------------------------------
* HDF5 Image palette, ignore
*-------------------------------------------------------------------------
@@ -386,103 +376,7 @@ 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;
- if (( sid = H5Dget_space( did )) < 0 )
- goto out;
- if (( rank = H5Sget_simple_extent_ndims(sid)) < 0 )
- goto out;
- if (( tid = H5Dget_type( did )) < 0 )
- goto out;
- if (( tclass = H5Tget_class(tid)) < 0)
- goto out;
-
- if ( ( H5T_FLOAT == tclass || H5T_INTEGER == tclass) &&
- ( rank == 2 ) )
- {
-
- if ( H5Sget_simple_extent_dims( sid, dims, maxdim ) < 0 )
- goto out;
-
- size = H5Tget_size( tid );
-
- nelmts = 1;
- for ( j = 0; j < rank; j++)
- {
- nelmts *= dims[j];
- }
-
- if ( NULL == (buf = HDmalloc( (size_t)nelmts * size )))
- goto out;
- if ( H5Dread(did,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0 )
- goto out;
-
- height = dims[0];
- width = dims[1];
-
- if ( opt.image_type == 0 )
- planes = 1;
- else if ( opt.image_type == 1 )
- 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;
-
- }
-
-
-
- H5Sclose(sid);
- H5Tclose(tid);
- H5Dclose(did);
-
+ {
@@ -505,17 +399,6 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name)
return 0;
out:
- H5E_BEGIN_TRY
- {
-
- H5Sclose(sid);
- H5Tclose(tid);
- H5Dclose(did);
-
- } H5E_END_TRY;
-
- if ( buf != NULL )
- free( buf );
return -1;
diff --git a/hl/tools/h52jpeg/h52jpegtst.c b/hl/tools/h52jpeg/h52jpegtst.c
index b420168..d22be87 100644
--- a/hl/tools/h52jpeg/h52jpegtst.c
+++ b/hl/tools/h52jpeg/h52jpegtst.c
@@ -25,12 +25,8 @@
#define IMAGE2_NAME "image24bitpixel"
#define PAL_NAME "palette"
#define PAL_ENTRIES 256
-#define RANK 2
-#define HEIGHT 200
-#define WIDTH 300
-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 */
@@ -59,11 +55,7 @@ int main( void )
/* make images */
if ( make_images( fid ) < 0 )
goto out;
-
- /* make images */
- if ( make_datasets( fid ) < 0 )
- goto out;
-
+
/* close the file. */
H5Fclose( fid );
@@ -143,181 +135,88 @@ out:
/*-------------------------------------------------------------------------
- * Function: make_datasets
+ * read_data
+ * utility function to read ASCII image data
+ * the files have a header of the type
*
- * Purpose: generate datasets
+ * components
+ * n
+ * height
+ * n
+ * width
+ * n
+ *
+ * followed by the image data
*
*-------------------------------------------------------------------------
*/
-static int make_datasets( hid_t fid )
+
+static int read_data( const char* fname, /*IN*/
+ hsize_t *width, /*OUT*/
+ hsize_t *height /*OUT*/ )
{
- 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;
+ int i, n;
+ int color_planes;
+ char str[20];
+ FILE *f;
+ int w, h;
+ char *srcdir = getenv("srcdir"); /* the source directory */
+ char data_file[512]=""; /* buffer to hold name of existing data file */
- if ((sid = H5Screate_simple(RANK, dims, NULL)) < 0)
+ /*-------------------------------------------------------------------------
+ * compose the name of the file to open, using "srcdir", if appropriate
+ *-------------------------------------------------------------------------
+ */
+ strcpy(data_file, "");
+ if (srcdir)
{
- goto out;
+ strcpy(data_file, srcdir);
+ strcat(data_file, "/");
}
+ strcat(data_file,fname);
/*-------------------------------------------------------------------------
- * H5T_NATIVE_SHORT
+ * read
*-------------------------------------------------------------------------
- */
- if (NULL == (buf = HDmalloc( (size_t)width * (size_t)height * sizeof(short) )))
- goto out;
+ */
- for ( i = 0; i < height * width; i++)
+ f = fopen(data_file, "r");
+ if ( f == NULL )
{
- buf[i] = gbuf[i];
+ printf( "Could not open file %s. Try set $srcdir \n", data_file );
+ return -1;
}
- 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;
+ 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);
- free( buf );
-
- /*-------------------------------------------------------------------------
- * H5T_NATIVE_INT
- *-------------------------------------------------------------------------
- */
- if (NULL == (buf = HDmalloc( (size_t)width * (size_t)height * sizeof(int) )))
- goto out;
+ *width = (hsize_t)w;
+ *height = (hsize_t)h;
- for ( i = 0; i < height * width; i++)
+ if ( gbuf )
{
- buf[i] = gbuf[i];
+ free( gbuf );
+ gbuf=NULL;
}
- 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 );
-
-
-
+ gbuf = (unsigned char*) malloc (w * h * color_planes * sizeof( unsigned char ));
- /* close */
- H5Sclose(sid);
-
- return 0;
-
-out:
- H5E_BEGIN_TRY
+ for (i = 0; i < h * w * color_planes ; i++)
{
-
- H5Sclose(sid);
- H5Dclose(did);
-
- } H5E_END_TRY;
+ fscanf( f, "%d",&n );
+ gbuf[i] = (unsigned char)n;
+ }
+ fclose(f);
- return -1;
+ return 1;
}
-/*-------------------------------------------------------------------------
- * 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*/ )
-{
- int i, n;
- int color_planes;
- char str[20];
- FILE *f;
- 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
- *-------------------------------------------------------------------------
- */
- strcpy(data_file, "");
- if (srcdir)
- {
- strcpy(data_file, srcdir);
- 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 ( gbuf )
- {
- free( gbuf );
- gbuf=NULL;
- }
-
- gbuf = (unsigned char*) malloc (w * h * color_planes * sizeof( unsigned char ));
-
- for (i = 0; i < h * w * color_planes ; i++)
- {
- fscanf( f, "%d",&n );
- gbuf[i] = (unsigned char)n;
- }
- fclose(f);
-
- return 1;
-
-}
-
-
diff --git a/hl/tools/h52jpeg/testfiles/h52jpegtst.h5 b/hl/tools/h52jpeg/testfiles/h52jpegtst.h5
index e7ad02f..859abe8 100644
--- a/hl/tools/h52jpeg/testfiles/h52jpegtst.h5
+++ b/hl/tools/h52jpeg/testfiles/h52jpegtst.h5
Binary files differ