vo_xv: Fix context Shminfo table size
[mplayer.git] / libvo / vo_dxr3.c
blob9893e80fb03f3509aa5543c5137c1e8a4169f446
1 /*
2 * DXR3/H+ video output
4 * Copyright (C) 2002-2003 David Holm <david@realityrift.com>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/em8300.h>
24 #include <sys/ioctl.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/select.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <stdio.h>
34 #include <time.h>
35 #include <math.h>
37 #include "config.h"
38 #include "mp_msg.h"
39 #include "help_mp.h"
40 #include "fastmemcpy.h"
42 #include "video_out.h"
43 #include "video_out_internal.h"
44 #include "aspect.h"
45 #include "spuenc.h"
46 #include "sub.h"
47 #ifdef CONFIG_GUI
48 #include "gui/interface.h"
49 #endif
50 #ifdef CONFIG_X11
51 #include "x11_common.h"
52 #endif
53 #include "libavutil/avstring.h"
55 #define SPU_SUPPORT
57 static const vo_info_t info =
59 "DXR3/H+ video out",
60 "dxr3",
61 "David Holm <dholm@iname.com>",
64 const LIBVO_EXTERN (dxr3)
66 /* Resolutions and positions */
67 static int v_width, v_height;
68 static int s_width, s_height;
69 static int osd_w, osd_h;
70 static int img_format;
72 /* Configuration values
73 * Don't declare these static, they
74 * should be accessible from the gui.
76 int dxr3_prebuf = 0;
77 int dxr3_newsync = 0;
78 int dxr3_overlay = 0;
79 int dxr3_device_num = 0;
80 int dxr3_norm = 0;
82 #define MAX_STR_SIZE 80 /* length for the static strings */
84 /* File descriptors */
85 static int fd_control = -1;
86 static int fd_video = -1;
87 static int fd_spu = -1;
88 static char fdv_name[MAX_STR_SIZE];
89 static char fds_name[MAX_STR_SIZE];
91 #ifdef SPU_SUPPORT
92 /* on screen display/subpics */
93 static char *osdpicbuf;
94 static int osdpicbuf_w;
95 static int osdpicbuf_h;
96 static int disposd;
97 static encodedata *spued;
98 static encodedata *spubuf;
99 #endif
102 /* Static variable used in ioctl's */
103 static int ioval;
104 static int prev_pts;
105 static int pts_offset;
106 static int old_vmode = -1;
109 /* Begin overlay.h */
111 Simple analog overlay API for DXR3/H+ linux driver.
113 Henrik Johansson
117 /* Pattern drawing callback used by the calibration functions.
118 The function is expected to:
119 Clear the entire screen.
120 Fill the screen with color bgcol (0xRRGGBB)
121 Draw a rectangle at (xpos,ypos) of size (width,height) in fgcol (0xRRGGBB)
124 typedef int (*pattern_drawer_cb)(int fgcol, int bgcol,
125 int xpos, int ypos, int width, int height, void *arg);
127 struct coeff {
128 float k,m;
131 typedef struct {
132 int dev;
134 int xres, yres,depth;
135 int xoffset,yoffset,xcorr;
136 int jitter;
137 int stability;
138 int keycolor;
139 struct coeff colcal_upper[3];
140 struct coeff colcal_lower[3];
141 float color_interval;
143 pattern_drawer_cb draw_pattern;
144 void *dp_arg;
145 } overlay_t;
148 static overlay_t *overlay_init(int dev);
149 static int overlay_release(overlay_t *);
151 static int overlay_read_state(overlay_t *o, char *path);
152 static int overlay_write_state(overlay_t *o, char *path);
154 static int overlay_set_screen(overlay_t *o, int xres, int yres, int depth);
155 static int overlay_set_mode(overlay_t *o, int mode);
156 static int overlay_set_attribute(overlay_t *o, int attribute, int val);
157 static int overlay_set_keycolor(overlay_t *o, int color);
158 static int overlay_set_window(overlay_t *o, int xpos,int ypos,int width,int height);
159 static int overlay_set_bcs(overlay_t *o, int brightness, int contrast, int saturation);
161 static int overlay_autocalibrate(overlay_t *o, pattern_drawer_cb pd, void *arg);
162 static void overlay_update_params(overlay_t *o);
163 static int overlay_signalmode(overlay_t *o, int mode);
164 /* End overlay.h */
167 #ifdef CONFIG_X11
168 #define KEY_COLOR 0x80a040
169 static XWindowAttributes xwin_attribs;
170 static overlay_t *overlay_data;
171 #endif
174 /* Functions for working with the em8300's internal clock */
175 /* End of internal clock functions */
177 static int control(uint32_t request, void *data)
179 switch (request) {
180 case VOCTRL_GUISUPPORT:
181 return VO_TRUE;
182 case VOCTRL_GUI_NOWINDOW:
183 if (dxr3_overlay) {
184 return VO_FALSE;
186 return VO_TRUE;
187 case VOCTRL_SET_SPU_PALETTE:
188 if (ioctl(fd_spu, EM8300_IOCTL_SPU_SETPALETTE, data) < 0) {
189 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToLoadNewSPUPalette);
190 return VO_ERROR;
192 return VO_TRUE;
193 #ifdef CONFIG_X11
194 case VOCTRL_ONTOP:
195 vo_x11_ontop();
196 return VO_TRUE;
197 case VOCTRL_FULLSCREEN:
198 if (dxr3_overlay) {
199 vo_x11_fullscreen();
200 overlay_signalmode(overlay_data,
201 vo_fs ? EM8300_OVERLAY_SIGNAL_ONLY :
202 EM8300_OVERLAY_SIGNAL_WITH_VGA);
203 return VO_TRUE;
205 return VO_FALSE;
206 #endif
207 case VOCTRL_RESUME:
208 if (dxr3_newsync) {
209 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
210 pts_offset = vo_pts - (ioval << 1);
211 if (pts_offset < 0) {
212 pts_offset = 0;
216 if (dxr3_prebuf) {
217 ioval = EM8300_PLAYMODE_PLAY;
218 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
219 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetPlaymode);
222 return VO_TRUE;
223 case VOCTRL_PAUSE:
224 if (dxr3_prebuf) {
225 ioval = EM8300_PLAYMODE_PAUSED;
226 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
227 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetPlaymode);
230 return VO_TRUE;
231 case VOCTRL_RESET:
232 if (dxr3_prebuf) {
233 close(fd_video);
234 fd_video = open(fdv_name, O_WRONLY);
235 close(fd_spu);
236 fd_spu = open(fds_name, O_WRONLY);
237 fsync(fd_video);
238 fsync(fd_spu);
240 return VO_TRUE;
241 case VOCTRL_QUERY_FORMAT:
243 uint32_t flag = 0;
245 if (*((uint32_t*)data) != IMGFMT_MPEGPES)
246 return 0;
248 flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_SPU;
249 if (dxr3_prebuf)
250 flag |= VFCAP_TIMER;
251 return flag;
253 case VOCTRL_SET_EQUALIZER:
255 em8300_bcs_t bcs;
256 struct voctrl_set_equalizer_args *args = data;
258 if (ioctl(fd_control, EM8300_IOCTL_GETBCS, &bcs) < 0)
259 return VO_FALSE;
260 if (!strcasecmp(args->name, "brightness"))
261 bcs.brightness = (args->value+100)*5;
262 else if (!strcasecmp(args->name, "contrast"))
263 bcs.contrast = (args->value+100)*5;
264 else if (!strcasecmp(args->name, "saturation"))
265 bcs.saturation = (args->value+100)*5;
266 else return VO_FALSE;
268 if (ioctl(fd_control, EM8300_IOCTL_SETBCS, &bcs) < 0)
269 return VO_FALSE;
270 return VO_TRUE;
272 case VOCTRL_GET_EQUALIZER:
274 em8300_bcs_t bcs;
275 struct voctrl_get_equalizer_args *args = data;
277 if (ioctl(fd_control, EM8300_IOCTL_GETBCS, &bcs) < 0)
278 return VO_FALSE;
280 if (!strcasecmp(args->name, "brightness"))
281 *args->valueptr = (bcs.brightness/5)-100;
282 else if (!strcasecmp(args->name, "contrast"))
283 *args->valueptr = (bcs.contrast/5)-100;
284 else if (!strcasecmp(args->name, "saturation"))
285 *args->valueptr = (bcs.saturation/5)-100;
286 else return VO_FALSE;
288 return VO_TRUE;
291 return VO_NOTIMPL;
294 void calculate_cvals(unsigned long mask, int *shift, int *prec)
296 /* Calculate shift and precision */
297 (*shift) = 0;
298 (*prec) = 0;
300 while (!(mask & 0x1)) {
301 (*shift)++;
302 mask >>= 1;
305 while (mask & 0x1) {
306 (*prec)++;
307 mask >>= 1;
311 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
313 int tmp1, tmp2, size;
314 em8300_register_t reg;
316 /* Softzoom turned on, downscale */
317 /* This activates the subpicture processor, you can safely disable this and still send */
318 /* broken subpics to the em8300, if it's enabled and you send broken subpics you will end */
319 /* up in a lockup */
320 ioval = EM8300_SPUMODE_ON;
321 if (ioctl(fd_control, EM8300_IOCTL_SET_SPUMODE, &ioval) < 0) {
322 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetSubpictureMode);
323 uninit();
324 return -1;
327 /* Set the playmode to play (just in case another app has set it to something else) */
328 ioval = EM8300_PLAYMODE_PLAY;
329 if (ioctl(fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval) < 0) {
330 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetPlaymode);
333 /* Start em8300 prebuffering and sync engine */
334 reg.microcode_register = 1;
335 reg.reg = 0;
336 reg.val = MVCOMMAND_SYNC;
337 ioctl(fd_control, EM8300_IOCTL_WRITEREG, &reg);
339 /* Clean buffer by syncing it */
340 ioval = EM8300_SUBDEVICE_VIDEO;
341 ioctl(fd_control, EM8300_IOCTL_FLUSH, &ioval);
342 ioval = EM8300_SUBDEVICE_AUDIO;
343 ioctl(fd_control, EM8300_IOCTL_FLUSH, &ioval);
345 /* Sync the video device to make sure the buffers are empty
346 * and set the playback speed to normal. Also reset the
347 * em8300 internal clock.
349 fsync(fd_video);
350 ioval = 0x900;
351 ioctl(fd_control, EM8300_IOCTL_SCR_SETSPEED, &ioval);
353 /* Store some variables statically that we need later in another scope */
354 img_format = format;
355 v_width = width;
356 v_height = height;
358 /* Set monitor_aspect to avoid jitter */
359 monitor_aspect = (float) width / (float) height;
361 if (ioctl(fd_control, EM8300_IOCTL_GET_VIDEOMODE, &old_vmode) < 0) {
362 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToGetTVNorm);
363 old_vmode = -1;
366 /* adjust TV norm */
367 if (dxr3_norm != 0) {
368 if (dxr3_norm == 5) {
369 ioval = EM8300_VIDEOMODE_NTSC;
370 } else if (dxr3_norm == 4) {
371 ioval = EM8300_VIDEOMODE_PAL60;
372 } else if (dxr3_norm == 3) {
373 ioval = EM8300_VIDEOMODE_PAL;
374 } else if (dxr3_norm == 2) {
375 if (vo_fps > 28) {
376 ioval = EM8300_VIDEOMODE_PAL60;
377 } else {
378 ioval = EM8300_VIDEOMODE_PAL;
381 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoSelectedTVNormByFrameRate);
382 ioval == EM8300_VIDEOMODE_PAL60 ? mp_msg(MSGT_VO,MSGL_INFO, "PAL-60") : mp_msg(MSGT_VO,MSGL_INFO, "PAL");
383 printf(".\n");
384 } else {
385 if (vo_fps > 28) {
386 ioval = EM8300_VIDEOMODE_NTSC;
387 } else {
388 ioval = EM8300_VIDEOMODE_PAL;
391 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoSelectedTVNormByFrameRate);
392 ioval == EM8300_VIDEOMODE_NTSC ? mp_msg(MSGT_VO,MSGL_INFO, "NTSC") : mp_msg(MSGT_VO,MSGL_INFO, "PAL");
393 printf(".\n");
396 if (old_vmode != ioval) {
397 if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &ioval) < 0) {
398 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToSetTVNorm);
404 /* libavcodec requires a width and height that is x|16 */
405 aspect_save_orig(width, height);
406 aspect_save_prescale(d_width, d_height);
407 ioctl(fd_control, EM8300_IOCTL_GET_VIDEOMODE, &ioval);
408 if (ioval == EM8300_VIDEOMODE_NTSC) {
409 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingUpForNTSC);
410 aspect_save_screenres(352, 240);
411 } else {
412 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingUpForPALSECAM);
413 aspect_save_screenres(352, 288);
415 aspect(&s_width, &s_height, A_ZOOM);
416 s_width -= s_width % 16;
417 s_height -= s_height % 16;
419 /* Try to figure out whether to use widescreen output or not */
420 /* Anamorphic widescreen modes makes this a pain in the ass */
421 tmp1 = abs(d_height - ((d_width / 4) * 3));
422 tmp2 = abs(d_height - (int) (d_width / 2.35));
423 if (tmp1 < tmp2) {
424 ioval = EM8300_ASPECTRATIO_4_3;
425 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingAspectRatioTo43);
426 } else {
427 ioval = EM8300_ASPECTRATIO_16_9;
428 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_SettingAspectRatioTo169);
430 ioctl(fd_control, EM8300_IOCTL_SET_ASPECTRATIO, &ioval);
432 #ifdef SPU_SUPPORT
433 #ifdef CONFIG_FREETYPE
434 if (ioval == EM8300_ASPECTRATIO_16_9) {
435 s_width *= d_height*1.78/s_height*(d_width*1.0/d_height)/2.35;
436 } else {
437 s_width *= 0.84;
439 //printf("VO: [dxr3] sw/sh:dw/dh ->%i,%i,%i,%i\n",s_width,s_height,d_width,d_height);
440 #else
441 s_width*=2;
442 s_height*=2;
443 #endif
445 osdpicbuf = calloc( 1,s_width * s_height);
446 if (osdpicbuf == NULL) {
447 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory);
448 return -1;
450 spued = (encodedata *) malloc(sizeof(encodedata));
451 if (spued == NULL) {
452 free( osdpicbuf );
453 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory);
454 return -1;
456 spubuf = (encodedata *) malloc(sizeof(encodedata));
457 if (spubuf == NULL) {
458 free( osdpicbuf );
459 free( spued );
460 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_OutOfMemory);
461 return -1;
463 osd_w = s_width;
464 osd_h = s_height;
465 osdpicbuf_w = s_width;
466 osdpicbuf_h = s_height;
468 spubuf->count=0;
469 pixbuf_encode_rle( 0,0,osdpicbuf_w,osdpicbuf_h - 1,osdpicbuf,osdpicbuf_w,spubuf );
471 #endif
473 #ifdef CONFIG_X11
474 if (dxr3_overlay) {
475 XVisualInfo vinfo;
476 XSetWindowAttributes xswa;
477 XSizeHints hint;
478 unsigned long xswamask;
479 Colormap cmap;
480 XColor key_color;
481 Window junkwindow;
482 Screen *scr;
483 int depth, red_shift, red_prec, green_shift, green_prec, blue_shift, blue_prec, acq_color;
484 em8300_overlay_screen_t ovlscr;
485 em8300_attribute_t ovlattr;
487 vo_dx = (vo_screenwidth - d_width) / 2;
488 vo_dy = (vo_screenheight - d_height) / 2;
489 vo_dwidth = d_width;
490 vo_dheight = d_height;
491 #ifdef CONFIG_GUI
492 if (use_gui) {
493 guiGetEvent(guiSetShVideo, 0);
494 XSetWindowBackground(mDisplay, vo_window, KEY_COLOR);
495 XClearWindow(mDisplay, vo_window);
496 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &xwin_attribs);
497 depth = xwin_attribs.depth;
498 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
499 depth = 24;
501 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
502 } else
503 #endif
505 XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &xwin_attribs);
506 depth = xwin_attribs.depth;
507 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) {
508 depth = 24;
510 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
511 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
512 d_width, d_height, flags,
513 CopyFromParent, "Viewing Window", title);
514 xswa.background_pixel = KEY_COLOR;
515 xswa.border_pixel = 0;
516 xswamask = CWBackPixel | CWBorderPixel;
517 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
520 /* Start setting up overlay */
521 XGetWindowAttributes(mDisplay, mRootWin, &xwin_attribs);
522 overlay_set_screen(overlay_data, xwin_attribs.width, xwin_attribs.height, xwin_attribs.depth);
523 overlay_read_state(overlay_data, NULL);
525 /* Allocate keycolor */
526 cmap = vo_x11_create_colormap(&vinfo);
527 calculate_cvals(vinfo.red_mask, &red_shift, &red_prec);
528 calculate_cvals(vinfo.green_mask, &green_shift, &green_prec);
529 calculate_cvals(vinfo.blue_mask, &blue_shift, &blue_prec);
531 key_color.red = ((KEY_COLOR >> 16) & 0xff) * 256;
532 key_color.green = ((KEY_COLOR >> 8) & 0xff) * 256;
533 key_color.blue = (KEY_COLOR & 0xff) * 256;
534 key_color.pixel = (((key_color.red >> (16 - red_prec)) << red_shift) +
535 ((key_color.green >> (16 - green_prec)) << green_shift) +
536 ((key_color.blue >> (16 - blue_prec)) << blue_shift));
537 key_color.flags = DoRed | DoGreen | DoBlue;
538 if (!XAllocColor(mDisplay, cmap, &key_color)) {
539 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToAllocateKeycolor);
540 return -1;
543 acq_color = ((key_color.red / 256) << 16) | ((key_color.green / 256) << 8) | key_color.blue;
544 if (key_color.pixel != KEY_COLOR) {
545 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_UnableToAllocateExactKeycolor, key_color.pixel);
548 /* Set keycolor and activate overlay */
549 XSetWindowBackground(mDisplay, vo_window, key_color.pixel);
550 XClearWindow(mDisplay, vo_window);
551 overlay_set_keycolor(overlay_data, key_color.pixel);
552 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OVERLAY);
553 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_RECTANGLE);
555 #endif
557 return 0;
560 static void draw_alpha(int x, int y, int w, int h, unsigned char* src, unsigned char *srca, int srcstride)
562 #ifdef SPU_SUPPORT
563 unsigned char *buf = &osdpicbuf[(y * osdpicbuf_w) + x];
564 int by = 0;
565 register int lx, ly;
566 register int stride = 0;
568 for (ly = 0; ly < h - 1; ly++)
570 for(lx = 0; lx < w; lx++ )
571 if ( ( srca[stride + lx] )&&( src[stride + lx] >= 128 ) ) buf[by + lx] = 3;
572 by+=osdpicbuf_w;
573 stride+=srcstride;
575 pixbuf_encode_rle(x, y, osdpicbuf_w, osdpicbuf_h - 1, osdpicbuf, osdpicbuf_w, spued);
576 #endif
579 extern int vo_osd_changed_flag;
580 extern mp_osd_obj_t* vo_osd_list;
582 static void draw_osd(void)
584 #ifdef SPU_SUPPORT
585 static int cleared = 0;
586 int changed = 0;
588 if ((disposd % 15) == 0)
591 mp_osd_obj_t* obj = vo_osd_list;
592 vo_update_osd( osd_w,osd_h );
593 while( obj )
595 if ( obj->flags & OSDFLAG_VISIBLE ) { changed=1; break; }
596 obj=obj->next;
599 if ( changed )
601 vo_draw_text(osd_w, osd_h, draw_alpha);
602 memset(osdpicbuf, 0, s_width * s_height);
603 cleared=0;
605 else
607 if ( !cleared )
609 spued->count=spubuf->count;
610 fast_memcpy( spued->data,spubuf->data,DATASIZE );
611 cleared=1;
616 /* could stand some check here to see if the subpic hasn't changed
617 * as if it hasn't and we re-send it it will "blink" as the last one
618 * is turned off, and the new one (same one) is turned on
620 /* Subpics are not stable yet =(
621 expect lockups if you enable */
622 #if 1
623 write(fd_spu, spued->data, spued->count);
624 #endif
626 disposd++;
627 #endif
631 static int draw_frame(uint8_t * src[])
633 vo_mpegpes_t *p = (vo_mpegpes_t *) src[0];
635 #ifdef SPU_SUPPORT
636 if (p->id == 0x20) {
637 write(fd_spu, p->data, p->size);
638 } else
639 #endif
640 write(fd_video, p->data, p->size);
641 return 0;
644 static void flip_page(void)
646 #ifdef CONFIG_X11
647 if (dxr3_overlay) {
648 int event = vo_x11_check_events(mDisplay);
649 if (event & VO_EVENT_RESIZE) {
650 Window junkwindow;
651 XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs);
652 XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow);
653 overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height);
655 if (event & VO_EVENT_EXPOSE) {
656 Window junkwindow;
657 XSetWindowBackground(mDisplay, vo_window, KEY_COLOR);
658 XClearWindow(mDisplay, vo_window);
659 XGetWindowAttributes(mDisplay, vo_window, &xwin_attribs);
660 XTranslateCoordinates(mDisplay, vo_window, mRootWin, -xwin_attribs.border_width, -xwin_attribs.border_width, &xwin_attribs.x, &xwin_attribs.y, &junkwindow);
661 overlay_set_window(overlay_data, xwin_attribs.x, xwin_attribs.y, xwin_attribs.width, xwin_attribs.height);
664 #endif
666 if (dxr3_newsync) {
667 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
668 ioval <<= 1;
669 if (vo_pts == 0) {
670 ioval = 0;
671 ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval);
672 pts_offset = 0;
673 } else if ((vo_pts - pts_offset) < (ioval - 7200) || (vo_pts - pts_offset) > (ioval + 7200)) {
674 ioval = (vo_pts + pts_offset) >> 1;
675 ioctl(fd_control, EM8300_IOCTL_SCR_SET, &ioval);
676 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
677 pts_offset = vo_pts - (ioval << 1);
678 if (pts_offset < 0) {
679 pts_offset = 0;
682 ioval = vo_pts + pts_offset;
683 ioctl(fd_video, EM8300_IOCTL_SPU_SETPTS, &ioval);
684 ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &ioval);
685 prev_pts = vo_pts;
686 } else if (dxr3_prebuf) {
687 ioctl(fd_spu, EM8300_IOCTL_SPU_SETPTS, &vo_pts);
688 ioctl(fd_video, EM8300_IOCTL_VIDEO_SETPTS, &vo_pts);
692 static int draw_slice(uint8_t *srcimg[], int stride[], int w, int h, int x0, int y0)
694 return -1;
697 static void uninit(void)
699 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Uninitializing);
700 #ifdef CONFIG_X11
701 if (dxr3_overlay) {
702 overlay_set_mode(overlay_data, EM8300_OVERLAY_MODE_OFF);
703 overlay_release(overlay_data);
705 #ifdef CONFIG_GUI
706 if (!use_gui) {
707 #endif
708 vo_x11_uninit();
710 #ifdef CONFIG_GUI
712 #endif
714 #endif
715 if (old_vmode != -1) {
716 if (ioctl(fd_control, EM8300_IOCTL_SET_VIDEOMODE, &old_vmode) < 0) {
717 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedRestoringTVNorm);
721 if (fd_video) {
722 close(fd_video);
724 if (fd_spu) {
725 close(fd_spu);
727 if (fd_control) {
728 close(fd_control);
730 #ifdef SPU_SUPPORT
731 if(osdpicbuf) {
732 free(osdpicbuf);
734 if(spued) {
735 free(spued);
737 #endif
740 static void check_events(void)
744 static int preinit(const char *arg)
746 char devname[MAX_STR_SIZE];
747 int fdflags = O_WRONLY;
749 /* Parse commandline */
750 while (arg) {
751 if (!strncmp("prebuf", arg, 6) && !dxr3_prebuf) {
752 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_EnablingPrebuffering);
753 dxr3_prebuf = 1;
754 } else if (!strncmp("sync", arg, 4) && !dxr3_newsync) {
755 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UsingNewSyncEngine);
756 dxr3_newsync = 1;
757 } else if (!strncmp("overlay", arg, 7) && !dxr3_overlay) {
758 #ifdef CONFIG_X11
759 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UsingOverlay);
760 dxr3_overlay = 1;
761 #else
762 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorYouNeedToCompileMplayerWithX11);
763 #endif
764 } else if (!strncmp("norm=", arg, 5)) {
765 arg += 5;
766 // dxr3_norm is 0 (-> don't change norm) by default
767 // but maybe someone changes this in the future
769 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_WillSetTVNormTo);
771 if (*arg == '5') {
772 dxr3_norm = 5;
773 mp_msg(MSGT_VO,MSGL_INFO, "NTSC");
774 } else if (*arg == '4') {
775 dxr3_norm = 4;
776 mp_msg(MSGT_VO,MSGL_INFO, "PAL-60");
777 } else if (*arg == '3') {
778 dxr3_norm = 3;
779 mp_msg(MSGT_VO,MSGL_INFO, "PAL");
780 } else if (*arg == '2') {
781 dxr3_norm = 2;
782 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALPAL60);
783 } else if (*arg == '1') {
784 dxr3_norm = 1;
785 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALNTSC);
786 } else if (*arg == '0') {
787 dxr3_norm = 0;
788 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UseCurrentNorm);
789 } else {
790 dxr3_norm = 0;
791 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_UseUnknownNormSuppliedCurrentNorm);
794 mp_msg(MSGT_VO,MSGL_INFO, ".\n");
795 } else if (arg[0] == '0' || arg[0] == '1' || arg[0] == '2' || arg[0] == '3') {
796 dxr3_device_num = arg[0];
799 arg = strchr(arg, ':');
800 if (arg) {
801 arg++;
806 /* Open the control interface */
807 sprintf(devname, "/dev/em8300-%d", dxr3_device_num);
808 fd_control = open(devname, fdflags);
809 if (fd_control < 1) {
810 /* Fall back to old naming scheme */
811 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTrying, devname);
812 sprintf(devname, "/dev/em8300");
813 fd_control = open(devname, fdflags);
814 if (fd_control < 1) {
815 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWell);
816 return -1;
818 } else {
819 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname);
822 /* Open the video interface */
823 sprintf(devname, "/dev/em8300_mv-%d", dxr3_device_num);
824 fd_video = open(devname, fdflags);
825 if (fd_video < 0) {
826 /* Fall back to old naming scheme */
827 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingMV, devname);
828 sprintf(devname, "/dev/em8300_mv");
829 fd_video = open(devname, fdflags);
830 if (fd_video < 0) {
831 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellMV);
832 uninit();
833 return -1;
835 } else {
836 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname);
838 strcpy(fdv_name, devname);
840 /* Open the subpicture interface */
841 sprintf(devname, "/dev/em8300_sp-%d", dxr3_device_num);
842 fd_spu = open(devname, fdflags);
843 if (fd_spu < 0) {
844 /* Fall back to old naming scheme */
845 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingSP, devname);
846 sprintf(devname, "/dev/em8300_sp");
847 fd_spu = open(devname, fdflags);
848 if (fd_spu < 0) {
849 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellSP);
850 uninit();
851 return -1;
853 } else {
854 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_Opened, devname);
856 strcpy(fds_name, devname);
858 #ifdef CONFIG_X11
859 if (dxr3_overlay) {
861 /* Fucked up hack needed to enable overlay.
862 * Will be removed as soon as I figure out
863 * how to make it work like it should
865 Display *dpy;
866 overlay_t *ov;
867 XWindowAttributes attribs;
869 dpy = XOpenDisplay(NULL);
870 if (!dpy) {
871 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToOpenDisplayDuringHackSetup);
872 return -1;
874 XGetWindowAttributes(dpy, RootWindow(dpy, DefaultScreen(dpy)), &attribs);
875 ov = overlay_init(fd_control);
876 overlay_set_screen(ov, attribs.width, attribs.height, PlanesOfScreen(ScreenOfDisplay(dpy, 0)));
877 overlay_read_state(ov, NULL);
878 overlay_set_keycolor(ov, KEY_COLOR);
879 overlay_set_mode(ov, EM8300_OVERLAY_MODE_OVERLAY);
880 overlay_set_mode(ov, EM8300_OVERLAY_MODE_RECTANGLE);
881 overlay_release(ov);
882 XCloseDisplay(dpy);
883 /* End of fucked up hack */
885 /* Initialize overlay and X11 */
886 overlay_data = overlay_init(fd_control);
887 #ifdef CONFIG_GUI
888 if (!use_gui) {
889 #endif
890 if (!vo_init()) {
891 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_UnableToInitX11);
892 return -1;
894 #ifdef CONFIG_GUI
896 #endif
898 #endif
900 if (dxr3_newsync) {
901 ioctl(fd_control, EM8300_IOCTL_SCR_GET, &ioval);
902 pts_offset = vo_pts - (ioval << 1);
903 if (pts_offset < 0) {
904 pts_offset = 0;
908 return 0;
911 /* Begin overlay.c */
912 static int update_parameters(overlay_t *o)
914 overlay_set_attribute(o, EM9010_ATTRIBUTE_XOFFSET, o->xoffset);
915 overlay_set_attribute(o, EM9010_ATTRIBUTE_YOFFSET, o->yoffset);
916 overlay_set_attribute(o, EM9010_ATTRIBUTE_XCORR, o->xcorr);
917 overlay_set_attribute(o, EM9010_ATTRIBUTE_STABILITY, o->stability);
918 overlay_set_attribute(o, EM9010_ATTRIBUTE_JITTER, o->jitter);
919 return 0;
922 static int overlay_set_attribute(overlay_t *o, int attribute, int value)
924 em8300_attribute_t attr;
926 attr.attribute = attribute;
927 attr.value = value;
928 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SET_ATTRIBUTE, &attr)==-1)
930 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedSettingOverlayAttribute);
931 return -1;
934 return 0;
937 static overlay_t *overlay_init(int dev)
939 overlay_t *o;
941 o = (overlay_t *) malloc(sizeof(overlay_t));
943 if(!o)
944 return NULL;
946 memset(o,0,sizeof(overlay_t));
948 o->dev = dev;
949 o->xres = 1280; o->yres=1024; o->xcorr=1000;
950 o->color_interval=10;
952 return o;
955 static int overlay_release(overlay_t *o)
957 if(o)
958 free(o);
960 return 0;
962 #define TYPE_INT 1
963 #define TYPE_XINT 2
964 #define TYPE_COEFF 3
965 #define TYPE_FLOAT 4
967 struct lut_entry {
968 char *name;
969 int type;
970 void *ptr;
973 static struct lut_entry *new_lookuptable(overlay_t *o)
975 struct lut_entry m[] = {
976 {"xoffset", TYPE_INT, &o->xoffset},
977 {"yoffset", TYPE_INT, &o->yoffset},
978 {"xcorr", TYPE_INT, &o->xcorr},
979 {"jitter", TYPE_INT, &o->jitter},
980 {"stability", TYPE_INT, &o->stability},
981 {"keycolor", TYPE_XINT, &o->keycolor},
982 {"colcal_upper", TYPE_COEFF, &o->colcal_upper[0]},
983 {"colcal_lower", TYPE_COEFF, &o->colcal_lower[0]},
984 {"color_interval", TYPE_FLOAT, &o->color_interval},
985 {0,0,0}
986 },*p;
988 p = malloc(sizeof(m));
989 memcpy(p,m,sizeof(m));
990 return p;
993 static int lookup_parameter(overlay_t *o, struct lut_entry *lut, char *name, void **ptr, int *type) {
994 int i;
996 for(i=0; lut[i].name; i++) {
997 if(!strcmp(name,lut[i].name)) {
998 *ptr = lut[i].ptr;
999 *type = lut[i].type;
1000 return 1;
1003 return 0;
1006 static int overlay_read_state(overlay_t *o, char *p)
1008 char *a,*tok;
1009 char path[128],fname[128],tmp[128],line[256];
1010 FILE *fp;
1011 struct lut_entry *lut;
1012 void *ptr;
1013 int type;
1014 int j;
1016 if(!p) {
1017 av_strlcpy(fname, getenv("HOME"), sizeof( fname ));
1018 av_strlcat(fname,"/.overlay", sizeof( fname ));
1019 } else
1020 av_strlcpy(fname, p, sizeof( fname ));
1022 sprintf(tmp,"/res_%dx%dx%d",o->xres,o->yres,o->depth);
1023 av_strlcat(fname, tmp, sizeof( fname ));
1025 if(!(fp=fopen(fname,"r")))
1026 return -1;
1028 lut = new_lookuptable(o);
1030 while(!feof(fp)) {
1031 if(!fgets(line,256,fp))
1032 break;
1033 tok=strtok(line," ");
1034 if(lookup_parameter(o,lut,tok,&ptr,&type)) {
1035 tok=strtok(NULL," ");
1036 switch(type) {
1037 case TYPE_INT:
1038 sscanf(tok,"%d",(int *)ptr);
1039 break;
1040 case TYPE_XINT:
1041 sscanf(tok,"%x",(int *)ptr);
1042 break;
1043 case TYPE_FLOAT:
1044 sscanf(tok,"%f",(float *)ptr);
1045 break;
1046 case TYPE_COEFF:
1047 for(j=0;j<3;j++) {
1048 sscanf(tok,"%f",&((struct coeff *)ptr)[j].k);
1049 tok=strtok(NULL," ");
1050 sscanf(tok,"%f",&((struct coeff *)ptr)[j].m);
1051 tok=strtok(NULL," ");
1053 break;
1059 update_parameters(o);
1061 free(lut);
1062 fclose(fp);
1063 return 0;
1066 static void overlay_update_params(overlay_t *o) {
1067 update_parameters(o);
1070 static int overlay_write_state(overlay_t *o, char *p)
1072 char *a;
1073 char path[128],fname[128],tmp[128];
1074 FILE *fp;
1075 char line[256],*tok;
1076 struct lut_entry *lut;
1077 int i,j;
1079 if(!p) {
1080 av_strlcpy(fname, getenv("HOME"), sizeof( fname ));
1081 av_strlcat(fname,"/.overlay", sizeof( fname ));
1082 } else
1083 av_strlcpy(fname, p, sizeof( fname ));
1085 if(access(fname, W_OK|X_OK|R_OK)) {
1086 if(mkdir(fname,0766))
1087 return -1;
1090 sprintf(tmp,"/res_%dx%dx%d",o->xres,o->yres,o->depth);
1091 av_strlcat(fname, tmp, sizeof( fname ));
1093 if(!(fp=fopen(fname,"w")))
1094 return -1;
1096 lut = new_lookuptable(o);
1098 for(i=0; lut[i].name; i++) {
1099 fprintf(fp,"%s ",lut[i].name);
1100 switch(lut[i].type) {
1101 case TYPE_INT:
1102 fprintf(fp,"%d\n",*(int *)lut[i].ptr);
1103 break;
1104 case TYPE_XINT:
1105 fprintf(fp,"%06x\n",*(int *)lut[i].ptr);
1106 break;
1107 case TYPE_FLOAT:
1108 fprintf(fp,"%f\n",*(float *)lut[i].ptr);
1109 break;
1110 case TYPE_COEFF:
1111 for(j=0;j<3;j++)
1112 fprintf(fp,"%f %f ",((struct coeff *)lut[i].ptr)[j].k,
1113 ((struct coeff *)lut[i].ptr)[j].m);
1114 fprintf(fp,"\n");
1115 break;
1119 fclose(fp);
1120 return 0;
1123 static int overlay_set_screen(overlay_t *o, int xres, int yres, int depth)
1125 em8300_overlay_screen_t scr;
1127 o->xres = xres;
1128 o->yres = yres;
1129 o->depth = depth;
1131 scr.xsize = xres;
1132 scr.ysize = yres;
1134 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETSCREEN, &scr)==-1)
1136 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedSettingOverlayScreen);
1137 return -1;
1139 return 0;
1142 static int overlay_set_mode(overlay_t *o, int mode)
1144 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETMODE, &mode)==-1) {
1145 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedEnablingOverlay);
1146 return -1;
1148 return 0;
1151 static int overlay_set_window(overlay_t *o, int xpos,int ypos,int width,int height)
1153 em8300_overlay_window_t win;
1154 win.xpos = xpos;
1155 win.ypos = ypos;
1156 win.width = width;
1157 win.height = height;
1159 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETWINDOW, &win)==-1)
1161 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedResizingOverlayWindow);
1162 return -1;
1164 return 0;
1167 static int overlay_set_bcs(overlay_t *o, int brightness, int contrast, int saturation)
1169 em8300_bcs_t bcs;
1170 bcs.brightness = brightness;
1171 bcs.contrast = contrast;
1172 bcs.saturation = saturation;
1174 if (ioctl(o->dev, EM8300_IOCTL_GETBCS, &bcs)==-1)
1176 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedSettingOverlayBcs);
1177 return -1;
1179 return 0;
1182 static int col_interp(float x, struct coeff c)
1184 float y;
1185 y = x*c.k + c.m;
1186 if(y > 255)
1187 y = 255;
1188 if(y < 0)
1189 y = 0;
1190 return rint(y);
1193 static int overlay_set_keycolor(overlay_t *o, int color) {
1194 int r = (color & 0xff0000) >> 16;
1195 int g = (color & 0x00ff00) >> 8;
1196 int b = (color & 0x0000ff);
1197 float ru,gu,bu;
1198 float rl,gl,bl;
1199 int upper,lower;
1201 ru = r+o->color_interval;
1202 gu = g+o->color_interval;
1203 bu = b+o->color_interval;
1205 rl = r-o->color_interval;
1206 gl = g-o->color_interval;
1207 bl = b-o->color_interval;
1209 upper = (col_interp(ru, o->colcal_upper[0]) << 16) |
1210 (col_interp(gu, o->colcal_upper[1]) << 8) |
1211 (col_interp(bu, o->colcal_upper[2]));
1213 lower = (col_interp(rl, o->colcal_lower[0]) << 16) |
1214 (col_interp(gl, o->colcal_lower[1]) << 8) |
1215 (col_interp(bl, o->colcal_lower[2]));
1217 //printf("0x%06x 0x%06x\n",upper,lower);
1218 overlay_set_attribute(o,EM9010_ATTRIBUTE_KEYCOLOR_UPPER,upper);
1219 overlay_set_attribute(o,EM9010_ATTRIBUTE_KEYCOLOR_LOWER,lower);
1220 return 0;
1223 static void least_sq_fit(int *x, int *y, int n, float *k, float *m)
1225 float sx=0,sy=0,sxx=0,sxy=0;
1226 float delta,b;
1227 int i;
1229 for(i=0; i < n; i++) {
1230 sx=sx+x[i];
1231 sy=sy+y[i];
1232 sxx=sxx+x[i]*x[i];
1233 sxy=sxy+x[i]*y[i];
1236 delta=sxx*n-sx*sx;
1238 *m=(sxx*sy-sx*sxy)/delta;
1239 *k=(sxy*n-sx*sy)/delta;
1242 static int overlay_autocalibrate(overlay_t *o, pattern_drawer_cb pd, void *arg)
1244 em8300_overlay_calibrate_t cal;
1245 em8300_overlay_window_t win;
1246 int x[256],r[256],g[256],b[256],n;
1247 float k,m;
1249 int i;
1251 o->draw_pattern=pd;
1252 o->dp_arg = arg;
1254 overlay_set_mode(o, EM8300_OVERLAY_MODE_OVERLAY);
1255 overlay_set_screen(o, o->xres, o->yres, o->depth);
1257 /* Calibrate Y-offset */
1259 o->draw_pattern(0x0000ff, 0, 0, 0, 355, 1, o->dp_arg);
1261 cal.cal_mode = EM8300_OVERLAY_CALMODE_YOFFSET;
1262 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1264 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedGettingOverlayYOffsetValues);
1265 return -1;
1267 o->yoffset = cal.result;
1268 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_YOffset,cal.result);
1270 /* Calibrate X-offset */
1272 o->draw_pattern(0x0000ff, 0, 0, 0, 2, 288, o->dp_arg);
1274 cal.cal_mode = EM8300_OVERLAY_CALMODE_XOFFSET;
1275 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1277 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedGettingOverlayXOffsetValues);
1278 return -1;
1280 o->xoffset = cal.result;
1281 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_XOffset,cal.result);
1283 /* Calibrate X scale correction */
1285 o->draw_pattern(0x0000ff, 0, 355, 0, 2, 288, o->dp_arg);
1287 cal.cal_mode = EM8300_OVERLAY_CALMODE_XCORRECTION;
1288 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1290 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedGettingOverlayXScaleCorrection);
1291 return -1;
1293 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_DXR3_XCorrection,cal.result);
1294 o->xcorr = cal.result;
1296 win.xpos = 10;
1297 win.ypos = 10;
1298 win.width = o->xres-20;
1299 win.height = o->yres-20;
1300 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_SETWINDOW, &win)==-1) {
1301 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_DXR3_FailedResizingOverlayWindow);
1302 exit(1);
1305 /* Calibrate key color upper limit */
1307 for(i=128,n=0; i <= 0xff; i+=4) {
1308 o->draw_pattern(i | (i << 8) | (i << 16), 0,
1309 (o->xres-200)/2,0,200,o->yres,o->dp_arg);
1311 cal.arg = i;
1312 cal.arg2 = 1;
1313 cal.cal_mode = EM8300_OVERLAY_CALMODE_COLOR;
1315 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1317 return -1 ;
1320 x[n] = i;
1321 r[n] = (cal.result>>16)&0xff;
1322 g[n] = (cal.result>>8)&0xff;
1323 b[n] = (cal.result)&0xff;
1324 n++;
1327 least_sq_fit(x,r,n,&o->colcal_upper[0].k,&o->colcal_upper[0].m);
1328 least_sq_fit(x,g,n,&o->colcal_upper[1].k,&o->colcal_upper[1].m);
1329 least_sq_fit(x,b,n,&o->colcal_upper[2].k,&o->colcal_upper[2].m);
1331 /* Calibrate key color lower limit */
1333 for(i=128,n=0; i <= 0xff; i+=4) {
1334 o->draw_pattern(i | (i << 8) | (i << 16), 0xffffff,
1335 (o->xres-200)/2,0,200,o->yres, o->dp_arg);
1337 cal.arg = i;
1338 cal.arg2 = 2;
1339 cal.cal_mode = EM8300_OVERLAY_CALMODE_COLOR;
1341 if (ioctl(o->dev, EM8300_IOCTL_OVERLAY_CALIBRATE, &cal))
1343 return -1 ;
1345 x[n] = i;
1346 r[n] = (cal.result>>16)&0xff;
1347 g[n] = (cal.result>>8)&0xff;
1348 b[n] = (cal.result)&0xff;
1349 n++;
1352 least_sq_fit(x,r,n,&o->colcal_lower[0].k,&o->colcal_lower[0].m);
1353 least_sq_fit(x,g,n,&o->colcal_lower[1].k,&o->colcal_lower[1].m);
1354 least_sq_fit(x,b,n,&o->colcal_lower[2].k,&o->colcal_lower[2].m);
1356 overlay_set_mode(o, EM8300_OVERLAY_MODE_OFF);
1358 return 0;
1362 static int overlay_signalmode(overlay_t *o, int mode) {
1363 if(ioctl(o->dev, EM8300_IOCTL_OVERLAY_SIGNALMODE, &mode) ==-1) {
1364 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_DXR3_FailedSetSignalMix);
1365 return -1;
1367 return 0;
1369 /* End overlay.c */