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

Last change on this file since 964 was 964, checked in by Sam Hocevar, 14 years ago
  • Renamed caca_set_delay() and caca_get_rendertime() into caca_set_display_time() and caca_get_display_time() for consistency.
  • Property svn:keywords set to Id
File size: 3.8 KB
RevLine 
[654]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 964 2006-05-19 05:44:27Z 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"
[858]15#include "common.h"
[654]16
17#if defined(HAVE_INTTYPES_H)
18#   include <inttypes.h>
19#endif
20
[670]21#if !defined(__KERNEL__)
22#   include <stdio.h>
23#   include <math.h>
24#endif
25
[654]26#include "cucul.h"
27#include "caca.h"
28
[661]29uint32_t buffer[256 * 4];
[654]30
31int main(void)
32{
[777]33    caca_event_t ev;
[811]34    cucul_canvas_t *cv, *cw, *mask;
35    caca_display_t *dp;
[777]36    cucul_dither_t *left, *right;
[670]37    float gam = 1.0;
[654]38    int x;
39
[813]40    cv = cucul_create_canvas(0, 0);
[819]41    dp = caca_create_display(cv);
[654]42
[813]43    cw = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
44    mask = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
[670]45
[654]46    for(x = 0; x < 256; x++)
[661]47    {
[654]48        buffer[x] = (x << 16) | (x << 8) | (x<< 0);
[661]49        buffer[x + 256] = (0xff << 16) |    (x << 8) | (0x00 << 0);
50        buffer[x + 512] = (0x00 << 16) | (0xff << 8) |    (x << 0);
51        buffer[x + 768] =    (x << 16) | (0x00 << 8) | (0xff << 0);
52    }
[654]53
[734]54    left = cucul_create_dither(32, 256, 4, 4 * 256,
[654]55                               0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
[734]56    right = cucul_create_dither(32, 256, 4, 4 * 256,
[654]57                                0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
[964]58    caca_set_display_time(dp, 20000);
[654]59
[670]60    for(x = 0; ; x++)
[659]61    {
[811]62        int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
[659]63
[681]64        if(ret)
65        {
[810]66            if(ev.data.key.ch == CACA_KEY_LEFT)
[681]67                gam /= 1.03;
[810]68            else if(ev.data.key.ch == CACA_KEY_RIGHT)
[681]69                gam *= 1.03;
[810]70            else if(ev.data.key.ch == CACA_KEY_DOWN)
[681]71                gam = 1.0;
[810]72            else if(ev.data.key.ch == CACA_KEY_ESCAPE)
[681]73                break;
74        }
[659]75
[670]76        /* Resize the spare canvas, just in case the main one changed */
[813]77        cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
78        cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
[670]79
[734]80        /* Draw the regular dither on the main canvas */
[816]81        cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
82                            cucul_get_canvas_height(cv), left, buffer);
[659]83
[734]84        /* Draw the gamma-modified dither on the spare canvas */
85        cucul_set_dither_gamma(right, gam);
[816]86        cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
87                            cucul_get_canvas_height(cw), right, buffer);
[659]88
[670]89        /* Draw something on the mask */
[832]90        cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
91        cucul_clear_canvas(mask);
[670]92        cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE);
93        cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
[813]94                                   * 0.5 * cucul_get_canvas_width(mask),
[670]95                                 (1.0 + cos(0.05 * (float)x))
[813]96                                   * 0.5 * cucul_get_canvas_height(mask),
97                                 cucul_get_canvas_width(mask) / 2,
98                                 cucul_get_canvas_height(mask) / 2, "#");
[670]99
100        /* Blit the spare canvas onto the first one */
[811]101        cucul_blit(cv, 0, 0, cw, mask);
[670]102
[811]103        cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
104        cucul_printf(cv, 2, 1,
[670]105                     "gamma=%g - use arrows to change, Esc to quit", gam);
[659]106
[819]107        caca_refresh_display(dp);
[659]108    }
109
[734]110    cucul_free_dither(left);
111    cucul_free_dither(right);
[654]112
[819]113    caca_free_display(dp);
[813]114    cucul_free_canvas(cv);
[654]115
116    return 0;
117}
118
Note: See TracBrowser for help on using the repository browser.