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 858 2006-04-24 19:57:23Z 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 | #include "common.h" |
---|
16 | |
---|
17 | #if defined(HAVE_INTTYPES_H) |
---|
18 | # include <inttypes.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | #if !defined(__KERNEL__) |
---|
22 | # include <stdio.h> |
---|
23 | # include <math.h> |
---|
24 | #endif |
---|
25 | |
---|
26 | #include "cucul.h" |
---|
27 | #include "caca.h" |
---|
28 | |
---|
29 | uint32_t buffer[256 * 4]; |
---|
30 | |
---|
31 | int main(void) |
---|
32 | { |
---|
33 | caca_event_t ev; |
---|
34 | cucul_canvas_t *cv, *cw, *mask; |
---|
35 | caca_display_t *dp; |
---|
36 | cucul_dither_t *left, *right; |
---|
37 | float gam = 1.0; |
---|
38 | int x; |
---|
39 | |
---|
40 | cv = cucul_create_canvas(0, 0); |
---|
41 | dp = caca_create_display(cv); |
---|
42 | |
---|
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)); |
---|
45 | |
---|
46 | for(x = 0; x < 256; x++) |
---|
47 | { |
---|
48 | buffer[x] = (x << 16) | (x << 8) | (x<< 0); |
---|
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 | } |
---|
53 | |
---|
54 | left = cucul_create_dither(32, 256, 4, 4 * 256, |
---|
55 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
56 | right = cucul_create_dither(32, 256, 4, 4 * 256, |
---|
57 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
58 | caca_set_delay(dp, 20000); |
---|
59 | |
---|
60 | for(x = 0; ; x++) |
---|
61 | { |
---|
62 | int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0); |
---|
63 | |
---|
64 | if(ret) |
---|
65 | { |
---|
66 | if(ev.data.key.ch == CACA_KEY_LEFT) |
---|
67 | gam /= 1.03; |
---|
68 | else if(ev.data.key.ch == CACA_KEY_RIGHT) |
---|
69 | gam *= 1.03; |
---|
70 | else if(ev.data.key.ch == CACA_KEY_DOWN) |
---|
71 | gam = 1.0; |
---|
72 | else if(ev.data.key.ch == CACA_KEY_ESCAPE) |
---|
73 | break; |
---|
74 | } |
---|
75 | |
---|
76 | /* Resize the spare canvas, just in case the main one changed */ |
---|
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)); |
---|
79 | |
---|
80 | /* Draw the regular dither on the main canvas */ |
---|
81 | cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), |
---|
82 | cucul_get_canvas_height(cv), left, buffer); |
---|
83 | |
---|
84 | /* Draw the gamma-modified dither on the spare canvas */ |
---|
85 | cucul_set_dither_gamma(right, gam); |
---|
86 | cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw), |
---|
87 | cucul_get_canvas_height(cw), right, buffer); |
---|
88 | |
---|
89 | /* Draw something on the mask */ |
---|
90 | cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); |
---|
91 | cucul_clear_canvas(mask); |
---|
92 | cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE); |
---|
93 | cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x)) |
---|
94 | * 0.5 * cucul_get_canvas_width(mask), |
---|
95 | (1.0 + cos(0.05 * (float)x)) |
---|
96 | * 0.5 * cucul_get_canvas_height(mask), |
---|
97 | cucul_get_canvas_width(mask) / 2, |
---|
98 | cucul_get_canvas_height(mask) / 2, "#"); |
---|
99 | |
---|
100 | /* Blit the spare canvas onto the first one */ |
---|
101 | cucul_blit(cv, 0, 0, cw, mask); |
---|
102 | |
---|
103 | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); |
---|
104 | cucul_printf(cv, 2, 1, |
---|
105 | "gamma=%g - use arrows to change, Esc to quit", gam); |
---|
106 | |
---|
107 | caca_refresh_display(dp); |
---|
108 | } |
---|
109 | |
---|
110 | cucul_free_dither(left); |
---|
111 | cucul_free_dither(right); |
---|
112 | |
---|
113 | caca_free_display(dp); |
---|
114 | cucul_free_canvas(cv); |
---|
115 | |
---|
116 | return 0; |
---|
117 | } |
---|
118 | |
---|