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 680 2006-03-23 17:20:57Z 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 | cucul_t *qq, *gg, *mask; |
---|
37 | caca_t *kk; |
---|
38 | struct cucul_bitmap *left, *right; |
---|
39 | float gam = 1.0; |
---|
40 | int x; |
---|
41 | |
---|
42 | qq = cucul_create(0, 0); |
---|
43 | kk = caca_attach(qq); |
---|
44 | |
---|
45 | gg = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); |
---|
46 | mask = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); |
---|
47 | |
---|
48 | for(x = 0; x < 256; x++) |
---|
49 | { |
---|
50 | buffer[x] = (x << 16) | (x << 8) | (x<< 0); |
---|
51 | buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0); |
---|
52 | buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0); |
---|
53 | buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0); |
---|
54 | } |
---|
55 | |
---|
56 | left = cucul_create_bitmap(32, 256, 4, 4 * 256, |
---|
57 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
58 | right = cucul_create_bitmap(32, 256, 4, 4 * 256, |
---|
59 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
60 | caca_set_delay(kk, 20000); |
---|
61 | |
---|
62 | for(x = 0; ; x++) |
---|
63 | { |
---|
64 | int ev = caca_get_event(kk, CACA_EVENT_KEY_PRESS); |
---|
65 | |
---|
66 | if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT)) |
---|
67 | gam /= 1.03; |
---|
68 | else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT)) |
---|
69 | gam *= 1.03; |
---|
70 | else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN)) |
---|
71 | gam = 1.0; |
---|
72 | else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE)) |
---|
73 | break; |
---|
74 | |
---|
75 | /* Resize the spare canvas, just in case the main one changed */ |
---|
76 | cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); |
---|
77 | cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq)); |
---|
78 | |
---|
79 | /* Draw the regular bitmap on the main canvas */ |
---|
80 | cucul_draw_bitmap(qq, 0, 0, |
---|
81 | cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, |
---|
82 | left, buffer); |
---|
83 | |
---|
84 | /* Draw the gamma-modified bitmap on the spare canvas */ |
---|
85 | cucul_set_bitmap_gamma(right, gam); |
---|
86 | cucul_draw_bitmap(gg, 0, 0, |
---|
87 | cucul_get_width(gg) - 1, cucul_get_height(gg) - 1, |
---|
88 | right, buffer); |
---|
89 | |
---|
90 | /* Draw something on the mask */ |
---|
91 | cucul_clear(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_width(mask), |
---|
95 | (1.0 + cos(0.05 * (float)x)) |
---|
96 | * 0.5 * cucul_get_height(mask), |
---|
97 | cucul_get_width(mask) / 2, |
---|
98 | cucul_get_height(mask) / 2, "#"); |
---|
99 | |
---|
100 | /* Blit the spare canvas onto the first one */ |
---|
101 | cucul_blit(qq, 0, 0, gg, mask); |
---|
102 | |
---|
103 | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); |
---|
104 | cucul_printf(qq, 2, 1, |
---|
105 | "gamma=%g - use arrows to change, Esc to quit", gam); |
---|
106 | |
---|
107 | caca_display(kk); |
---|
108 | } |
---|
109 | |
---|
110 | cucul_free_bitmap(left); |
---|
111 | cucul_free_bitmap(right); |
---|
112 | |
---|
113 | caca_detach(kk); |
---|
114 | cucul_free(qq); |
---|
115 | |
---|
116 | return 0; |
---|
117 | } |
---|
118 | |
---|