Enlightenment CVS committal Author : raster Project : e17 Module : libs/epeg
Dir : e17/libs/epeg/src/bin Modified Files: epeg_main.c Log Message: michel briand's cleanup of epeg test prog... :) =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/epeg/src/bin/epeg_main.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- epeg_main.c 10 Jun 2004 06:39:59 -0000 1.5 +++ epeg_main.c 26 Jul 2005 11:30:55 -0000 1.6 @@ -1,76 +1,123 @@ #include "epeg_main.h" +#include <unistd.h> +#include <stdio.h> +#include <getopt.h> +#include <string.h> -/* main */ +static int verbose_flag = 0; +static int thumb_width = 0; +static int thumb_height = 0; +static char *thumb_comment = NULL; +static struct option long_options[] = +{ + {"verbose", no_argument, 0, 'v'}, + {"width", required_argument, 0, 'w'}, + {"height", required_argument, 0, 'h'}, + {"comment", required_argument, 0, 'c'}, + {0, 0, 0, 0} +}; + +void +usage(const char *myname) +{ + printf("Usage: %s [options] input.jpg thumb.jpg\n" + " -v, --verbose\n" + " -w, --width=<width> set thumbnail width\n" + " -h, --height=<heigth> set thumbnail heigth\n" + " -c, --comment=<comment> put a comment in thumbnail\n", myname); + exit(0); +} int main(int argc, char **argv) { Epeg_Image *im; + int c; + int option_index = 0; + char *input_file = NULL, *output_file = NULL; - if (argc != 3) - { - printf("Usage: %s input.jpg thumb.jpg\n", argv[0]); - exit(0); - } - im = epeg_file_open(argv[1]); - if (!im) - { - printf("cannot open %s\n", argv[1]); - exit(-1); - } - { - const char *com; - Epeg_Thumbnail_Info info; - int w, h; - - com = epeg_comment_get(im); - if (com) printf("Comment: %s\n", com); - epeg_thumbnail_comments_get(im, &info); - if (info.mimetype) - { - printf("Thumb Mimetype: %s\n", info.mimetype); - if (info.uri) printf("Thumb URI: %s\n", info.uri); - printf("Thumb Mtime: %llu\n", info.mtime); - printf("Thumb Width: %i\n", info.w); - printf("Thumb Height: %i\n", info.h); - } - epeg_size_get(im, &w, &h); - printf("Image size: %ix%i\n", w, h); - } - - epeg_decode_size_set (im, 128, 96); + while ((c = getopt_long(argc, argv, "w:h:vc:", long_options, &option_index)) != -1) { + switch (c) { + case 0: + usage(argv[0]); + break; + case 'v': + verbose_flag = 1; + break; + case 'w': + thumb_width = strtol(optarg, NULL, 10); + if (thumb_width < 1) { + fprintf(stderr, "setting thumb_width to a default minimum of 64\n"); + thumb_width = 64; + } + if (verbose_flag) printf("thumb_width = %d\n", thumb_width); + break; + case 'h': + thumb_height = strtol(optarg, NULL, 10); + if (thumb_height < 1) { + fprintf(stderr, "setting thumb_height to a default minimum of 64\n"); + thumb_height = 64; + } + if (verbose_flag) printf("thumb_height = %d\n", thumb_height); + break; + case 'c': + thumb_comment = strdup(optarg); + if (verbose_flag) printf("thumb_comment = %s\n", thumb_comment); + break; + case '?': + usage(argv[0]); + break; + default: + abort(); + } + } + + if (optind < argc) { + if (optind < (argc-1)) { + input_file = argv[optind++]; + if (verbose_flag) printf("input_file = %s\n", input_file); + output_file = argv[optind]; + if (verbose_flag) printf("output_file = %s\n", output_file); + } else { + usage(argv[0]); + } + } + + if (!input_file || !output_file) usage(argv[0]); + + if (!thumb_comment) thumb_comment = "Smelly pants!"; -#if 0 - { - unsigned int *pixels; - -/* epeg_decode_colorspace_set(im, EPEG_ARGB32); */ - pixels = epeg_pixels_get(im, 0, 0, 128, 96); - if (pixels) - { - int x, y; - unsigned int *p; - -/* printf("Image pixels:\n"); */ - p = pixels; - for (y = 0; y < 96; y++) - { - for (x = 0; x < 128; x++) - { -/* printf("%08x ", p[0]);*/ - p ++; - } -/* printf("\n");*/ - } - epeg_pixels_free(im, pixels); - } - } -#endif + im = epeg_file_open(input_file); + if (!im) { + fprintf(stderr, "%s: cannot open %s\n", argv[0], input_file); + exit(-1); + } + + { + const char *com; + Epeg_Thumbnail_Info info; + int w, h; + + com = epeg_comment_get(im); + if (verbose_flag) if (com) printf("Comment: %s\n", com); + epeg_thumbnail_comments_get(im, &info); + if (info.mimetype) { + if (verbose_flag) printf("Thumb Mimetype: %s\n", info.mimetype); + if (verbose_flag) if (info.uri) printf("Thumb URI: %s\n", info.uri); + if (verbose_flag) printf("Thumb Mtime: %llu\n", info.mtime); + if (verbose_flag) printf("Thumb Width: %i\n", info.w); + if (verbose_flag) printf("Thumb Height: %i\n", info.h); + } + epeg_size_get(im, &w, &h); + if (verbose_flag) printf("Image size: %ix%i\n", w, h); + } + if (verbose_flag) printf("Thumb size: %dx%d\n", thumb_width, thumb_height); + epeg_decode_size_set(im, thumb_width, thumb_height); epeg_quality_set (im, 80); epeg_thumbnail_comments_enable (im, 1); - epeg_comment_set (im, "Smelly pants!"); - epeg_file_output_set (im, argv[2]); + epeg_comment_set (im, thumb_comment); + epeg_file_output_set (im, output_file); epeg_encode (im); epeg_close (im); return 0; ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs