From 96a94c38917bf52c17cc1a280cbb672f4d1d13d3 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 12 Apr 2014 21:59:52 +0200 Subject: libmemdraw: improve readbyte() and writebyte() routines remove unused memsetb() routine. replace foo ? 1 : 0 with foo != 0 avoid double calculation of rgb components in readbyte() handle byte aligned color components in writebyte() which lets us avoid the read-modify-write and the shifting. surprisingly, the branches in the loop are way less important than avoiding the memory access. this change makes ganes/snes playable at -3 scaling. --- sys/src/libmemdraw/draw.c | 56 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'sys/src') diff --git a/sys/src/libmemdraw/draw.c b/sys/src/libmemdraw/draw.c index 3bd5ff0e7..4a15fac7d 100644 --- a/sys/src/libmemdraw/draw.c +++ b/sys/src/libmemdraw/draw.c @@ -1496,7 +1496,7 @@ readcmap(Param *p, uchar *buf, int y) 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; @@ -1603,7 +1603,7 @@ readbyte(Param *p, uchar *buf, int y) 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 */ @@ -1655,16 +1655,17 @@ DBG print("g %x %x %x\n", ured, ugrn, ublu); *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){ @@ -1708,7 +1709,6 @@ writebyte(Param *p, uchar *w, Buffer src) dx = p->dx; nb = img->depth/8; - mask = (nb==4) ? 0 : ~((1<depth)-1); isalpha = img->flags&Falpha; isgrey = img->flags&Fgrey; @@ -1720,6 +1720,37 @@ writebyte(Param *p, uchar *w, Buffer src) 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