#include #include #include #include "tabs.h" #ifdef T386 #define swizbytes(a) (((a)<<24)|(((a)&0xFF00)<<8)|(((a)&0xFF0000)>>8)|((a)>>24)) #else #define swizbytes(a) (a) #endif /* * texture - uses bitblt, logarithmically if f doesn't involve D * but special case some textures whose rows can be packed in 32 bits */ void gtexture(GBitmap *dm, Rectangle r, GBitmap *sm, Fcode f) { Point p, dp; int x, y, d, w, hm, wneed, sld, dld; ulong a, b, lmask, rmask, *ps, *pe, *pp, s[32]; Rectangle savdr; if(rectclip(&r, dm->clipr) == 0) return; dp = sub(sm->clipr.max, sm->clipr.min); if(dp.x==0 || dp.y==0) return; p.x = r.min.x - (r.min.x % dp.x); p.y = r.min.y - (r.min.y % dp.y); f &= 0xF; if(f==S || f==notS){ sld = sm->ldepth; dld = dm->ldepth; w = dp.x << sld; wneed = (dld == sld) ? 32 : 32 >> dld; if((sld == 0 || sld == dld) && sm->clipr.min.x == 0 && sm->r.min.x == 0 && sm->clipr.min.y == 0 && sm->r.min.y == 0 && w <= wneed && wneed%w == 0 && dp.y <= 32 && (dp.y&(dp.y-1))==0) { /* 32-bit word tiling; replicate/convert rows into s[] */ for(y = 0; y < dp.y; y++) { a = swizbytes(sm->base[y]); /* we know sm rows fit in a word */ if(w < wneed) { b = a >> (32-w); for(x = w; x < wneed; x += w) a |= b << (32-x-w); } if(sld != dld) switch(dld) { case 1: a = (tab01[a>>24]<<16) | tab01[(a>>16)&0xFF]; break; case 2: a = tab02[a>>24]; break; case 3: a = tab03[a>>28]; break; default: return; /* don't handle ldepth > 3 yet */ } if(f == notS) a = ~a; s[y] = swizbytes(a); } a = (r.min.x<> a; rmask = ~0UL << (32-((r.max.x<width; hm = dp.y-1; /* we know dp.y is a power of 2 */ for(y = r.min.y; y < r.max.y; y++) { a = s[y&hm]; b = *ps; *ps = ((a^b)&lmask)^b; if(ps < pe) { for(pp = ps+1; ppclipr; rectclip(&dm->clipr, r); if(!eqpt(p, r.min)){ gbitblt(dm, p, sm, sm->clipr, f); d = dp.x; gbitblt(dm, add(p, Pt(d, 0)), sm, sm->clipr, f); for(x=p.x+d; x+dclipr, f); for(y=p.y+d; y+dclipr, f); for(d=dp.x; p.x+dclipr = savdr; } }else{ savdr = dm->clipr; rectclip(&dm->clipr, r); for(y=p.y; yclipr, f); dm->clipr = savdr; } }