source: libcaca/trunk/test/gamma.c @ 665

Last change on this file since 665 was 665, checked in by Sam Hocevar, 16 years ago
  • Changed the cucul_init parameter so that it now directly accepts a canvas size (use cucul_init(0, 0) for the old behaviour).
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/*
2 *  gamma         libcucul gamma test program
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: gamma.c 665 2006-03-22 17:46:11Z sam $
7 *
8 *  This program is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14#include "config.h"
15
16#if defined(HAVE_INTTYPES_H)
17#   include <inttypes.h>
18#else
19typedef unsigned char uint8_t;
20typedef unsigned short uint16_t;
21typedef unsigned int uint32_t;
22#endif
23
24#include "cucul.h"
25#include "caca.h"
26
27uint32_t buffer[256 * 4];
28
29int main(void)
30{
31    cucul_t *qq;
32    caca_t *kk;
33
34    struct cucul_bitmap *left, *right;
35    int x;
36
37    qq = cucul_init(0, 0);
38    kk = caca_attach(qq);
39
40    for(x = 0; x < 256; x++)
41    {
42        buffer[x] = (x << 16) | (x << 8) | (x<< 0);
43        buffer[x + 256] = (0xff << 16) |    (x << 8) | (0x00 << 0);
44        buffer[x + 512] = (0x00 << 16) | (0xff << 8) |    (x << 0);
45        buffer[x + 768] =    (x << 16) | (0x00 << 8) | (0xff << 0);
46    }
47
48    left = cucul_create_bitmap(qq, 32, 256, 4, 4 * 256,
49                               0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
50    right = cucul_create_bitmap(qq, 32, 256, 4, 4 * 256,
51                                0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
52    caca_set_delay(kk, 20000);
53
54    for(x = 0; ; x = (x + 1) % 256)
55    {
56        float g = (x > 128) ? (256.0 + 8.0 - x) / 64.0 : (8.0 + x) / 64.0;
57
58        if(caca_get_event(kk, CACA_EVENT_KEY_PRESS))
59            break;
60
61        cucul_draw_bitmap(qq, 0, cucul_get_height(qq) / 2,
62                          cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
63                          left, buffer);
64
65        cucul_set_bitmap_gamma(right, g);
66        cucul_draw_bitmap(qq, 0, 0,
67                          cucul_get_width(qq) - 1, cucul_get_height(qq) / 2 - 1,
68                          right, buffer);
69
70        cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
71        cucul_printf(qq, 2, 1, "gamma=%g", g);
72
73        caca_display(kk);
74    }
75
76    cucul_free_bitmap(left);
77    cucul_free_bitmap(right);
78
79    caca_detach(kk);
80    cucul_end(qq);
81
82    return 0;
83}
84
Note: See TracBrowser for help on using the repository browser.