Mercurial > mplayer.hg
changeset 35050:b291f44d864a
Avoid some code duplication related to drawing the OSD.
This also fixes some bugs in sdl and xv when drawing
OSD on uyvy frames.
author | reimar |
---|---|
date | Sun, 02 Sep 2012 21:51:42 +0000 |
parents | a0ff4fde7a48 |
children | fdd4b7d35537 |
files | libvo/video_out.h libvo/vo_dga.c libvo/vo_fbdev.c libvo/vo_fbdev2.c libvo/vo_gl2.c libvo/vo_sdl.c libvo/vo_x11.c libvo/vo_xv.c |
diffstat | 8 files changed, 49 insertions(+), 241 deletions(-) [+] |
line wrap: on
line diff
--- a/libvo/video_out.h Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/video_out.h Sun Sep 02 21:51:42 2012 +0000 @@ -279,6 +279,14 @@ struct vo_rect *borders, const struct vo_rect *crop); void vo_mouse_movement(int posx, int posy); +static inline int pixel_stride(unsigned fmt) { + if (IMGFMT_IS_RGB(fmt)) + return (IMGFMT_RGB_DEPTH(fmt) + 7) / 8; + if (IMGFMT_IS_BGR(fmt)) + return (IMGFMT_BGR_DEPTH(fmt) + 7) / 8; + return IMGFMT_IS_YUVP16(fmt) ? 2 : 1; +} + static inline int aspect_scaling(void) { return vo_fs;
--- a/libvo/vo_dga.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_dga.c Sun Sep 02 21:51:42 2012 +0000 @@ -245,31 +245,15 @@ char *d; unsigned int offset; int buffer_stride; + int bpp = pixel_stride(vo_dga_src_format); + vo_draw_alpha_func draw = vo_get_draw_alpha(vo_dga_src_format); offset = vo_dga_width * y0 + x0; - buffer_stride = vo_dga_width; + buffer_stride = vo_dga_width * bpp; d = CURRENT_VIDEO_BUFFER.data + vo_dga_vp_offset; - - switch (HW_MODE.vdm_mplayer_depth) - { + d += bpp * offset; - case 32: - vo_draw_alpha_rgb32(w, h, src, srca, stride, d + 4 * offset, - 4 * buffer_stride); - break; - case 24: - vo_draw_alpha_rgb24(w, h, src, srca, stride, d + 3 * offset, - 3 * buffer_stride); - break; - case 15: - vo_draw_alpha_rgb15(w, h, src, srca, stride, d + 2 * offset, - 2 * buffer_stride); - break; - case 16: - vo_draw_alpha_rgb16(w, h, src, srca, stride, d + 2 * offset, - 2 * buffer_stride); - break; - } + if (draw) draw(w, h, src, srca, stride, d, buffer_stride); }
--- a/libvo/vo_fbdev.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_fbdev.c Sun Sep 02 21:51:42 2012 +0000 @@ -848,25 +848,7 @@ mp_msg(MSGT_VO, MSGL_WARN, "requested %d bpp, got %d bpp!!!\n", fb_bpp_we_want, fb_bpp); - switch (fb_bpp) { - case 32: - draw_alpha_p = vo_draw_alpha_rgb32; - break; - case 24: - draw_alpha_p = vo_draw_alpha_rgb24; - break; - case 16: - draw_alpha_p = vo_draw_alpha_rgb16; - break; - case 15: - draw_alpha_p = vo_draw_alpha_rgb15; - break; - case 12: - draw_alpha_p = vo_draw_alpha_rgb12; - break; - default: - return 1; - } + draw_alpha_p = vo_get_draw_alpha(format); fb_xres = fb_vinfo.xres; fb_yres = fb_vinfo.yres;
--- a/libvo/vo_fbdev2.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_fbdev2.c Sun Sep 02 21:51:42 2012 +0000 @@ -229,14 +229,7 @@ return 1; } - switch (fb_bpp) { - case 32: draw_alpha_p = vo_draw_alpha_rgb32; break; - case 24: draw_alpha_p = vo_draw_alpha_rgb24; break; - case 16: draw_alpha_p = vo_draw_alpha_rgb16; break; - case 15: draw_alpha_p = vo_draw_alpha_rgb15; break; - case 12: draw_alpha_p = vo_draw_alpha_rgb12; break; - default: return 1; - } + draw_alpha_p = vo_get_draw_alpha(format); if (vo_config_count == 0) { if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) {
--- a/libvo/vo_gl2.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_gl2.c Sun Sep 02 21:51:42 2012 +0000 @@ -89,9 +89,6 @@ static int is_yuv; static int use_glFinish; -static void (*draw_alpha_fnc) - (int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); - /* The squares that are tiled to make up the game screen polygon */ @@ -456,23 +453,11 @@ glLoadIdentity(); } -static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb32(w,h,src,srca,stride,ImageData+4*(y0*image_width+x0),4*image_width); -} - -static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb24(w,h,src,srca,stride,ImageData+3*(y0*image_width+x0),3*image_width); -} - -static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb16(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width); -} - -static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ - vo_draw_alpha_rgb15(w,h,src,srca,stride,ImageData+2*(y0*image_width+x0),2*image_width); -} - -static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ +static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ + int bpp = pixel_stride(image_format); + vo_draw_alpha_func draw = vo_get_draw_alpha(image_format); + if (!draw) return; + draw(w,h,src,srca,stride,ImageData+bpp*(y0*image_width+x0),bpp*image_width); } #ifdef CONFIG_GL_WIN32 @@ -665,19 +650,6 @@ image_bytes=(image_bpp+7)/8; - draw_alpha_fnc=draw_alpha_null; - - switch(image_bpp) { - case 15: - draw_alpha_fnc=draw_alpha_15; break; - case 16: - draw_alpha_fnc=draw_alpha_16; break; - case 24: - draw_alpha_fnc=draw_alpha_24; break; - case 32: - draw_alpha_fnc=draw_alpha_32; break; - } - if (initGl(vo_dwidth, vo_dheight) == -1) return -1; @@ -730,7 +702,7 @@ static void draw_osd(void) { if (ImageData) - vo_draw_text(image_width,image_height,draw_alpha_fnc); + vo_draw_text(image_width,image_height,draw_alpha); } static void
--- a/libvo/vo_sdl.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_sdl.c Sun Sep 02 21:51:42 2012 +0000 @@ -233,6 +233,8 @@ static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ struct sdl_priv_s *priv = &sdl_priv; + vo_draw_alpha_func draw = vo_get_draw_alpha(priv->format); + if (!draw) return; if(priv->osd_has_changed) { /* OSD did change. Store a bounding box of everything drawn into the OSD */ @@ -268,67 +270,25 @@ return; } + x0 *= pixel_stride(priv->format); switch(priv->format) { + case IMGFMT_YUY2: + case IMGFMT_YVYU: + case IMGFMT_UYVY: case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_IYUV: - vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]); - break; - case IMGFMT_YUY2: - case IMGFMT_YVYU: - x0 *= 2; - vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]); - break; - case IMGFMT_UYVY: - x0 *= 2; - vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]); + draw(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->overlay->pitches[0]*y0+x0,priv->overlay->pitches[0]); break; default: if(priv->dblit) { - x0 *= priv->surface->format->BytesPerPixel; - switch(priv->format) { - case IMGFMT_RGB15: - case IMGFMT_BGR15: - vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); - break; - case IMGFMT_RGB16: - case IMGFMT_BGR16: - vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); - break; - case IMGFMT_RGB24: - case IMGFMT_BGR24: - vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); - break; - case IMGFMT_RGB32: - case IMGFMT_BGR32: - vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); - break; - } + draw(w,h,src,srca,stride,((uint8_t *) priv->surface->pixels)+y0*priv->surface->pitch+x0,priv->surface->pitch); } else { - x0 *= priv->rgbsurface->format->BytesPerPixel; - switch(priv->format) { - case IMGFMT_RGB15: - case IMGFMT_BGR15: - vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch); - break; - case IMGFMT_RGB16: - case IMGFMT_BGR16: - vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch); - break; - case IMGFMT_RGB24: - case IMGFMT_BGR24: - vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch); - break; - case IMGFMT_RGB32: - case IMGFMT_BGR32: - vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch); - break; + draw(w,h,src,srca,stride,((uint8_t *) priv->rgbsurface->pixels)+y0*priv->rgbsurface->pitch+x0,priv->rgbsurface->pitch); } } - - } }
--- a/libvo/vo_x11.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_x11.c Sun Sep 02 21:51:42 2012 +0000 @@ -66,9 +66,7 @@ const LIBVO_EXTERN(x11) /* private prototypes */ -static void (*draw_alpha_fnc) (int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride); +vo_draw_alpha_func draw_alpha_func; /* local data */ static unsigned char *ImageData; @@ -110,42 +108,13 @@ flip_page(); } -static void draw_alpha_32(int x0, int y0, int w, int h, unsigned char *src, - unsigned char *srca, int stride) -{ - vo_draw_alpha_rgb32(w, h, src, srca, stride, - ImageData + 4 * (y0 * image_width + x0), - 4 * image_width); -} - -static void draw_alpha_24(int x0, int y0, int w, int h, unsigned char *src, - unsigned char *srca, int stride) +static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, + unsigned char *srca, int stride) { - vo_draw_alpha_rgb24(w, h, src, srca, stride, - ImageData + 3 * (y0 * image_width + x0), - 3 * image_width); -} - -static void draw_alpha_16(int x0, int y0, int w, int h, unsigned char *src, - unsigned char *srca, int stride) -{ - vo_draw_alpha_rgb16(w, h, src, srca, stride, - ImageData + 2 * (y0 * image_width + x0), - 2 * image_width); -} - -static void draw_alpha_15(int x0, int y0, int w, int h, unsigned char *src, - unsigned char *srca, int stride) -{ - vo_draw_alpha_rgb15(w, h, src, srca, stride, - ImageData + 2 * (y0 * image_width + x0), - 2 * image_width); -} - -static void draw_alpha_null(int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride) -{ + int bpp = pixel_stride(out_format); + draw_alpha_func(w, h, src, srca, stride, + ImageData + bpp * (y0 * image_width + x0), + bpp * image_width); } static struct SwsContext *swsContext = NULL; @@ -406,24 +375,9 @@ return -1; } out_format = fmte->mpfmt; - switch ((bpp = myximage->bits_per_pixel)) - { - case 24: - draw_alpha_fnc = draw_alpha_24; - break; - case 32: - draw_alpha_fnc = draw_alpha_32; - break; - case 15: - case 16: - if (depth == 15) - draw_alpha_fnc = draw_alpha_15; - else - draw_alpha_fnc = draw_alpha_16; - break; - default: - draw_alpha_fnc = draw_alpha_null; - } + draw_alpha_func = vo_get_draw_alpha(out_format); + + bpp = myximage->bits_per_pixel; out_offset = 0; // We can easily "emulate" non-native RGB32 and BGR32 if (out_format == (IMGFMT_BGR32 | 128) || out_format == (IMGFMT_RGB32 | 128)) { @@ -482,7 +436,8 @@ static void draw_osd(void) { - vo_draw_text(image_width, image_height, draw_alpha_fnc); + if (draw_alpha_func) + vo_draw_text(image_width, image_height, draw_alpha); } static void flip_page(void)
--- a/libvo/vo_xv.c Sun Sep 02 21:17:03 2012 +0000 +++ b/libvo/vo_xv.c Sun Sep 02 21:51:42 2012 +0000 @@ -107,9 +107,7 @@ static struct vo_rect dst_rect; static uint32_t max_width = 0, max_height = 0; // zero means: not set -static void (*draw_alpha_fnc) (int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride); +vo_draw_alpha_func draw_alpha_func; static void fixup_osd_position(int *x0, int *y0, int *w, int *h) { @@ -120,48 +118,20 @@ *y0 = FFMIN(*y0, image_height - *h); } -static void draw_alpha_yv12(int x0, int y0, int w, int h, +static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) { + if (!draw_alpha_func) return; fixup_osd_position(&x0, &y0, &w, &h); - vo_draw_alpha_yv12(w, h, src, srca, stride, + x0 *= pixel_stride(xv_format); + draw_alpha_func(w, h, src, srca, stride, xvimage[current_buf]->data + xvimage[current_buf]->offsets[0] + xvimage[current_buf]->pitches[0] * y0 + x0, xvimage[current_buf]->pitches[0]); } -static void draw_alpha_yuy2(int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride) -{ - fixup_osd_position(&x0, &y0, &w, &h); - vo_draw_alpha_yuy2(w, h, src, srca, stride, - xvimage[current_buf]->data + - xvimage[current_buf]->offsets[0] + - xvimage[current_buf]->pitches[0] * y0 + 2 * x0, - xvimage[current_buf]->pitches[0]); -} - -static void draw_alpha_uyvy(int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride) -{ - fixup_osd_position(&x0, &y0, &w, &h); - vo_draw_alpha_yuy2(w, h, src, srca, stride, - xvimage[current_buf]->data + - xvimage[current_buf]->offsets[0] + - xvimage[current_buf]->pitches[0] * y0 + 2 * x0 + 1, - xvimage[current_buf]->pitches[0]); -} - -static void draw_alpha_null(int x0, int y0, int w, int h, - unsigned char *src, unsigned char *srca, - int stride) -{ -} - static void deallocate_xvimage(int foo); @@ -268,23 +238,7 @@ mp_msg(MSGT_VO, MSGL_V, "using Xvideo port %d for hw scaling\n", xv_port); - switch (xv_format) - { - case IMGFMT_YV12: - case IMGFMT_I420: - case IMGFMT_IYUV: - draw_alpha_fnc = draw_alpha_yv12; - break; - case IMGFMT_YUY2: - case IMGFMT_YVYU: - draw_alpha_fnc = draw_alpha_yuy2; - break; - case IMGFMT_UYVY: - draw_alpha_fnc = draw_alpha_uyvy; - break; - default: - draw_alpha_fnc = draw_alpha_null; - } + draw_alpha_func = vo_get_draw_alpha(xv_format); if (vo_config_count) for (current_buf = 0; current_buf < num_buffers; ++current_buf) @@ -407,7 +361,7 @@ { vo_draw_text(image_width - image_width * vo_panscan_x / (vo_dwidth + vo_panscan_x), - image_height, draw_alpha_fnc); + image_height, draw_alpha); } static void flip_page(void)