On Sun, 3 Dec 2000, Andreas Beck wrote:

> > > To catch all cases you need a loop,
> 
> > A loop over what? Over the rgb-compontents? Or over different colordepth?
> 
> Over the width of the expanded version, with a stepsize determined by the
> significant bits of the to-be-expanded one.
> 
> > > which is why I am worrying about performance.
> > What about unrolling the loop?
> 
> You can't do that generically. You'd have to introduce lots of special cases
> for the different color schemes, then.

How about moving this stuff into linear_*/color.c ?

Then you'd have neither switch()'es for special cases nor a loop (if it is
unrolled).

> The algorithm for expanding a right-aligned "value" of length "nowlegth"
> to "exlength" is:
> 
> res=0;
> for(a=exlength-nowlength;a>-nowlength;a-=nowlength)
>       if (a>=0)
>               res|=(value<<a);
>       else
>               res|=(value>>(-a));


If I got you right, it should _basically_ like the attached patch. I know, that
the patch is still wrong, because I tested it. So _don't_ commit it into CVS,
please!!
 

Christoph Egger
E-Mail: [EMAIL PROTECTED]
--- 20001126/degas/lib/libggi/default/color/color.c     Mon Aug 30 07:17:36 1999
+++ degas/lib/libggi/default/color/color.c      Sun Dec  3 14:36:24 2000
@@ -162,14 +162,32 @@
 int GGI_color_TRUE_unmappixel(ggi_visual *vis, ggi_pixel pixel, ggi_color *col)
 {
        color_truepriv *priv = vis->colorpriv;
+       int a;
 
+
+#define EXPAND(a, exlength, nowlength, value, res)     \
+       res = 0;                                        \
+       for (a = exlength - nowlength; a > -nowlength; a -= nowlength) {        \
+               if (a >= 0) {                           \
+                       res |= (value << a);            \
+               } else {                                \
+                       res |= (value >> (-a));         \
+               }                                       \
+       }
+
+
+       EXPAND(a, 16, 16 - priv->red_unmap, pixel & priv->red_mask, col->r);
+       EXPAND(a, 16, 16 - priv->green_unmap, pixel & priv->green_mask, col->g);
+       EXPAND(a, 16, 16 - priv->blue_unmap, pixel & priv->blue_mask, col->b);
+
+#if 0
        col->r = DOSHIFT(pixel & priv->red_mask,
                         priv->red_unmap);
        col->g = DOSHIFT(pixel & priv->green_mask,
                         priv->green_unmap);
        col->b = DOSHIFT(pixel & priv->blue_mask,
                         priv->blue_unmap);
-
+#endif
        return 0;
 }
 

Reply via email to