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 811 2006-04-18 15:11:25Z 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 |
---|
19 | typedef unsigned char uint8_t; |
---|
20 | typedef unsigned short uint16_t; |
---|
21 | typedef 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 | |
---|
32 | uint32_t buffer[256 * 4]; |
---|
33 | |
---|
34 | int main(void) |
---|
35 | { |
---|
36 | caca_event_t ev; |
---|
37 | cucul_canvas_t *cv, *cw, *mask; |
---|
38 | caca_display_t *dp; |
---|
39 | cucul_dither_t *left, *right; |
---|
40 | float gam = 1.0; |
---|
41 | int x; |
---|
42 | |
---|
43 | cv = cucul_create(0, 0); |
---|
44 | dp = caca_attach(cv); |
---|
45 | |
---|
46 | cw = cucul_create(cucul_get_width(cv), cucul_get_height(cv)); |
---|
47 | mask = cucul_create(cucul_get_width(cv), cucul_get_height(cv)); |
---|
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_dither(32, 256, 4, 4 * 256, |
---|
58 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
59 | right = cucul_create_dither(32, 256, 4, 4 * 256, |
---|
60 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
61 | caca_set_delay(dp, 20000); |
---|
62 | |
---|
63 | for(x = 0; ; x++) |
---|
64 | { |
---|
65 | int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0); |
---|
66 | |
---|
67 | if(ret) |
---|
68 | { |
---|
69 | if(ev.data.key.ch == CACA_KEY_LEFT) |
---|
70 | gam /= 1.03; |
---|
71 | else if(ev.data.key.ch == CACA_KEY_RIGHT) |
---|
72 | gam *= 1.03; |
---|
73 | else if(ev.data.key.ch == CACA_KEY_DOWN) |
---|
74 | gam = 1.0; |
---|
75 | else if(ev.data.key.ch == CACA_KEY_ESCAPE) |
---|
76 | break; |
---|
77 | } |
---|
78 | |
---|
79 | /* Resize the spare canvas, just in case the main one changed */ |
---|
80 | cucul_set_size(cw, cucul_get_width(cv), cucul_get_height(cv)); |
---|
81 | cucul_set_size(mask, cucul_get_width(cv), cucul_get_height(cv)); |
---|
82 | |
---|
83 | /* Draw the regular dither on the main canvas */ |
---|
84 | cucul_dither_bitmap(cv, 0, 0, |
---|
85 | cucul_get_width(cv) - 1, cucul_get_height(cv) - 1, |
---|
86 | left, buffer); |
---|
87 | |
---|
88 | /* Draw the gamma-modified dither on the spare canvas */ |
---|
89 | cucul_set_dither_gamma(right, gam); |
---|
90 | cucul_dither_bitmap(cw, 0, 0, |
---|
91 | cucul_get_width(cw) - 1, cucul_get_height(cw) - 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(cv, 0, 0, cw, mask); |
---|
106 | |
---|
107 | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); |
---|
108 | cucul_printf(cv, 2, 1, |
---|
109 | "gamma=%g - use arrows to change, Esc to quit", gam); |
---|
110 | |
---|
111 | caca_display(dp); |
---|
112 | } |
---|
113 | |
---|
114 | cucul_free_dither(left); |
---|
115 | cucul_free_dither(right); |
---|
116 | |
---|
117 | caca_detach(dp); |
---|
118 | cucul_free(cv); |
---|
119 | |
---|
120 | return 0; |
---|
121 | } |
---|
122 | |
---|