diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-07-15 14:51:48 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2008-07-15 14:51:48 (GMT) |
commit | 1572fb46e083a6d44235c77638752777106e86d3 (patch) | |
tree | 004969ea2eb861d1724f7f4bfcbc99d7cda683c7 | |
parent | bca3b0e1fc31a59113cbe1c1b9e28efa25b90bdb (diff) | |
download | hdf5-1572fb46e083a6d44235c77638752777106e86d3.zip hdf5-1572fb46e083a6d44235c77638752777106e86d3.tar.gz hdf5-1572fb46e083a6d44235c77638752777106e86d3.tar.bz2 |
[svn-r15366] cleaned warnings and unused features
tested: linux
-rw-r--r-- | hl/tools/h52jpeg/h52jpeg.c | 483 |
1 files changed, 231 insertions, 252 deletions
diff --git a/hl/tools/h52jpeg/h52jpeg.c b/hl/tools/h52jpeg/h52jpeg.c index a380741..07171a1 100644 --- a/hl/tools/h52jpeg/h52jpeg.c +++ b/hl/tools/h52jpeg/h52jpeg.c @@ -40,14 +40,13 @@ const char *progname = "h52jpeg"; int d_status = EXIT_SUCCESS; /* command-line options: The user can specify short or long-named parameters */ -static const char *s_opts = "hVvi:t:cp:"; +static const char *s_opts = "hVvi:cp:"; static struct long_options l_opts[] = { { "help", no_arg, 'h' }, { "version", no_arg, 'V' }, { "verbose", no_arg, 'v' }, { "image", require_arg, 'i' }, - { "type", require_arg, 't' }, - { "convert", no_arg, 'c' }, + { "convert", no_arg, 'c' },
{ "palette", require_arg, 'p' }, { NULL, 0, '\0' } }; @@ -60,7 +59,7 @@ typedef struct const char *template_name; const char *image_name; int image_type; - int convert_true; + int convert_true;
int idx_palette; int verbose; } h52jpeg_opt_t; @@ -69,10 +68,10 @@ typedef struct /* prototypes */ static void usage(const char *prog); static int h52jpeg(h52jpeg_opt_t opt); -static void make_jpeg_name( const char* template_name, const char* image_name, char* jpeg_name); +static void make_jpeg_name( const char* template_name, const char* image_name, char* jpeg_name);
static int do_object(hid_t fid, h52jpeg_opt_t opt, const char* image_name); static int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_name); -static void write_JPEG_file(char *filename, JSAMPLE *image_buffer, int image_height, int image_width, int planes); +static void write_JPEG_file(char *filename, JSAMPLE *image_buffer, int image_height, int image_width, int planes);
static void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, unsigned char* pbuf, unsigned char* tbuf); /*------------------------------------------------------------------------- @@ -89,11 +88,10 @@ static void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, int main(int argc, const char *argv[]) { h52jpeg_opt_t opt; - const char *image_type = NULL; int op; /* initialze options to 0 */ - memset(&opt,0,sizeof(h52jpeg_opt_t)); + memset(&opt,0,sizeof(h52jpeg_opt_t));
/* parse command line options */ while ((op = get_option(argc, argv, s_opts, l_opts)) != EOF) @@ -112,30 +110,13 @@ int main(int argc, const char *argv[]) case 'i': opt.image_name = opt_arg; break; - case 't': - image_type = opt_arg; - - if ( HDstrcmp( image_type, "grey" ) == 0 ) - { - opt.image_type = 0; - } - else if ( HDstrcmp( image_type, "true" ) == 0 ) - { - opt.image_type = 1; - } - else - { - printf("<%s> is an invalid image type\n", image_type); - exit(EXIT_FAILURE); - } - - break; + case 'c': opt.convert_true = 1; - break; - case 'p': - opt.idx_palette = atoi(opt_arg); + break;
+ case 'p':
+ opt.idx_palette = atoi(opt_arg);
break; } /* switch */ @@ -184,12 +165,11 @@ static void usage(const char *prog) printf(" -v, --verbose Verbose mode, print object information\n"); printf(" -V, --version Print HDF5 version number and exit\n"); printf(" -i, --image Image name (full path in HDF5 file)\n"); - printf(" -c, --convert Convert image from graycolor to truecolor\n"); + printf(" -c, --convert Convert image from graycolor to truecolor\n");
printf(" -p P, --palette=P Use HDF5 palette index P in conversion -c\n"); printf("\n"); - printf(" T - is a string, either <grey> or <true>\n"); printf(" P - is an integer, the palette index in the HDF5 image. Default is 0\n"); } @@ -299,82 +279,82 @@ out: return -1; } - - -/*------------------------------------------------------------------------- - * Function: do_object - * - * Parameters: HDF5 file id, command line options, an object name - * - * Purpose: read HDF5 object, save jpeg image - * - * Return: 0, all is fine, -1 not all is fine - * - *------------------------------------------------------------------------- - */ -static -int do_object(hid_t fid, h52jpeg_opt_t opt, const char* object_name) -{ - int done=0; /* return value from do_image */ - char jpeg_name[1024]; - - /* build the jpeg file name */ - make_jpeg_name( opt.template_name, object_name, jpeg_name); - - if ( opt.verbose) - { - printf("%s ...", object_name ); - } - - /*------------------------------------------------------------------------- - * HDF5 Image - *------------------------------------------------------------------------- - */ - - if ( H5IMis_image( fid, object_name ) ) - { - /* read image, save jpeg image */ - done = do_image(fid, opt, object_name, jpeg_name); - } - - /*------------------------------------------------------------------------- - * HDF5 Image palette, ignore - *------------------------------------------------------------------------- - */ - - else if ( H5IMis_palette( fid, object_name ) ) - { - - } - - /*------------------------------------------------------------------------- - * regular dataset - *------------------------------------------------------------------------- - */ - - else - { - - - } /* else */ - - - if ( opt.verbose) - { - if ( done ) - { - printf("saved to %s\n", jpeg_name ); - } - else - { - printf("\n"); - } - - } - - return 0; - - +
+
+/*-------------------------------------------------------------------------
+ * Function: do_object
+ *
+ * Parameters: HDF5 file id, command line options, an object name
+ *
+ * Purpose: read HDF5 object, save jpeg image
+ *
+ * Return: 0, all is fine, -1 not all is fine
+ *
+ *-------------------------------------------------------------------------
+ */
+static
+int do_object(hid_t fid, h52jpeg_opt_t opt, const char* object_name)
+{
+ int done=0; /* return value from do_image */
+ char jpeg_name[1024];
+
+ /* build the jpeg file name */
+ make_jpeg_name( opt.template_name, object_name, jpeg_name);
+
+ if ( opt.verbose)
+ {
+ printf("%s ...", object_name );
+ }
+
+ /*-------------------------------------------------------------------------
+ * HDF5 Image
+ *-------------------------------------------------------------------------
+ */
+
+ if ( H5IMis_image( fid, object_name ) )
+ {
+ /* read image, save jpeg image */
+ done = do_image(fid, opt, object_name, jpeg_name);
+ }
+
+ /*-------------------------------------------------------------------------
+ * HDF5 Image palette, ignore
+ *-------------------------------------------------------------------------
+ */
+
+ else if ( H5IMis_palette( fid, object_name ) )
+ {
+
+ }
+
+ /*-------------------------------------------------------------------------
+ * regular dataset
+ *-------------------------------------------------------------------------
+ */
+
+ else
+ {
+
+
+ } /* else */
+
+
+ if ( opt.verbose)
+ {
+ if ( done )
+ {
+ printf("saved to %s\n", jpeg_name );
+ }
+ else
+ {
+ printf("\n");
+ }
+
+ }
+
+ return 0;
+
+
} @@ -398,7 +378,7 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na char interlace[20]; hssize_t npals; const char* name; - int done; + int done;
unsigned char* ibuf=NULL; name = image_name; @@ -411,116 +391,115 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na if (NULL == (ibuf = HDmalloc( (size_t)width * (size_t)height * (size_t)planes ))) goto out; - if ( H5IMread_image( fid, name, ibuf ) < 0 ) - { - goto out; - } - - /*------------------------------------------------------------------------- - * no conversion to true color requested or true color image, just save what we found - * this will result either in - * - * 24bit HDF5 ---> true color jpeg - * 8bit HDF5 ---> grey color jpeg - * - *------------------------------------------------------------------------- - */ - if ( planes == 3 || !opt.convert_true ) + if ( H5IMread_image( fid, name, ibuf ) < 0 )
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * no conversion to true color requested or true color image, just save what we found
+ * this will result either in
+ *
+ * 24bit HDF5 ---> true color jpeg
+ * 8bit HDF5 ---> grey color jpeg
+ *
+ *-------------------------------------------------------------------------
+ */
+ if ( planes == 3 || !opt.convert_true )
{ /* write the jpeg file */ write_JPEG_file (jpeg_name, ibuf, (int) height, (int) width, - (int) planes); - - done = 1; - } - /*------------------------------------------------------------------------- - * conversion to truecolor - * this will result in - * - * 8bit HDF5 ---> true color jpeg - * - *------------------------------------------------------------------------- - */ - else if (opt.convert_true && planes == 1 ) - { - hssize_t npals; /* number of palettes */ - hsize_t pdims[2]; /* palette dimensions */ - unsigned char *pbuf=NULL;/* palette array */ - unsigned char *tbuf=NULL;/* true color array */ - int ipal; /* palette to use */ - - if ( H5IMget_npalettes( fid, name, &npals ) < 0 ) - { - goto out; - } - - /*------------------------------------------------------------------------- - * there are palettes - *------------------------------------------------------------------------- - */ - if ( npals > 0 ) - { - /* use either the default (0) palette or a requested one */ - ipal = ( opt.idx_palette > 0 ) ? opt.idx_palette : 0; - - /* the requested palette may not exist . use the default */ - if ( opt.idx_palette >= npals ) - { - ipal = 0; - - if ( opt.verbose ) - { - printf("palette index <%d> does not exist. Using default...", - ipal ); - } - } - - - if ( H5IMget_palette_info( fid, name, ipal, pdims ) < 0 ) - goto out; - - if (NULL == (pbuf = HDmalloc( (size_t)pdims[0] * (size_t)pdims[1] ))) - goto out; - - if (NULL == (tbuf = HDmalloc( (size_t)width * (size_t)height * 3 ))) - goto out; - - if ( H5IMget_palette( fid, name, ipal, pbuf ) < 0 ) - goto out; - - /* convert indexed image to true color image */ - convert_to_true(width, height, ibuf, pbuf, tbuf); - - /* write the jpeg file */ - write_JPEG_file (jpeg_name, - tbuf, - (int) height, - (int) width, - 3); - - done = 1; - - free( pbuf ); - free( tbuf ); - pbuf = NULL; - tbuf = NULL; - } - /*------------------------------------------------------------------------- - * there are no palettes - *------------------------------------------------------------------------- - */ - else - { - done = 0; - if ( opt.verbose ) - { - printf("image <%s> has no palette...", name ); - } - } /* no palettes */ - + (int) planes);
+
+ done = 1;
+ }
+ /*-------------------------------------------------------------------------
+ * conversion to truecolor
+ * this will result in
+ *
+ * 8bit HDF5 ---> true color jpeg
+ *
+ *-------------------------------------------------------------------------
+ */
+ else if (opt.convert_true && planes == 1 )
+ {
+ hsize_t pdims[2]; /* palette dimensions */
+ unsigned char *pbuf=NULL;/* palette array */
+ unsigned char *tbuf=NULL;/* true color array */
+ int ipal; /* palette to use */
+
+ if ( H5IMget_npalettes( fid, name, &npals ) < 0 )
+ {
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------------
+ * there are palettes
+ *-------------------------------------------------------------------------
+ */
+ if ( npals > 0 )
+ {
+ /* use either the default (0) palette or a requested one */
+ ipal = ( opt.idx_palette > 0 ) ? opt.idx_palette : 0;
+
+ /* the requested palette may not exist . use the default */
+ if ( opt.idx_palette >= npals )
+ {
+ ipal = 0;
+
+ if ( opt.verbose )
+ {
+ printf("palette index <%d> does not exist. Using default...",
+ ipal );
+ }
+ }
+
+
+ if ( H5IMget_palette_info( fid, name, ipal, pdims ) < 0 )
+ goto out;
+
+ if (NULL == (pbuf = HDmalloc( (size_t)pdims[0] * (size_t)pdims[1] )))
+ goto out;
+
+ if (NULL == (tbuf = HDmalloc( (size_t)width * (size_t)height * 3 )))
+ goto out;
+
+ if ( H5IMget_palette( fid, name, ipal, pbuf ) < 0 )
+ goto out;
+
+ /* convert indexed image to true color image */
+ convert_to_true(width, height, ibuf, pbuf, tbuf);
+
+ /* write the jpeg file */
+ write_JPEG_file (jpeg_name,
+ tbuf,
+ (int) height,
+ (int) width,
+ 3);
+
+ done = 1;
+
+ free( pbuf );
+ free( tbuf );
+ pbuf = NULL;
+ tbuf = NULL;
+ }
+ /*-------------------------------------------------------------------------
+ * there are no palettes
+ *-------------------------------------------------------------------------
+ */
+ else
+ {
+ done = 0;
+ if ( opt.verbose )
+ {
+ printf("image <%s> has no palette...", name );
+ }
+ } /* no palettes */
+
} /* conversion to truecolor */ free( ibuf ); @@ -580,46 +559,46 @@ void make_jpeg_name( const char* template_name, const char* image_name, char* jp } -/*------------------------------------------------------------------------- - * Function: convert_to_true - * - * Parameters: - * - * Purpose: convert a greycolor buffer to a true color using a palette buffer - * - * Return: - * - *------------------------------------------------------------------------- - */ -static -void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, unsigned char* pbuf, unsigned char* tbuf) -{ - hsize_t i, j; - - for ( i = 0, j = 0; i < width * height; i++, j += 3) - { - unsigned char idx; - unsigned char r; - unsigned char g; - unsigned char b; - - /* get the index from the grey image */ - idx = ibuf[i]; - - /* get the RGB color */ - r = pbuf[3*idx]; - g = pbuf[3*idx+1]; - b = pbuf[3*idx+2]; - - /* define the color buffer */ - tbuf[j] = r; - tbuf[j+1] = g; - tbuf[j+2] = b; - - } - - -} +/*-------------------------------------------------------------------------
+ * Function: convert_to_true
+ *
+ * Parameters:
+ *
+ * Purpose: convert a greycolor buffer to a true color using a palette buffer
+ *
+ * Return:
+ *
+ *-------------------------------------------------------------------------
+ */
+static
+void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, unsigned char* pbuf, unsigned char* tbuf)
+{
+ hsize_t i, j;
+
+ for ( i = 0, j = 0; i < width * height; i++, j += 3)
+ {
+ unsigned char idx;
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+
+ /* get the index from the grey image */
+ idx = ibuf[i];
+
+ /* get the RGB color */
+ r = pbuf[3*idx];
+ g = pbuf[3*idx+1];
+ b = pbuf[3*idx+2];
+
+ /* define the color buffer */
+ tbuf[j] = r;
+ tbuf[j+1] = g;
+ tbuf[j+2] = b;
+
+ }
+
+
+}
/* |