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