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

Last change on this file since 2671 was 2671, checked in by Sam Hocevar, 14 years ago
  • random.c: implement random dithering using a deterministic pseudo-RNG.
File size: 1.7 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   random dithering\n");
21        fprintf(stderr, "  2   Floyd-Steinberg (raster)\n");
22        fprintf(stderr, "  3   Floyd-Steinberg (serpentine)\n");
23        fprintf(stderr, "  4   Ostromoukhov (raster)\n");
24        fprintf(stderr, "  5   Ostromoukhov (serpentine)\n");
25        fprintf(stderr, "  6   Direct binary search\n");
26        return EXIT_FAILURE;
27    }
28
29    srcname = argv[1];
30    dstname = argv[3];
31
32    img = pipi_load(srcname);
33
34    switch(atoi(argv[2]))
35    {
36        case 7:
37            newimg = pipi_dither_dbs(img);
38            break;
39        case 6:
40            newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_SERPENTINE);
41            break;
42        case 5:
43            newimg = pipi_dither_ostromoukhov(img, PIPI_SCAN_RASTER);
44            break;
45        case 4:
46            newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_SERPENTINE);
47            break;
48        case 3:
49            newimg = pipi_dither_floydsteinberg(img, PIPI_SCAN_RASTER);
50            break;
51        case 2:
52            newimg = pipi_dither_ordered(img);
53            break;
54        case 1:
55        default:
56            newimg = pipi_dither_random(img);
57            break;
58    }
59
60    pipi_free(img);
61
62    pipi_save(newimg, dstname);
63    pipi_free(newimg);
64
65    return 0;
66}
67
Note: See TracBrowser for help on using the repository browser.