diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/CATEGORIES | 1 | ||||
-rw-r--r-- | apps/plugins/test_grey.c | 242 |
2 files changed, 243 insertions, 0 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES index 2fd08ca01e..738c031698 100644 --- a/apps/plugins/CATEGORIES +++ b/apps/plugins/CATEGORIES | |||
@@ -81,6 +81,7 @@ stopwatch,apps | |||
81 | test_codec,viewers | 81 | test_codec,viewers |
82 | test_disk,apps | 82 | test_disk,apps |
83 | test_fps,apps | 83 | test_fps,apps |
84 | test_grey,apps | ||
84 | test_sampr,apps | 85 | test_sampr,apps |
85 | test_scanrate,apps | 86 | test_scanrate,apps |
86 | test_viewports,apps | 87 | test_viewports,apps |
diff --git a/apps/plugins/test_grey.c b/apps/plugins/test_grey.c new file mode 100644 index 0000000000..a413854332 --- /dev/null +++ b/apps/plugins/test_grey.c | |||
@@ -0,0 +1,242 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 Jens Arnold | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "plugin.h" | ||
20 | #include "grey.h" | ||
21 | #include "helper.h" | ||
22 | |||
23 | PLUGIN_HEADER | ||
24 | |||
25 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \ | ||
26 | || (CONFIG_KEYPAD == IPOD_1G2G_PAD) | ||
27 | #define GREY_QUIT BUTTON_MENU | ||
28 | #define GREY_OK BUTTON_SELECT | ||
29 | #define GREY_PREV BUTTON_LEFT | ||
30 | #define GREY_NEXT BUTTON_RIGHT | ||
31 | #define GREY_UP BUTTON_SCROLL_FWD | ||
32 | #define GREY_DOWN BUTTON_SCROLL_BACK | ||
33 | |||
34 | #elif CONFIG_KEYPAD == IRIVER_H100_PAD | ||
35 | #define GREY_QUIT BUTTON_OFF | ||
36 | #define GREY_OK BUTTON_SELECT | ||
37 | #define GREY_PREV BUTTON_LEFT | ||
38 | #define GREY_NEXT BUTTON_RIGHT | ||
39 | #define GREY_UP BUTTON_UP | ||
40 | #define GREY_DOWN BUTTON_DOWN | ||
41 | |||
42 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
43 | #define GREY_QUIT BUTTON_OFF | ||
44 | #define GREY_OK BUTTON_PLAY | ||
45 | #define GREY_PREV BUTTON_LEFT | ||
46 | #define GREY_NEXT BUTTON_RIGHT | ||
47 | #define GREY_UP BUTTON_UP | ||
48 | #define GREY_DOWN BUTTON_DOWN | ||
49 | |||
50 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
51 | #define GREY_QUIT BUTTON_OFF | ||
52 | #define GREY_OK BUTTON_MENU | ||
53 | #define GREY_PREV BUTTON_LEFT | ||
54 | #define GREY_NEXT BUTTON_RIGHT | ||
55 | #define GREY_UP BUTTON_UP | ||
56 | #define GREY_DOWN BUTTON_DOWN | ||
57 | |||
58 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) \ | ||
59 | || (CONFIG_KEYPAD == MROBE100_PAD) | ||
60 | #define GREY_QUIT BUTTON_POWER | ||
61 | #define GREY_OK BUTTON_SELECT | ||
62 | #define GREY_PREV BUTTON_LEFT | ||
63 | #define GREY_NEXT BUTTON_RIGHT | ||
64 | #define GREY_UP BUTTON_UP | ||
65 | #define GREY_DOWN BUTTON_DOWN | ||
66 | |||
67 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD | ||
68 | #define GREY_QUIT BUTTON_RC_REC | ||
69 | #define GREY_OK BUTTON_RC_PLAY | ||
70 | #define GREY_PREV BUTTON_RC_REW | ||
71 | #define GREY_NEXT BUTTON_RC_FF | ||
72 | #define GREY_UP BUTTON_RC_VOL_UP | ||
73 | #define GREY_DOWN BUTTON_RC_VOL_DOWN | ||
74 | |||
75 | #else | ||
76 | #error unsupported keypad | ||
77 | #endif | ||
78 | |||
79 | #define BLOCK_WIDTH (LCD_WIDTH/8) | ||
80 | #define BLOCK_HEIGHT (LCD_HEIGHT/8) | ||
81 | |||
82 | #define STEPS 16 | ||
83 | |||
84 | GREY_INFO_STRUCT | ||
85 | |||
86 | static const unsigned char dither_matrix[16][16] = { | ||
87 | { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, | ||
88 | { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, | ||
89 | { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, | ||
90 | { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, | ||
91 | { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, | ||
92 | { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, | ||
93 | { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, | ||
94 | { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, | ||
95 | { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, | ||
96 | { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, | ||
97 | { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, | ||
98 | { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, | ||
99 | { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, | ||
100 | { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, | ||
101 | { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, | ||
102 | { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } | ||
103 | }; | ||
104 | |||
105 | static unsigned char input_levels[STEPS+1]; | ||
106 | static unsigned char lcd_levels[STEPS+1]; | ||
107 | |||
108 | static struct plugin_api* rb; | ||
109 | static unsigned char *gbuf; | ||
110 | static size_t gbuf_size = 0; | ||
111 | |||
112 | static void fill_rastered(int bx, int by, int bw, int bh, int step) | ||
113 | { | ||
114 | int x, xmax, y, ymax; | ||
115 | int level; | ||
116 | |||
117 | if (step < 0) | ||
118 | step = 0; | ||
119 | else if (step > STEPS) | ||
120 | step = STEPS; | ||
121 | |||
122 | level = input_levels[step]; | ||
123 | level += (level-1) >> 7; | ||
124 | |||
125 | for (y = (LCD_HEIGHT/2) + by * BLOCK_HEIGHT, ymax = y + bh * BLOCK_HEIGHT; | ||
126 | y < ymax; y++) | ||
127 | { | ||
128 | for (x = (LCD_WIDTH/2) + bx * BLOCK_WIDTH, xmax = x + bw * BLOCK_WIDTH; | ||
129 | x < xmax; x++) | ||
130 | { | ||
131 | grey_set_foreground((level > dither_matrix[y & 0xf][x & 0xf]) | ||
132 | ? 255 : 0); | ||
133 | grey_drawpixel(x, y); | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /* plugin entry point */ | ||
139 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
140 | { | ||
141 | bool done = false; | ||
142 | int cur_step = 1; | ||
143 | int button, i, l, fd; | ||
144 | unsigned char filename[MAX_PATH]; | ||
145 | |||
146 | /* standard stuff */ | ||
147 | (void)parameter; | ||
148 | rb = api; | ||
149 | |||
150 | gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); | ||
151 | |||
152 | if (!grey_init(rb, gbuf, gbuf_size, | ||
153 | GREY_BUFFERED|GREY_RAWMAPPED|GREY_ON_COP, | ||
154 | LCD_WIDTH, LCD_HEIGHT, NULL)) | ||
155 | { | ||
156 | rb->splash(HZ, "Not enough memory."); | ||
157 | return PLUGIN_ERROR; | ||
158 | } | ||
159 | for (i = 0; i <= STEPS; i++) | ||
160 | input_levels[i] = lcd_levels[i] = (255 * i + (STEPS/2)) / STEPS; | ||
161 | |||
162 | backlight_force_on(rb); /* backlight control in lib/helper.c */ | ||
163 | |||
164 | grey_set_background(0); /* set background to black */ | ||
165 | grey_clear_display(); | ||
166 | grey_show(true); | ||
167 | |||
168 | while (!done) | ||
169 | { | ||
170 | fill_rastered(-3, -3, 2, 2, cur_step - 1); | ||
171 | fill_rastered(-1, -3, 2, 2, cur_step); | ||
172 | fill_rastered(1, -3, 2, 2, cur_step + 1); | ||
173 | fill_rastered(-3, -1, 2, 2, cur_step); | ||
174 | grey_set_foreground(lcd_levels[cur_step]); | ||
175 | grey_fillrect(LCD_WIDTH/2-BLOCK_WIDTH, LCD_HEIGHT/2-BLOCK_HEIGHT, | ||
176 | 2*BLOCK_WIDTH, 2*BLOCK_HEIGHT); | ||
177 | fill_rastered(1, -1, 2, 2, cur_step); | ||
178 | fill_rastered(-3, 1, 2, 2, cur_step + 1); | ||
179 | fill_rastered(-1, 1, 2, 2, cur_step); | ||
180 | fill_rastered(1, 1, 2, 2, cur_step - 1); | ||
181 | grey_update(); | ||
182 | |||
183 | button = rb->button_get(true); | ||
184 | switch (button) | ||
185 | { | ||
186 | case GREY_PREV: | ||
187 | if (cur_step > 0) | ||
188 | cur_step--; | ||
189 | break; | ||
190 | |||
191 | case GREY_NEXT: | ||
192 | if (cur_step < STEPS) | ||
193 | cur_step++; | ||
194 | break; | ||
195 | |||
196 | case GREY_UP: | ||
197 | case GREY_UP|BUTTON_REPEAT: | ||
198 | l = lcd_levels[cur_step]; | ||
199 | if (l < 255) | ||
200 | { | ||
201 | l++; | ||
202 | for (i = cur_step; i <= STEPS; i++) | ||
203 | if (lcd_levels[i] < l) | ||
204 | lcd_levels[i] = l; | ||
205 | } | ||
206 | break; | ||
207 | |||
208 | case GREY_DOWN: | ||
209 | case GREY_DOWN|BUTTON_REPEAT: | ||
210 | l = lcd_levels[cur_step]; | ||
211 | if (l > 0) | ||
212 | { | ||
213 | l--; | ||
214 | for (i = cur_step; i >= 0; i--) | ||
215 | if (lcd_levels[i] > l) | ||
216 | lcd_levels[i] = l; | ||
217 | } | ||
218 | break; | ||
219 | |||
220 | case GREY_OK: | ||
221 | rb->create_numbered_filename(filename, "/", "test_grey_", | ||
222 | ".txt", 2 IF_CNFN_NUM_(, NULL)); | ||
223 | fd = rb->open(filename, O_RDWR|O_CREAT|O_TRUNC); | ||
224 | if (fd >= 0) | ||
225 | { | ||
226 | for (i = 0; i <= STEPS; i++) | ||
227 | rb->fdprintf(fd, "%3d: %3d\n", input_levels[i], | ||
228 | lcd_levels[i]); | ||
229 | rb->close(fd); | ||
230 | } | ||
231 | /* fall through */ | ||
232 | |||
233 | case GREY_QUIT: | ||
234 | done = true; | ||
235 | break; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | grey_release(); | ||
240 | backlight_use_settings(rb); /* backlight control in lib/helper.c */ | ||
241 | return PLUGIN_OK; | ||
242 | } | ||