FUNCNAME(halvetexture)1 static void FUNCNAME(halvetexture)(uchar *src, uint sw, uint sh, uint stride, uchar *dst)
2 {
3 for(uchar *yend = &src[sh*stride]; src < yend;)
4 {
5 for(uchar *xend = &src[sw*BPP], *xsrc = src; xsrc < xend; xsrc += 2*BPP, dst += BPP)
6 {
7 #define OP(c, n) dst[n] = (uint(xsrc[n]) + uint(xsrc[n+BPP]) + uint(xsrc[stride+n]) + uint(xsrc[stride+n+BPP]))>>2
8 PIXELOP
9 #undef OP
10 }
11 src += 2*stride;
12 }
13 }
14
FUNCNAME(shifttexture)15 static void FUNCNAME(shifttexture)(uchar *src, uint sw, uint sh, uint stride, uchar *dst, uint dw, uint dh)
16 {
17 uint wfrac = sw/dw, hfrac = sh/dh, wshift = 0, hshift = 0;
18 while(dw<<wshift < sw) wshift++;
19 while(dh<<hshift < sh) hshift++;
20 uint tshift = wshift + hshift;
21 for(uchar *yend = &src[sh*stride]; src < yend;)
22 {
23 for(uchar *xend = &src[sw*BPP], *xsrc = src; xsrc < xend; xsrc += wfrac*BPP, dst += BPP)
24 {
25 #define OP(c, n) c##t = 0
26 DEFPIXEL
27 #undef OP
28 for(uchar *ycur = xsrc, *xend = &ycur[wfrac*BPP], *yend = &src[hfrac*stride];
29 ycur < yend;
30 ycur += stride, xend += stride)
31 {
32 for(uchar *xcur = ycur; xcur < xend; xcur += BPP)
33 {
34 #define OP(c, n) c##t += xcur[n]
35 PIXELOP
36 #undef OP
37 }
38 }
39 #define OP(c, n) dst[n] = (c##t)>>tshift
40 PIXELOP
41 #undef OP
42 }
43 src += hfrac*stride;
44 }
45 }
46
FUNCNAME(scaletexture)47 static void FUNCNAME(scaletexture)(uchar *src, uint sw, uint sh, uint stride, uchar *dst, uint dw, uint dh)
48 {
49 uint wfrac = (sw<<12)/dw, hfrac = (sh<<12)/dh, darea = dw*dh, sarea = sw*sh;
50 int over, under;
51 for(over = 0; (darea>>over) > sarea; over++);
52 for(under = 0; (darea<<under) < sarea; under++);
53 uint cscale = clamp(under, over - 12, 12),
54 ascale = clamp(12 + under - over, 0, 24),
55 dscale = ascale + 12 - cscale,
56 area = ((ullong)darea<<ascale)/sarea;
57 dw *= wfrac;
58 dh *= hfrac;
59 for(uint y = 0; y < dh; y += hfrac)
60 {
61 const uint yn = y + hfrac - 1, yi = y>>12, h = (yn>>12) - yi, ylow = ((yn|(-int(h)>>24))&0xFFFU) + 1 - (y&0xFFFU), yhigh = (yn&0xFFFU) + 1;
62 const uchar *ysrc = &src[yi*stride];
63 for(uint x = 0; x < dw; x += wfrac, dst += BPP)
64 {
65 const uint xn = x + wfrac - 1, xi = x>>12, w = (xn>>12) - xi, xlow = ((w+0xFFFU)&0x1000U) - (x&0xFFFU), xhigh = (xn&0xFFFU) + 1;
66 const uchar *xsrc = &ysrc[xi*BPP], *xend = &xsrc[w*BPP];
67 #define OP(c, n) c##t = 0
68 DEFPIXEL
69 #undef OP
70 for(const uchar *xcur = &xsrc[BPP]; xcur < xend; xcur += BPP)
71 {
72 #define OP(c, n) c##t += xcur[n]
73 PIXELOP
74 #undef OP
75 }
76 #define OP(c, n) c##t = (ylow*(c##t + ((xsrc[n]*xlow + xend[n]*xhigh)>>12)))>>cscale
77 PIXELOP
78 #undef OP
79 if(h)
80 {
81 xsrc += stride;
82 xend += stride;
83 for(uint hcur = h; --hcur; xsrc += stride, xend += stride)
84 {
85 #define OP(c, n) c = 0
86 DEFPIXEL
87 #undef OP
88 for(const uchar *xcur = &xsrc[BPP]; xcur < xend; xcur += BPP)
89 {
90 #define OP(c, n) c += xcur[n]
91 PIXELOP
92 #undef OP
93 }
94 #define OP(c, n) c##t += ((c<<12) + xsrc[n]*xlow + xend[n]*xhigh)>>cscale
95 PIXELOP
96 #undef OP
97 }
98 #define OP(c, n) c = 0
99 DEFPIXEL
100 #undef OP
101 for(const uchar *xcur = &xsrc[BPP]; xcur < xend; xcur += BPP)
102 {
103 #define OP(c, n) c += xcur[n]
104 PIXELOP
105 #undef OP
106 }
107 #define OP(c, n) c##t += (yhigh*(c + ((xsrc[n]*xlow + xend[n]*xhigh)>>12)))>>cscale
108 PIXELOP
109 #undef OP
110 }
111 #define OP(c, n) dst[n] = (c##t * area)>>dscale
112 PIXELOP
113 #undef OP
114 }
115 }
116 }
117
118 #undef FUNCNAME
119 #undef DEFPIXEL
120 #undef PIXELOP
121 #undef BPP
122
123