/*
* It would be fair to say that this doesn't work for >8-bit screens.
*/
void
flushmemscreen(Rectangle r)
{
VGAscr *scr;
uchar *sp, *disp, *sdisp, *edisp;
int y, len, incs, off, page;
/*
* On some video cards (e.g. Mach64), the palette is used as the
* DAC registers for >8-bit modes. We don't want to set them when the user
* is trying to set a colormap and the card is in one of these modes.
*/
int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
VGAscr *scr;
int x;
static ulong
pixelbits(Memimage *i, Point pt)
{
uchar *p;
ulong val;
int off, bpp, npack;
val = 0;
p = byteaddr(i, pt);
switch(bpp=i->depth){
case 1:
case 2:
case 4:
npack = 8/bpp;
off = pt.x%npack;
val = p[0] >> bpp*(npack-1-off);
val &= (1<<bpp)-1;
break;
case 8:
val = p[0];
break;
case 16:
val = p[0]|(p[1]<<8);
break;
case 24:
val = p[0]|(p[1]<<8)|(p[2]<<16);
break;
case 32:
val = p[0]|(p[1]<<8)|(p[2]<<16)|(p[3]<<24);
break;
}
while(bpp<32){
val |= val<<bpp;
bpp *= 2;
}
return val;
}
a = 0xFF;
r = g = b = 0xAA; /* garbage */
for(chan=img->chan; chan; chan>>=8){
nb = NBITS(chan);
ov = v = val&((1<<nb)-1);
val >>= nb;
while(nb < 8){
v |= v<<nb;
nb *= 2;
}
v >>= (nb-8);
switch(TYPE(chan)){
case CRed:
r = v;
break;
case CGreen:
g = v;
break;
case CBlue:
b = v;
break;
case CAlpha:
a = v;
break;
case CGrey:
r = g = b = v;
break;
case CMap:
p = img->cmap->cmap2rgb+3*ov;
r = *p++;
g = *p++;
b = *p;
break;
}
}
return (r<<24)|(g<<16)|(b<<8)|a;
}
static ulong
rgbatoimg(Memimage *img, ulong rgba)
{
ulong chan;
int d, nb;
ulong v;
uchar *p, r, g, b, a, m;
v = 0;
r = rgba>>24;
g = rgba>>16;
b = rgba>>8;
a = rgba;
d = 0;
for(chan=img->chan; chan; chan>>=8){
nb = NBITS(chan);
switch(TYPE(chan)){
case CRed:
v |= (r>>(8-nb))<<d;
break;
case CGreen:
v |= (g>>(8-nb))<<d;
break;
case CBlue:
v |= (b>>(8-nb))<<d;
break;
case CAlpha:
v |= (a>>(8-nb))<<d;
break;
case CMap:
p = img->cmap->rgb2cmap;
m = p[(r>>4)*256+(g>>4)*16+(b>>4)];
v |= m<<d;
break;
case CGrey:
m = RGB2K(r,g,b);
v |= m<<d;
break;
}
d += nb;
}
// print("rgba2img %.8lux = %.*lux\n", rgba, 2*d/8, v);
return v;
}
Memimage *lastbadi;
Memdata *lastbad;
Memimage *lastbadsrc, *lastbaddst;
int hwaccel = 1;
int hwblank = 1;
int
hwdraw(Memdrawparam *par)
{
int m;
VGAscr *scr;
Memimage *dst, *src;
/*
* If we have an opaque mask and source is one opaque
* pixel we can convert to the destination format and just
* replicate with memset.
*/
m = Simplesrc|Simplemask|Fullmask;
if(scr->fill && (par->state&m)==m && ((par->srgba&0xFF) == 0xFF))
return scr->fill(scr, par->r, par->sdval);
/*
* If no source alpha, an opaque mask, we can just copy the
* source onto the destination. If the channels are the same and
* the source is not replicated, memmove suffices.
*/
src = par->src;
if(scr->scroll && src->data->bdata==dst->data->bdata && !(src->flags&Falpha)
&& (par->state&(Simplemask|Fullmask))==(Simplemask|Fullmask)){
// if(src->zero != dst->zero){
// lastbadsrc = src;
// lastbaddst = dst;
// iprint("#");
// }
return scr->scroll(scr, par->r, par->sr);
}