summaryrefslogtreecommitdiffstats
path: root/hl/tools/h52jpeg/h52jpegtst.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/tools/h52jpeg/h52jpegtst.c')
-rw-r--r--hl/tools/h52jpeg/h52jpegtst.c213
1 files changed, 56 insertions, 157 deletions
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;
-
-}
-
-