| 12 | | #include "header.h" |
|---|
| 13 | | #include "resize.h" |
|---|
| 14 | | |
|---|
| 15 | | static void |
|---|
| 16 | | version (void) |
|---|
| 17 | | { |
|---|
| 18 | | printf ("FastPhoto " VERSION "\n"); |
|---|
| 19 | | } |
|---|
| 20 | | |
|---|
| 21 | | static void |
|---|
| 22 | | usage (void) |
|---|
| 23 | | { |
|---|
| 24 | | printf ("Usage: fastphoto [options] infile [outfile]\n"); |
|---|
| 25 | | printf ("Rescale a JPEG image\n"); |
|---|
| 26 | | printf ("\nScaling options\n"); |
|---|
| 27 | | printf (" -x, --width Set the width of the output image\n"); |
|---|
| 28 | | printf (" -y, --height Set the height of the output image\n"); |
|---|
| 29 | | printf (" -s, --scale Set a percentage to scale the image by\n"); |
|---|
| 30 | | printf ("\nOutput options\n"); |
|---|
| 31 | | printf (" -g, --gray Output grayscale\n"); |
|---|
| 32 | | printf (" -q, --quality Set the output quality 0-100\n"); |
|---|
| 33 | | printf ("\nInformational options\n"); |
|---|
| 34 | | printf (" -i, --info Print information about image\n"); |
|---|
| 35 | | printf ("\nMiscellaneous options\n"); |
|---|
| 36 | | printf (" -h, --help Display this help and exit\n"); |
|---|
| 37 | | printf (" -v, --version Output version information and exit\n"); |
|---|
| 38 | | printf ("\n"); |
|---|
| 39 | | } |
|---|
| 40 | | |
|---|
| 41 | | static int |
|---|
| 42 | | cmd_main (fastphoto_t * params, int argc, char * argv[]) |
|---|
| 43 | | { |
|---|
| 44 | | int err = 0; |
|---|
| 45 | | int show_help = 0; |
|---|
| 46 | | int show_version = 0; |
|---|
| 47 | | int i; |
|---|
| 48 | | |
|---|
| 49 | | while (1) { |
|---|
| 50 | | char * optstring = "hvx:y:s:gq:i"; |
|---|
| 51 | | |
|---|
| 52 | | #ifdef HAVE_GETOPT_LONG |
|---|
| 53 | | static struct option long_options[] = { |
|---|
| 54 | | {"help", no_argument, 0, 'h'}, |
|---|
| 55 | | {"version", no_argument, 0, 'v'}, |
|---|
| 56 | | {"width", required_argument, 0, 'x'}, |
|---|
| 57 | | {"height", required_argument, 0, 'y'}, |
|---|
| 58 | | {"scale", required_argument, 0, 's'}, |
|---|
| 59 | | {"gray", no_argument, 0, 'g'}, |
|---|
| 60 | | {"quality", required_argument, 0, 'q'}, |
|---|
| 61 | | {"info", no_argument, 0, 'i'}, |
|---|
| 62 | | {0,0,0,0} |
|---|
| 63 | | }; |
|---|
| 64 | | |
|---|
| 65 | | i = getopt_long (argc, argv, optstring, long_options, NULL); |
|---|
| 66 | | #else |
|---|
| 67 | | i = getopt (argc, argv, optstring); |
|---|
| 68 | | #endif |
|---|
| 69 | | |
|---|
| 70 | | if (i == -1) break; |
|---|
| 71 | | if (i == ':') { |
|---|
| 72 | | usage (); |
|---|
| 73 | | return 1; |
|---|
| 74 | | } |
|---|
| 75 | | |
|---|
| 76 | | switch (i) { |
|---|
| 77 | | case 'h': /* help */ |
|---|
| 78 | | show_help = 1; |
|---|
| 79 | | break; |
|---|
| 80 | | case 'v': /* version */ |
|---|
| 81 | | show_version = 1; |
|---|
| 82 | | break; |
|---|
| 83 | | case 'x': /* width */ |
|---|
| 84 | | params->x = atoi (optarg); |
|---|
| 85 | | break; |
|---|
| 86 | | case 'y': /* height */ |
|---|
| 87 | | params->y = atoi (optarg); |
|---|
| 88 | | break; |
|---|
| 89 | | case 's': /* scale */ |
|---|
| 90 | | params->scale = atoi (optarg); |
|---|
| 91 | | break; |
|---|
| 92 | | case 'g': /* gray */ |
|---|
| 93 | | params->gray = 1; |
|---|
| 94 | | break; |
|---|
| 95 | | case 'q': /* quality */ |
|---|
| 96 | | params->quality = atoi (optarg); |
|---|
| 97 | | break; |
|---|
| 98 | | case 'i': /* info */ |
|---|
| 99 | | params->info = 1; |
|---|
| 100 | | break; |
|---|
| 101 | | default: |
|---|
| 102 | | break; |
|---|
| 103 | | } |
|---|
| 104 | | |
|---|
| 105 | | } |
|---|
| 106 | | |
|---|
| 107 | | if (show_version) { |
|---|
| 108 | | version (); |
|---|
| 109 | | } |
|---|
| 110 | | |
|---|
| 111 | | if (show_help) { |
|---|
| 112 | | usage (); |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | if (show_version || show_help) { |
|---|
| 116 | | return 0; |
|---|
| 117 | | } |
|---|
| 118 | | |
|---|
| 119 | | if (optind >= argc) { |
|---|
| 120 | | usage (); |
|---|
| 121 | | return 1; |
|---|
| 122 | | } |
|---|
| 123 | | |
|---|
| 124 | | params->in.name = argv[optind++]; |
|---|
| 125 | | |
|---|
| 126 | | if (optind >= argc) { |
|---|
| 127 | | memory_init (params); |
|---|
| 128 | | } else { |
|---|
| 129 | | params->out.name = argv[optind++]; |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | err = resize (params); |
|---|
| 133 | | |
|---|
| 134 | | if (!err) |
|---|
| 135 | | send_memory (params); |
|---|
| 136 | | |
|---|
| 137 | | return err; |
|---|
| 138 | | } |
|---|
| 139 | | |
|---|
| | 9 | #include "cmd.h" |
|---|
| | 10 | |
|---|