#include "config.h" #include "common.h" #if !defined HAVE_GETOPT_LONG # include "mygetopt.h" #elif defined HAVE_GETOPT_H # include #endif #include #include #include #include #if defined HAVE_GETOPT_LONG # define mygetopt getopt_long # define myoptind optind # define myoptarg optarg # define myoption option #endif #define MOREINFO "Try `%s --help' for more information.\n" int main(int argc, char *argv[]) { char *srcname = NULL, *dstname = NULL; pipi_image_t *src, *dst; int i, w = 0, h = 0, bpp = 24; for(;;) { int option_index = 0; static struct myoption long_options[] = { { "geometry", 1, NULL, 'g' }, { "bpp", 1, NULL, 'b' }, }; int c = mygetopt(argc, argv, "g:b:", long_options, &option_index); if(c == -1) break; switch(c) { case 'b': bpp = atoi(myoptarg); if(bpp != 32 && bpp != 24 && bpp != 16) { fprintf(stderr, "%s: invalid bpp -- %s\n", argv[0], myoptarg); return EXIT_FAILURE; } break; case 'g': w = atoi(myoptarg); if(strchr(myoptarg, 'x')) h = atoi(strchr(myoptarg, 'x') + 1); break; default: fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); printf(MOREINFO, argv[0]); return EXIT_FAILURE; } } for(i = myoptind; i < argc; i++) { if(!srcname) srcname = argv[i]; else dstname = argv[i]; } if(!srcname || !dstname) { fprintf(stderr, "%s: too few arguments\n", argv[0]); printf(MOREINFO, argv[0]); return EXIT_FAILURE; } src = pipi_load(srcname); if(!src) { fprintf(stderr, "%s: could not load `%s'\n", argv[0], srcname); return EXIT_FAILURE; } dst = pipi_resize(src, w, h); if(bpp == 16) pipi_dither_24to16(dst); pipi_save(dst, dstname); pipi_free(src); pipi_free(dst); return 0; }