4 * Video driver for libcaca
6 * by Pigeon <pigeon@pigeond.net>
8 * Some functions/codes/ideas are from x11 and aalib vo
10 * TODO: support those draw_alpha stuff?
23 #include "video_out.h"
24 #include "video_out_internal.h"
27 #include "osdep/keycodes.h"
32 static vo_info_t info
= {
35 "Pigeon <pigeon@pigeond.net>",
42 static struct caca_bitmap
*cbitmap
= NULL
;
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
82 strcpy(osdmessagetext
, m
);
85 stoposd
= time(NULL
) + duration
;
86 osdx
= (screen_w
- strlen (osdmessagetext
)) / 2;
90 static void osdpercent(int duration
, int min
, int max
, int val
, char *desc
, char *unit
)
93 * prints a bar for setting values
98 step
= (float)screen_w
/ (float)(max
- min
);
99 where
= (val
- min
) * step
;
100 osdmessage (duration
, "%s: %i%s", desc
, val
, unit
);
102 posbar
[screen_w
- 1] = '|';
104 for (i
= 0; i
< screen_w
; i
++)
115 if (where
!= (screen_w
- 1))
116 posbar
[screen_w
- 1] = '|';
118 posbar
[screen_w
] = '\0';
123 screen_w
= caca_get_width();
124 screen_h
= caca_get_height();
127 caca_free_bitmap(cbitmap
);
129 cbitmap
= caca_create_bitmap(bpp
, image_width
, image_height
,
130 depth
* image_width
, rmask
, gmask
, bmask
,
134 mp_msg(MSGT_VO
, MSGL_FATAL
, "vo_caca: caca_create_bitmap failed!\n");
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
;
144 image_format
= format
;
152 static int draw_frame(uint8_t *src
[])
154 caca_draw_bitmap(0, 0, screen_w
, screen_h
, cbitmap
, src
[0]);
158 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
163 static void flip_page(void)
168 if (time(NULL
) >= stoposd
)
174 caca_putstr(osdx
, osdy
, osdmessagetext
);
177 caca_putstr(0, posbary
, posbar
);
184 static void check_events (void)
188 if ((cev
= caca_get_event(CACA_EVENT_ANY
)))
190 if (cev
& CACA_EVENT_RESIZE
)
194 } else if (cev
& CACA_EVENT_KEY_RELEASE
)
196 int key
= (cev
& 0x00ffffff);
197 enum caca_feature cf
;
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
));
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
));
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
));
231 mplayer_put_key(KEY_UP
);
234 mplayer_put_key(KEY_DOWN
);
237 mplayer_put_key(KEY_LEFT
);
240 mplayer_put_key(KEY_RIGHT
);
242 case CACA_KEY_ESCAPE
:
243 mplayer_put_key(KEY_ESC
);
245 case CACA_KEY_PAGEUP
:
246 mplayer_put_key(KEY_PAGE_UP
);
248 case CACA_KEY_PAGEDOWN
:
249 mplayer_put_key(KEY_PAGE_DOWN
);
251 case CACA_KEY_RETURN
:
252 mplayer_put_key(KEY_ENTER
);
255 mplayer_put_key(KEY_HOME
);
258 mplayer_put_key(KEY_END
);
262 mplayer_put_key (key
);
269 static void uninit(void)
271 caca_free_bitmap(cbitmap
);
277 static void draw_osd(void)
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
],
287 static int preinit(const char *arg
)
291 mp_msg(MSGT_VO
, MSGL_ERR
, "vo_caca: Unknown subdevice: %s\n", arg
);
297 mp_msg(MSGT_VO
, MSGL_ERR
, "vo_caca: failed to initialize\n");
301 caca_set_window_title("MPlayer");
303 /* Default libcaca features */
304 caca_set_feature(CACA_ANTIALIASING_PREFILTER
);
305 caca_set_feature(CACA_DITHERING_RANDOM
);
310 static int query_format(uint32_t format
)
312 if (format
== IMGFMT_BGR24
)
322 static int control(uint32_t request
, void *data
, ...)
326 case VOCTRL_QUERY_FORMAT
:
327 return query_format(*((uint32_t *)data
));