typo fixes
[mplayer/greg.git] / libvo / vo_caca.c
blob29d57c8ad201f1e2c7e8495defc1833335757848
1 /*
2 * MPlayer
3 *
4 * Video driver for libcaca
5 *
6 * by Pigeon <pigeon@pigeond.net>
8 * Some functions/codes/ideas are from x11 and aalib vo
10 * TODO: support those draw_alpha stuff?
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/stat.h>
17 #include <unistd.h>
18 #include <string.h>
19 #include <time.h>
20 #include <errno.h>
22 #include "config.h"
23 #include "video_out.h"
24 #include "video_out_internal.h"
25 #include "sub.h"
27 #include "osdep/keycodes.h"
28 #include "mp_msg.h"
30 #include <caca.h>
32 static vo_info_t info = {
33 "libcaca",
34 "caca",
35 "Pigeon <pigeon@pigeond.net>",
39 LIBVO_EXTERN (caca)
41 /* caca stuff */
42 static struct caca_bitmap *cbitmap = NULL;
44 /* image infos */
45 static int image_format;
46 static int image_width;
47 static int image_height;
49 static int screen_w, screen_h;
51 /* We want 24bpp always for now */
52 static unsigned int bpp = 24;
53 static unsigned int depth = 3;
54 static unsigned int rmask = 0xff0000;
55 static unsigned int gmask = 0x00ff00;
56 static unsigned int bmask = 0x0000ff;
57 static unsigned int amask = 0;
59 #define MESSAGE_SIZE 512
60 #define MESSAGE_DURATION 5
62 static time_t stoposd = 0;
63 static int showosdmessage = 0;
64 static char osdmessagetext[MESSAGE_SIZE];
65 static char posbar[MESSAGE_SIZE];
67 static int osdx = 0, osdy = 0;
68 static int posbary = 2;
70 static void osdmessage(int duration, char *fmt, ...)
73 * for outputting a centered string at the bottom
74 * of our window for a while
76 va_list ar;
77 char m[MESSAGE_SIZE];
79 va_start(ar, fmt);
80 vsprintf(m, fmt, ar);
81 va_end(ar);
82 strcpy(osdmessagetext, m);
84 showosdmessage = 1;
85 stoposd = time(NULL) + duration;
86 osdx = (screen_w - strlen (osdmessagetext)) / 2;
87 posbar[0] = '\0';
90 static void osdpercent(int duration, int min, int max, int val, char *desc, char *unit)
93 * prints a bar for setting values
95 float step;
96 int where, i;
98 step = (float)screen_w / (float)(max - min);
99 where = (val - min) * step;
100 osdmessage (duration, "%s: %i%s", desc, val, unit);
101 posbar[0] = '|';
102 posbar[screen_w - 1] = '|';
104 for (i = 0; i < screen_w; i++)
106 if (i == where)
107 posbar[i] = '#';
108 else
109 posbar[i] = '-';
112 if (where != 0)
113 posbar[0] = '|';
115 if (where != (screen_w - 1))
116 posbar[screen_w - 1] = '|';
118 posbar[screen_w] = '\0';
121 static int resize ()
123 screen_w = caca_get_width();
124 screen_h = caca_get_height();
126 if (cbitmap)
127 caca_free_bitmap(cbitmap);
129 cbitmap = caca_create_bitmap(bpp, image_width, image_height,
130 depth * image_width, rmask, gmask, bmask,
131 amask);
133 if (!cbitmap)
134 mp_msg(MSGT_VO, MSGL_FATAL, "vo_caca: caca_create_bitmap failed!\n");
136 return 0;
139 static int config(uint32_t width, uint32_t height, uint32_t d_width,
140 uint32_t d_height, uint32_t flags, char *title, uint32_t format)
142 image_height = height;
143 image_width = width;
144 image_format = format;
146 showosdmessage = 0;
147 posbar[0] = '\0';
149 return resize ();
152 static int draw_frame(uint8_t *src[])
154 caca_draw_bitmap(0, 0, screen_w, screen_h, cbitmap, src[0]);
155 return 0;
158 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
160 return 0;
163 static void flip_page(void)
166 if (showosdmessage)
168 if (time(NULL) >= stoposd)
170 showosdmessage = 0;
171 if (posbar)
172 posbar[0] = '\0';
173 } else {
174 caca_putstr(osdx, osdy, osdmessagetext);
176 if (posbar)
177 caca_putstr(0, posbary, posbar);
181 caca_refresh();
184 static void check_events (void)
186 unsigned int cev;
188 if ((cev = caca_get_event(CACA_EVENT_ANY)))
190 if (cev & CACA_EVENT_RESIZE)
192 caca_refresh();
193 resize();
194 } else if (cev & CACA_EVENT_KEY_RELEASE)
196 int key = (cev & 0x00ffffff);
197 enum caca_feature cf;
199 switch (key) {
200 case 'd':
201 case 'D':
202 /* Toggle dithering method */
203 cf = 1 + caca_get_feature(CACA_DITHERING);
204 if (cf > CACA_DITHERING_MAX)
205 cf = CACA_DITHERING_MIN;
206 caca_set_feature(cf);
207 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
208 break;
210 case 'a':
211 case 'A':
212 /* Toggle antialiasing method */
213 cf = 1 + caca_get_feature(CACA_ANTIALIASING);
214 if (cf > CACA_ANTIALIASING_MAX)
215 cf = CACA_ANTIALIASING_MIN;
216 caca_set_feature(cf);
217 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
218 break;
220 case 'b':
221 case 'B':
222 /* Toggle background method */
223 cf = 1 + caca_get_feature(CACA_BACKGROUND);
224 if (cf > CACA_BACKGROUND_MAX)
225 cf = CACA_BACKGROUND_MIN;
226 caca_set_feature(cf);
227 osdmessage(MESSAGE_DURATION, "Using %s", caca_get_feature_name(cf));
228 break;
230 case CACA_KEY_UP:
231 mplayer_put_key(KEY_UP);
232 break;
233 case CACA_KEY_DOWN:
234 mplayer_put_key(KEY_DOWN);
235 break;
236 case CACA_KEY_LEFT:
237 mplayer_put_key(KEY_LEFT);
238 break;
239 case CACA_KEY_RIGHT:
240 mplayer_put_key(KEY_RIGHT);
241 break;
242 case CACA_KEY_ESCAPE:
243 mplayer_put_key(KEY_ESC);
244 break;
245 case CACA_KEY_PAGEUP:
246 mplayer_put_key(KEY_PAGE_UP);
247 break;
248 case CACA_KEY_PAGEDOWN:
249 mplayer_put_key(KEY_PAGE_DOWN);
250 break;
251 case CACA_KEY_RETURN:
252 mplayer_put_key(KEY_ENTER);
253 break;
254 case CACA_KEY_HOME:
255 mplayer_put_key(KEY_HOME);
256 break;
257 case CACA_KEY_END:
258 mplayer_put_key(KEY_END);
259 break;
260 default:
261 if (key <= 255)
262 mplayer_put_key (key);
263 break;
269 static void uninit(void)
271 caca_free_bitmap(cbitmap);
272 cbitmap = NULL;
273 caca_end();
277 static void draw_osd(void)
279 #ifdef USE_OSD
280 if (vo_osd_progbar_type != -1)
281 osdpercent(MESSAGE_DURATION, 0, 255,
282 vo_osd_progbar_value, __sub_osd_names[vo_osd_progbar_type],
283 "");
284 #endif
287 static int preinit(const char *arg)
289 if (arg)
291 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: Unknown subdevice: %s\n", arg);
292 return ENOSYS;
295 if (caca_init())
297 mp_msg(MSGT_VO, MSGL_ERR, "vo_caca: failed to initialize\n");
298 return ENOSYS;
301 caca_set_window_title("MPlayer");
303 /* Default libcaca features */
304 caca_set_feature(CACA_ANTIALIASING_PREFILTER);
305 caca_set_feature(CACA_DITHERING_RANDOM);
307 return 0;
310 static int query_format(uint32_t format)
312 if (format == IMGFMT_BGR24)
313 return
314 #ifdef USE_OSD
315 VFCAP_OSD |
316 #endif
317 VFCAP_CSP_SUPPORTED;
319 return 0;
322 static int control(uint32_t request, void *data, ...)
324 switch(request)
326 case VOCTRL_QUERY_FORMAT:
327 return query_format(*((uint32_t *)data));
328 default:
329 return VO_NOTIMPL;