source: libpipi/trunk/examples/dither.c @ 2666

Last change on this file since 2666 was 2666, checked in by Sam Hocevar, 14 years ago
  • Prefix dithering functions with _dither_ to avoid namespace cluttering.
File size: 1.6 KB
Line 
1#include "config.h"
2#include "common.h"
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include <pipi.h>
9
10int main(int argc, char *argv[])
11{
12    char *srcname = NULL, *dstname = NULL;
13    pipi_image_t *img, *newimg;
14
15    if(argc < 3)
16    {
17        fprintf(stderr, "%s: too few arguments\n", argv[0]);
18        fprintf(stderr, "Usage: %s <src> <method> <dest>\n", argv[0]);
19        fprintf(stderr, "Where <method> is one of:\n");
20        fprintf(stderr, "  1   Floyd-Steinberg (raster)\n");
21        fprintf(stderr, "  2   Floyd-Steinberg (serpentine)\n");
22        fprintf(stderr, "  3   Ostromoukhov (raster)\n");
23        fprintf(stderr, "  4   Ostromoukhov (serpentine)\n");
24        fprintf(stderr, "  5   Direct binary search\n");
25        return EXIT_FAILURE;
26    }
27
28    srcname = argv[1];
29    dstname = argv[3];
30
31    img = pipi_load(srcname);
32
33    switch(atoi(argv[2]))
34    {
35        case 6:
36            newimg = pipi_dither_dbs(img);
37            break;
38        case 5:
39            newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_SERPENTINE);
40            break;
41        case 4:
42            newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_RASTER);
43            break;
44        case 3:
45            newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_SERPENTINE);
46            break;
47        case 2:
48            newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_RASTER);
49            break;
50        case 1:
51        default:
52            newimg = pipi_dither_ordered(img);
53            break;
54    }
55
56    pipi_free(img);
57
58    pipi_save(newimg, dstname);
59    pipi_free(newimg);
60
61    return 0;
62}
63
Note: See TracBrowser for help on using the repository browser.