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

Last change on this file since 710 was 710, checked in by Sam Hocevar, 15 years ago
  • Merged caca_wait_event() into caca_get_event() and added a timeout parameter to do what both functions did before, and even more.
  • Property svn:keywords set to Id
File size: 3.7 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 710 2006-04-01 14:44:09Z 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#if !defined(__KERNEL__)
25#   include <stdio.h>
26#   include <math.h>
27#endif
28
29#include "cucul.h"
30#include "caca.h"
31
32uint32_t buffer[256 * 4];
33
34int main(void)
35{
36    struct caca_event ev;
37    cucul_t *qq, *gg, *mask;
38    caca_t *kk;
39    struct cucul_bitmap *left, *right;
40    float gam = 1.0;
41    int x;
42
43    qq = cucul_create(0, 0);
44    kk = caca_attach(qq);
45
46    gg = cucul_create(cucul_get_width(qq), cucul_get_height(qq));
47    mask = cucul_create(cucul_get_width(qq), cucul_get_height(qq));
48
49    for(x = 0; x < 256; x++)
50    {
51        buffer[x] = (x << 16) | (x << 8) | (x<< 0);
52        buffer[x + 256] = (0xff << 16) |    (x << 8) | (0x00 << 0);
53        buffer[x + 512] = (0x00 << 16) | (0xff << 8) |    (x << 0);
54        buffer[x + 768] =    (x << 16) | (0x00 << 8) | (0xff << 0);
55    }
56
57    left = cucul_create_bitmap(32, 256, 4, 4 * 256,
58                               0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
59    right = cucul_create_bitmap(32, 256, 4, 4 * 256,
60                                0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
61    caca_set_delay(kk, 20000);
62
63    for(x = 0; ; x++)
64    {
65        int ret = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0);
66
67        if(ret)
68        {
69            if(ev.data.key.c == CACA_KEY_LEFT)
70                gam /= 1.03;
71            else if(ev.data.key.c == CACA_KEY_RIGHT)
72                gam *= 1.03;
73            else if(ev.data.key.c == CACA_KEY_DOWN)
74                gam = 1.0;
75            else if(ev.data.key.c == CACA_KEY_ESCAPE)
76                break;
77        }
78
79        /* Resize the spare canvas, just in case the main one changed */
80        cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq));
81        cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq));
82
83        /* Draw the regular bitmap on the main canvas */
84        cucul_draw_bitmap(qq, 0, 0,
85                          cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
86                          left, buffer);
87
88        /* Draw the gamma-modified bitmap on the spare canvas */
89        cucul_set_bitmap_gamma(right, gam);
90        cucul_draw_bitmap(gg, 0, 0,
91                          cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
92                          right, buffer);
93
94        /* Draw something on the mask */
95        cucul_clear(mask);
96        cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE);
97        cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
98                                   * 0.5 * cucul_get_width(mask),
99                                 (1.0 + cos(0.05 * (float)x))
100                                   * 0.5 * cucul_get_height(mask),
101                                 cucul_get_width(mask) / 2,
102                                 cucul_get_height(mask) / 2, "#");
103
104        /* Blit the spare canvas onto the first one */
105        cucul_blit(qq, 0, 0, gg, mask);
106
107        cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
108        cucul_printf(qq, 2, 1,
109                     "gamma=%g - use arrows to change, Esc to quit", gam);
110
111        caca_display(kk);
112    }
113
114    cucul_free_bitmap(left);
115    cucul_free_bitmap(right);
116
117    caca_detach(kk);
118    cucul_free(qq);
119
120    return 0;
121}
122
Note: See TracBrowser for help on using the repository browser.