cinap's draw optimization for byte-aligned images, and replace "(x&y)? 1: 0 with "(x&y) != 0". Reference: /n/atom/patch/applied/memdrawbytes Date: Tue Apr 15 16:37:37 CES 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/libmemdraw/draw.c Tue Apr 15 16:35:20 2014 +++ /sys/src/libmemdraw/draw.c Tue Apr 15 16:35:22 2014 @@ -52,7 +52,6 @@ void memimageinit(void) { - extern void memdrawallocinit(void); static int didinit = 0; if(didinit) @@ -222,7 +221,7 @@ int splitcoords; Rectangle omr; - if(r->min.x>=r->max.x || r->min.y>=r->max.y) + if(badrect(*r)) return 0; splitcoords = (p0->x!=p1->x) || (p0->y!=p1->y); /* clip to destination */ @@ -1471,7 +1470,7 @@ end = p->bytey0e + y*p->bwidth; cmap = p->img->cmap->cmap2rgb; convgrey = p->convgrey; - copyalpha = (p->img->flags&Falpha) ? 1 : 0; + copyalpha = (p->img->flags&Falpha) != 0; w = buf; dx = p->dx; @@ -1528,8 +1527,8 @@ static void writecmap(Param *p, uchar *w, Buffer src) { - uchar *cmap, *red, *grn, *blu; - int i, dx, delta; + uchar *cmap, *red, *grn, *blu, *alpha; + int i, dx, delta, a, m; cmap = p->img->cmap->rgb2cmap; @@ -1539,8 +1538,20 @@ blu = src.blu; dx = p->dx; - for(i=0; i>4)*256+(*grn>>4)*16+(*blu>>4)]; + if(p->img->flags&Falpha){ + alpha = src.alpha; + m = p->img->shift[CMap]/8; + a = p->img->shift[CAlpha]/8; + for(i=0; i>4)*256+(*grn>>4)*16+(*blu>>4)]; + } + } else { + for(i=0; i>4)*256+(*grn>>4)*16+(*blu>>4)]; + } } #define DBG if(0) @@ -1566,7 +1577,7 @@ convgrey = p->convgrey; /* convert rgb to grey */ isgrey = img->flags&Fgrey; alphaonly = p->alphaonly; - copyalpha = (img->flags&Falpha) ? 1 : 0; + copyalpha = (img->flags&Falpha) != 0; DBG print("copyalpha %d alphaonly %d convgrey %d isgrey %d\n", copyalpha, alphaonly, convgrey, isgrey); /* if we can, avoid processing everything */ @@ -1618,16 +1629,17 @@ *w++ = RGB2K(ured, ugrn, ublu); DBG print("%x\n", w[-1]); }else{ - *w++ = brepl[(u >> img->shift[CBlue]) & img->mask[CBlue]]; - *w++ = grepl[(u >> img->shift[CGreen]) & img->mask[CGreen]]; - *w++ = rrepl[(u >> img->shift[CRed]) & img->mask[CRed]]; + w[0] = ublu; + w[1] = ugrn; + w[2] = ured; + w += 3; } } r += nb; if(r == end) r = begin; } - + b.alpha = copyalpha ? buf : &ones; b.rgba = (ulong*)buf; if(alphaonly){ @@ -1671,7 +1683,6 @@ dx = p->dx; nb = img->depth/8; - mask = (nb==4) ? 0 : ~((1<depth)-1); isalpha = img->flags&Falpha; isgrey = img->flags&Fgrey; @@ -1683,6 +1694,37 @@ adelta = 0; } + if((img->flags&Fbytes) != 0){ + int ogry, ored, ogrn, oblu, oalp; + + ogry = img->shift[CGrey]/8; + ored = img->shift[CRed]/8; + ogrn = img->shift[CGreen]/8; + oblu = img->shift[CBlue]/8; + oalp = img->shift[CAlpha]/8; + + for(i=0; idepth)-1); for(i=0; i