[MPlayer-dev-eng] [RFC] [PATCH] prepare for refactoring very similiar vo_draw_alpha_rgb12/15/16()

Janusz Krzysztofik jkrzyszt at tis.icnet.pl
Wed May 26 12:02:17 CEST 2010


Saturday 03 April 2010 16:55:10 Janusz Krzysztofik wrote:
> Saturday 03 April 2010 10:54:54 Diego Biurrun wrote:
> > On Fri, Mar 19, 2010 at 01:52:42AM +0100, Janusz Krzysztofik wrote:
> > > --- trunk.orig/libvo/osd.c	2010-02-26 02:40:23.000000000 +0100
> > > +++ trunk/libvo/osd.c	2010-03-19 01:01:29.000000000 +0100
> > > @@ -329,6 +329,38 @@ void vo_draw_alpha_init(void){
> > >
> > > +void vo_draw_alpha_rgb12(int w,int h, unsigned char* src, unsigned
> > > char *srca, int srcstride, unsigned char* dstbase,int dststride){
> > > +}
> > > +
> > >  void vo_draw_alpha_rgb15(int w,int h, unsigned char* src, unsigned
> > > char *srca, int srcstride, unsigned char* dstbase,int dststride){
> >
> > vo_draw_alpha_rgb12() looks very similar to vo_draw_alpha_rgb15() and
> > vo_draw_alpha_rgb16().  Ideally this should be refactored in some way.
>
> Sounds like better being addressed by a separate patch. Can I revisit it
> later, when finished with this one?

Diego,
I'm not sure how exactly you imagined the refactoring you mentioned, but as I 
promissed, here is my first attempt to do it to the extent I find reasonable.

The patch provides a new funciton, vo_draw_alpha_rgb1x(), derieved directly 
from all the three old vo_draw_alpha_rgb12/15/16(), and taking an extra 
argument "depth".

The vo_draw_alpha_rgb1x() can be called directly from other places instead of 
one of the old functions, or those old can be converted to stubs that just 
call vo_draw_alpha_rgb1x() with depth specified accordingly. Please advise 
which way you prefere, then I'll prepare a follow-up patch.

Created against mplayer svn revision 31221.

Signed-off-by: Janusz Krzysztofik <jkrzyszt at tis.icnet.pl>
---
--- libvo/osd.c.orig	2010-05-26 10:57:49.000000000 +0200
+++ libvo/osd.c	2010-05-26 11:46:35.000000000 +0200
@@ -331,6 +331,80 @@ void vo_draw_alpha_init(void){
 	}
 }
 
+void vo_draw_alpha_rgb1x(int w, int h, unsigned char *src, unsigned char *srca,
+                         int srcstride, unsigned char *dstbase, int dststride,
+                         int depth) {
+    int y;
+    for (y = 0; y < h; y++) {
+        register unsigned short *dst = (unsigned short *)dstbase;
+        register int x;
+        for (x = 0; x < w; x++) {
+            if (srca[x]) {
+                switch (depth) {
+#ifdef FAST_OSD
+#ifdef FAST_OSD_TABLE
+                case 12:
+                    dst[x] = fast_osd_12bpp_table[src[x]];
+                    break;
+                case 15:
+                    dst[x] = fast_osd_15bpp_table[src[x]];
+                    break;
+                case 16:
+                    dst[x] = fast_osd_16bpp_table[src[x]];
+                    break;
+#else
+                case 12:
+                    register unsigned int a = src[x] >> 4;
+                    dst[x] = (a <<  8) | (a << 4) | a;
+                    break;
+                case 15:
+                    register unsigned int a = src[x] >> 3;
+                    dst[x] = (a << 10) | (a << 5) | a;
+                    break;
+                case 16:
+                    register unsigned int a = src[x] >> 3;
+                    dst[x] = (a << 11) | ((src[x] >> 2) << 5) | a;
+                    break;
+#endif
+#else
+                case 12:
+                    unsigned char r = dst[x] & 0x0F;
+                    unsigned char g = (dst[x] >> 4) & 0x0F;
+                    unsigned char b = (dst[x] >> 8) & 0x0F;
+                    r = (((r * srca[x]) >> 4) + src[x]) >> 4;
+                    g = (((g * srca[x]) >> 4) + src[x]) >> 4;
+                    b = (((b * srca[x]) >> 4) + src[x]) >> 4;
+                    dst[x] = (b << 8) | (g << 4) | r;
+                    break;
+                case 15:
+                    unsigned char r = dst[x] & 0x1F;
+                    unsigned char g = (dst[x] >>  5) & 0x1F;
+                    unsigned char b = (dst[x] >> 10) & 0x1F;
+                    r = (((r * srca[x]) >> 5) + src[x]) >> 3;
+                    g = (((g * srca[x]) >> 5) + src[x]) >> 3;
+                    b = (((b * srca[x]) >> 5) + src[x]) >> 3;
+                    dst[x] = (b << 10) | (g << 5) | r;
+                    break;
+                case 16:
+                    unsigned char r = dst[x] & 0x1F;
+                    unsigned char g = (dst[x] >>  5) & 0x3F;
+                    unsigned char b = (dst[x] >> 11) & 0x1F;
+                    r = (((r * srca[x]) >> 5) + src[x]) >> 3;
+                    g = (((g * srca[x]) >> 6) + src[x]) >> 2;
+                    b = (((b * srca[x]) >> 5) + src[x]) >> 3;
+                    dst[x] = (b << 11) | (g << 5) | r;
+                    break;
+#endif
+                }
+            }
+        }
+        src += srcstride;
+        srca += srcstride;
+        dstbase += dststride;
+    }
+    return;
+}
+
 void vo_draw_alpha_rgb12(int w, int h, unsigned char* src, unsigned char *srca,
                          int srcstride, unsigned char* dstbase, int dststride) {
     int y;



More information about the MPlayer-dev-eng mailing list