From 7722c4c834891e088666945742fc1a5a3162b947 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Wed, 2 Jul 2008 10:25:26 -0500 Subject: [svn-r15311] added removal of more special characters from jpeg file name added a command line option -c to convert the output image to true or gray color --- hl/tools/h52jpeg/h52jpeg.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/hl/tools/h52jpeg/h52jpeg.c b/hl/tools/h52jpeg/h52jpeg.c index 785a078..8c0377d 100644 --- a/hl/tools/h52jpeg/h52jpeg.c +++ b/hl/tools/h52jpeg/h52jpeg.c @@ -40,13 +40,14 @@ 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:"; +static const char *s_opts = "hVvi:t:c:"; 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", require_arg, 'c' }, { NULL, 0, '\0' } }; @@ -58,6 +59,7 @@ typedef struct const char *template_name; const char *image_name; int image_type; + int convert_type; int verbose; } h52jpeg_opt_t; @@ -84,6 +86,7 @@ int main(int argc, const char *argv[]) { h52jpeg_opt_t opt; const char *image_type = NULL; + const char *convert_type = NULL; int op; /* initialze options to 0 */ @@ -125,6 +128,25 @@ int main(int argc, const char *argv[]) } break; + case 'c': + convert_type = opt_arg; + + + if ( HDstrcmp( convert_type, "grey" ) == 0 ) + { + opt.convert_type = 0; + } + else if ( HDstrcmp( convert_type, "true" ) == 0 ) + { + opt.convert_type = 1; + } + else + { + printf("<%s> is an invalid image type\n", image_type); + exit(EXIT_FAILURE); + } + + break; } /* switch */ @@ -172,7 +194,8 @@ 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(" -t T, --type=T Type of image (graycolor or truecolor)\n"); + printf(" -t T, --type=T Type of image to read (graycolor or truecolor)\n"); + printf(" -c T, --convert=T Convert image to type T (graycolor or truecolor)\n"); printf("\n"); @@ -296,7 +319,7 @@ out: * * Purpose: read HDF5 image/dataset, save jpeg image * - * Return: int + * Return: 0, all is fine, -1 not all is fine * *------------------------------------------------------------------------- */ @@ -411,7 +434,8 @@ out: * Parameters: template name (IN), image name (IN), jpeg name (IN/OUT) * * Purpose: build a name for the jpeg image file upon a template name - * and the HDF5 image name + * and the HDF5 image name. Replace the special characters + * "%", "@", "$", "/", ":", "&", and "*" with "_" * * Return: void * @@ -431,7 +455,14 @@ void make_jpeg_name( const char* template_name, const char* image_name, char* jp /* HDF5 path names might contain '/', replace with '_' */ for (j = 0; j < len; j++) { - if (jpeg_name[j] == '/') + if ( (jpeg_name[j] == '/') || + (jpeg_name[j] == '%') || + (jpeg_name[j] == '@') || + (jpeg_name[j] == '$') || + (jpeg_name[j] == '/') || + (jpeg_name[j] == ':') || + (jpeg_name[j] == '&') || + (jpeg_name[j] == '*') ) { jpeg_name[j] = '_'; } -- cgit v0.12