diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-30 04:11:10 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-30 04:11:10 (GMT) |
commit | 49d1722c303c7aed3b02052448111a0d1241df7a (patch) | |
tree | 848ea2afd8fa4cb38d60f97ab3cb43b11d5a579b /hl/tools/h52jpeg/h52jpeg.c | |
parent | 855dd92b0e72771df86ec81f5334ffd2add1bfb7 (diff) | |
download | hdf5-49d1722c303c7aed3b02052448111a0d1241df7a.zip hdf5-49d1722c303c7aed3b02052448111a0d1241df7a.tar.gz hdf5-49d1722c303c7aed3b02052448111a0d1241df7a.tar.bz2 |
[svn-r18195] Description:
Remove trailing whitespace from source code files.
Tested on:
None - just eyeballed
Diffstat (limited to 'hl/tools/h52jpeg/h52jpeg.c')
-rw-r--r-- | hl/tools/h52jpeg/h52jpeg.c | 282 |
1 files changed, 141 insertions, 141 deletions
diff --git a/hl/tools/h52jpeg/h52jpeg.c b/hl/tools/h52jpeg/h52jpeg.c index c4dacd1..80269ce 100644 --- a/hl/tools/h52jpeg/h52jpeg.c +++ b/hl/tools/h52jpeg/h52jpeg.c @@ -18,7 +18,7 @@ #include <stdio.h> #include <stdlib.h> -/* +/* * Include file for users of JPEG library. * system headers that define at least the typedefs FILE and size_t are needed before */ @@ -52,7 +52,7 @@ static struct long_options l_opts[] = { /* a structure that contains h52jpeg options */ -typedef struct +typedef struct { const char *file_name; const char *template_name; @@ -69,7 +69,7 @@ static int h52jpeg(h52jpeg_opt_t opt); 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); /*------------------------------------------------------------------------- @@ -77,7 +77,7 @@ static void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, * * Purpose: h52jpeg main program * - * main reads command line options and calls h52jpeg + * main reads command line options and calls h52jpeg * * Programmer: Pedro Vicente, pvn@hdfgroup.org * @@ -94,11 +94,11 @@ int main(int argc, const char *argv[]) /* initialze options to 0 */ memset(&opt,0,sizeof(h52jpeg_opt_t)); - + /* parse command line options */ - while ((op = get_option(argc, argv, s_opts, l_opts)) != EOF) + while ((op = get_option(argc, argv, s_opts, l_opts)) != EOF) { - switch ((char)op) + switch ((char)op) { case 'h': @@ -111,32 +111,32 @@ int main(int argc, const char *argv[]) case 'v': opt.verbose = 1; - break; - + break; + case 'i': opt.image_name = opt_arg; break; - + case 'c': opt.convert_true = 1; - + break; case 'p': opt.idx_palette = atoi(opt_arg); break; - + } /* switch */ - - + + } /* while */ - + /* check for file names to be processed */ - if ( argv[ opt_ind ] != NULL && argv[ opt_ind + 1 ] != NULL ) + if ( argv[ opt_ind ] != NULL && argv[ opt_ind + 1 ] != NULL ) { opt.file_name = argv[ opt_ind ]; - opt.template_name = argv[ opt_ind + 1 ]; + opt.template_name = argv[ opt_ind + 1 ]; } - + else { usage(progname); @@ -145,8 +145,8 @@ int main(int argc, const char *argv[]) if ( h52jpeg(opt) < 0 ) return 1; - - + + return 0; } @@ -173,9 +173,9 @@ static void usage(const char *prog) printf(" -i, --image Image name (full path in HDF5 file)\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(" P - is an integer, the palette index in the HDF5 image. Default is 0\n"); printf(" template - is a string used to name the jpeg file name; this name is made\n"); printf(" by concatenating this template with the HDF5 image name\n"); @@ -198,8 +198,8 @@ static void usage(const char *prog) printf("\n"); printf(" Exports the HDF5 image named <image> to a true color jpeg image, using\n"); printf(" the palette of index 1 in that image to do the conversion\n"); - - + + } /*------------------------------------------------------------------------- @@ -218,10 +218,10 @@ static int h52jpeg(h52jpeg_opt_t opt) hid_t fid; trav_table_t *travt = NULL; size_t i; - + /* open the HDF5 file */ - if (( fid = h5tools_fopen(opt.file_name, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t)0)) < 0) + if (( fid = h5tools_fopen(opt.file_name, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t)0)) < 0) { error_msg(progname, "cannot open file <%s>\n", opt.file_name ); return -1; @@ -231,81 +231,81 @@ static int h52jpeg(h52jpeg_opt_t opt) * object name was specified at command line *------------------------------------------------------------------------- */ - + if ( opt.image_name ) { /* read object, save jpeg image */ do_object(fid, opt, opt.image_name); - + } - + /*------------------------------------------------------------------------- * object name was not specified; traverse the file *------------------------------------------------------------------------- */ - + else - + { - + /* initialize traversal table */ trav_table_init(&travt); - + /* get the list of objects in the file */ if ( h5trav_gettable(fid, travt) < 0 ) goto out; - + /* search for images/datasets in file */ - for ( i = 0; i < travt->nobjs; i++) + for ( i = 0; i < travt->nobjs; i++) { - - switch ( travt->objs[i].type ) + + switch ( travt->objs[i].type ) { default: printf( "unknown object. Exiting ...\n" ); goto out; - + case H5TRAV_TYPE_GROUP: case H5TRAV_TYPE_NAMED_DATATYPE: case H5TRAV_TYPE_LINK: case H5TRAV_TYPE_UDLINK: - + break; - + case H5TRAV_TYPE_DATASET: /* read object, save jpeg image */ do_object(fid, opt, travt->objs[i].name); - break; /* H5TRAV_TYPE_DATASET */ - - } /* switch */ - - } /* i */ - - + break; /* H5TRAV_TYPE_DATASET */ + + } /* switch */ + + } /* i */ + + /* HDfree table */ trav_table_free(travt); - + } /* opt.image_name */ - - + + /* close */ if ( H5Fclose(fid) < 0 ) return -1; - + return 0; - + out: - H5E_BEGIN_TRY + H5E_BEGIN_TRY { H5Fclose(fid); - + } H5E_END_TRY; trav_table_free(travt); - + return -1; } @@ -329,29 +329,29 @@ 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); } - - + + if ( opt.verbose) - { + { if ( done ) { printf("saved to %s\n", jpeg_name ); @@ -360,12 +360,12 @@ int do_object(hid_t fid, h52jpeg_opt_t opt, const char* object_name) { printf("\n"); } - + } - + return 0; - + } @@ -394,22 +394,22 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na const char* name; int done; unsigned char* ibuf=NULL; - + name = image_name; - - done = 0; - + + done = 0; + if ( H5IMget_image_info( fid, name, &width, &height, &planes, interlace, &npals ) < 0 ) goto out; - - if (NULL == (ibuf = HDmalloc( (int)width * (int)height * (int)planes ))) + + if (NULL == (ibuf = HDmalloc( (int)width * (int)height * (int)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 @@ -422,12 +422,12 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na if ( planes == 3 || !opt.convert_true ) { /* write the jpeg file */ - write_JPEG_file (jpeg_name, - ibuf, - (int) height, - (int) width, - (int) planes); - + write_JPEG_file (jpeg_name, + ibuf, + (int) height, + (int) width, + (int) planes); + done = 1; } /*------------------------------------------------------------------------- @@ -444,12 +444,12 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na 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 *------------------------------------------------------------------------- @@ -463,68 +463,68 @@ int do_image(hid_t fid, h52jpeg_opt_t opt, const char* image_name, char* jpeg_na if ( opt.idx_palette >= npals ) { ipal = 0; - + if ( opt.verbose ) - { - printf("palette index <%d> does not exist. Using default...", + { + printf("palette index <%d> does not exist. Using default...", opt.idx_palette ); } } - - + + if ( H5IMget_palette_info( fid, name, ipal, pdims ) < 0 ) goto out; - - if (NULL == (pbuf = HDmalloc( (size_t)pdims[0] * (size_t)pdims[1] ))) + + if (NULL == (pbuf = HDmalloc( (size_t)pdims[0] * (size_t)pdims[1] ))) goto out; - - if (NULL == (tbuf = HDmalloc( (int)width * (int)height * 3 ))) + + if (NULL == (tbuf = HDmalloc( (int)width * (int)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); - + write_JPEG_file (jpeg_name, + tbuf, + (int) height, + (int) width, + 3); + done = 1; - + HDfree( pbuf ); HDfree( tbuf ); pbuf = NULL; - tbuf = 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 */ - + HDfree( ibuf ); ibuf = NULL; - + return done; - + out: - + return -1; - + } /*------------------------------------------------------------------------- @@ -533,7 +533,7 @@ 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. Replace the special characters + * and the HDF5 image name. Replace the special characters * '%', '@', '$', '/', ':', '&', ' ', and '*' with '_' * * Return: void @@ -550,7 +550,7 @@ void make_jpeg_name( const char* template_name, const char* image_name, char* jp HDstrcat( jpeg_name, image_name ); HDstrcat( jpeg_name, ".jpeg" ); len = HDstrlen( jpeg_name); - + /* HDF5 path names might contain '/', replace with '_' */ for (j = 0; j < len; j++) { @@ -563,11 +563,11 @@ void make_jpeg_name( const char* template_name, const char* image_name, char* jp (jpeg_name[j] == '&') || (jpeg_name[j] == ' ') || (jpeg_name[j] == '*') ) - { - jpeg_name[j] = '_'; + { + jpeg_name[j] = '_'; } } - + } /*------------------------------------------------------------------------- @@ -589,8 +589,8 @@ 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) + + for ( i = 0, j = 0; i < width * height; i++, j += 3) { unsigned char idx; unsigned char r; @@ -609,10 +609,10 @@ void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, unsign tbuf[j] = r; tbuf[j+1] = g; tbuf[j+2] = b; - + } - - + + } @@ -633,12 +633,12 @@ void convert_to_true( hsize_t width, hsize_t height, unsigned char* ibuf, unsign *------------------------------------------------------------------------- */ -static +static void write_JPEG_file(char *filename, /* JPEG file name */ JSAMPLE *image_buffer, /* Points to large array of R,G,B-order data */ int image_height, /* Number of rows in image */ int image_width, /* Number of columns in image */ - int planes) /* # of color components per pixel */ + int planes) /* # of color components per pixel */ { /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). @@ -660,9 +660,9 @@ void write_JPEG_file(char *filename, /* JPEG file name */ FILE * outfile; /* target file */ JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ int row_stride; /* physical row width in image buffer */ - + /* Step 1: allocate and initialize JPEG compression object */ - + /* We have to set up the error handler first, in case the initialization * step fails. (Unlikely, but it could happen if you are out of memory.) * This routine fills in the contents of struct jerr, and returns jerr's @@ -671,10 +671,10 @@ void write_JPEG_file(char *filename, /* JPEG file name */ cinfo.err = jpeg_std_error(&jerr); /* Now we can initialize the JPEG compression object. */ jpeg_create_compress(&cinfo); - + /* Step 2: specify data destination (eg, a file) */ /* Note: steps 2 and 3 can be done in either order. */ - + /* Here we use the library-supplied code to send compressed data to a * stdio stream. You can also write your own code to do something else. * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that @@ -685,22 +685,22 @@ void write_JPEG_file(char *filename, /* JPEG file name */ exit(1); } jpeg_stdio_dest(&cinfo, outfile); - + /* Step 3: set parameters for compression */ - + /* First we supply a description of the input image. * Four fields of the cinfo struct must be filled in: */ cinfo.image_width = image_width; /* image width and height, in pixels */ cinfo.image_height = image_height; cinfo.input_components = planes; /* # of color components per pixel */ - + /* colorspace of input image */ if (planes == 3) - cinfo.in_color_space = JCS_RGB; + cinfo.in_color_space = JCS_RGB; else if (planes == 1) - cinfo.in_color_space = JCS_GRAYSCALE; - + cinfo.in_color_space = JCS_GRAYSCALE; + /* Now use the library's routine to set default compression parameters. * (You must set at least cinfo.in_color_space before calling this, * since the defaults depend on the source color space.) @@ -710,24 +710,24 @@ void write_JPEG_file(char *filename, /* JPEG file name */ * Here we just illustrate the use of quality (quantization table) scaling: */ jpeg_set_quality(&cinfo, 100, TRUE /* limit to baseline-JPEG values */); - + /* Step 4: Start compressor */ - + /* TRUE ensures that we will write a complete interchange-JPEG file. * Pass TRUE unless you are very sure of what you're doing. */ jpeg_start_compress(&cinfo, TRUE); - + /* Step 5: while (scan lines remain to be written) */ /* jpeg_write_scanlines(...); */ - + /* Here we use the library's state variable cinfo.next_scanline as the * loop counter, so that we don't have to keep track ourselves. * To keep things simple, we pass one scanline per call; you can pass * more if you wish, though. */ row_stride = image_width * planes; /* JSAMPLEs per row in image_buffer */ - + while (cinfo.next_scanline < cinfo.image_height) { /* jpeg_write_scanlines expects an array of pointers to scanlines. * Here the array is only one element long, but you could pass @@ -736,18 +736,18 @@ void write_JPEG_file(char *filename, /* JPEG file name */ row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } - + /* Step 6: Finish compression */ - + jpeg_finish_compress(&cinfo); /* After finish_compress, we can close the output file. */ fclose(outfile); - + /* Step 7: release JPEG compression object */ - + /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_compress(&cinfo); - + /* And we're done! */ } |