source: libpipi/trunk/genethumb/genethumb.c @ 2263

Last change on this file since 2263 was 2263, checked in by Sam Hocevar, 13 years ago
  • Implemented 24 -> 16 bpp dithering.
  • Added the --bpp flag to genethumb.
File size: 1.8 KB
Line 
1#include "config.h"
2#include "common.h"
3
4#if !defined HAVE_GETOPT_LONG
5#   include "mygetopt.h"
6#elif defined HAVE_GETOPT_H
7#   include <getopt.h>
8#endif
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14#include <pipi.h>
15
16#if defined HAVE_GETOPT_LONG
17#   define mygetopt getopt_long
18#   define myoptind optind
19#   define myoptarg optarg
20#   define myoption option
21#endif
22
23#define MOREINFO "Try `%s --help' for more information.\n"
24
25int main(int argc, char *argv[])
26{
27    char *srcname = NULL, *dstname = NULL;
28    pipi_image_t *src, *dst;
29
30    int i, w = 0, h = 0, bpp = 24;
31
32    for(;;)
33    {
34        int option_index = 0;
35        static struct myoption long_options[] =
36        {
37            { "geometry",    1, NULL, 'g' },
38            { "bpp",         1, NULL, 'b' },
39        };
40        int c = mygetopt(argc, argv, "g:b:", long_options, &option_index);
41
42        if(c == -1)
43            break;
44
45        switch(c)
46        {
47        case 'b':
48            bpp = atoi(myoptarg);
49            if(bpp != 32 && bpp != 24 && bpp != 16)
50            {
51                fprintf(stderr, "%s: invalid bpp -- %s\n", argv[0], myoptarg);
52                return EXIT_FAILURE;
53            }
54            break;
55        case 'g':
56            w = atoi(myoptarg);
57            if(strchr(myoptarg, 'x'))
58                h = atoi(strchr(myoptarg, 'x') + 1);
59            break;
60        default:
61            fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
62            printf(MOREINFO, argv[0]);
63            return EXIT_FAILURE;
64        }
65    }
66
67    for(i = myoptind; i < argc; i++)
68    {
69        if(!srcname)
70            srcname = argv[i];
71        else
72            dstname = argv[i];
73    }
74
75    src = pipi_load(srcname);
76    dst = pipi_resize(src, w, h);
77    if(bpp == 16)
78        pipi_dither_24to16(dst);
79    pipi_save(dst, dstname);
80    pipi_free(src);
81    pipi_free(dst);
82
83    return 0;
84}
85
Note: See TracBrowser for help on using the repository browser.