Debian Codegraph @

examples/hsv.c

raw
1 /*
2 * hsv libcaca HSV rendering test program
3 * Copyright (c) 2003-2012 Sam Hocevar <[email protected]>
4 * All Rights Reserved
5 *
6 * This program is free software. It comes without any warranty, to
7 * the extent permitted by applicable law. You can redistribute it
8 * and/or modify it under the terms of the Do What the Fuck You Want
9 * to Public License, Version 2, as published by Sam Hocevar. See
10 * http://www.wtfpl.net/ for more details.
11 */
12
13 #include "config.h"
14
15 #if !defined(__KERNEL__)
16 # include <stdio.h>
17 #endif
18
19 #include "caca.h"
20
21 uint32_t buffer[256*256];
22
23 int main(int argc, char *argv[])
24 {
25 caca_display_t *dp;
26 caca_canvas_t *cv;
27
28 caca_dither_t *dither;
29 int x, y;
30
31 dp = caca_create_display(NULL);
32 if(dp == NULL)
33 {
34 printf("Can't create display\n");
35 return -1;
36 }
37
38 cv = caca_get_canvas(dp);
39
40 for(y = 0; y < 256; y++)
41 for(x = 0; x < 256; x++)
42 {
43 buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0);
44 }
45
46 dither = caca_create_dither(32, 256, 256, 4 * 256,
47 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
48 caca_dither_bitmap(caca_get_canvas(dp), 0, 0, caca_get_canvas_width(cv),
49 caca_get_canvas_height(cv), dither, buffer);
50 caca_free_dither(dither);
51
52 caca_refresh_display(dp);
53
54 caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);
55
56 caca_free_display(dp);
57
58 return 0;
59 }
60