2 src
= tonumber(arg
[2]);
3 dest
= tonumber(arg
[3]);
5 bits8
= (arg
[5] == "8");
9 coeffs_for
= function(xpos
, srcsize
, dstsize
, alpha
)
11 local center
= math
.floor(xpos
* srcsize
/ dstsize
);
12 for i
= -alpha
+ 1, alpha
do
13 local point
= center
+ i
;
14 local x
= point
+ 0.5 - xpos
* srcsize
/ dstsize
- 0.5 * srcsize
/ dstsize
;
15 if x
< -1e-10 or x
> 1e-10 then
16 local xpi
= x
* math
.pi
;
17 if point
>= 0 and point
< srcsize
then
18 ret
[point
] = a
* math
.sin(xpi
) * math
.sin(xpi
/ a
) / (xpi
* xpi
);
21 if point
>= 0 and point
< srcsize
then
28 for k
, v
in pairs(ret
) do
31 for k
, v
in pairs(ret
) do
32 ret
[k
] = math
.floor(coeffscale
* ret
[k
] / sum
+ 0.5);
37 emit_pixel
= function(xpos
, srcsize
, dstsize
, alpha
)
38 local t
= coeffs_for(xpos
, srcsize
, dstsize
, alpha
);
39 io
.stdout
:write("tmp[" .. xpos
.. "]=(");
40 for k
,v
in pairs(t
) do
41 io
.stdout
:write(v
.. "*src[" .. k
.. "]+");
43 io
.stdout
:write("0)/" .. coeffscale
.. ";\n");
46 emit_fn_prologue
= function(name
, dstsize
, b8f
)
48 io
.stdout
:write("void " .. name
.. "(unsigned char* dst, unsigned char* src)\n");
50 io
.stdout
:write("void " .. name
.. "(unsigned short* dst, unsigned short* src)\n");
52 io
.stdout
:write("{\n");
53 io
.stdout
:write("int tmp[" .. dstsize
.. "];\n");
56 emit_fn_epilogue
= function(dstsize
, b8f
)
57 io
.stdout
:write("for(int i = 0; i < " .. dstsize
.. "; i++)\n");
58 io
.stdout
:write("if(tmp[i] < 0) dst[i] = 0;\n");
60 io
.stdout
:write("else if(tmp[i] > 255) dst[i] = 255;\n");
62 io
.stdout
:write("else if(tmp[i] > 65535) dst[i] = 65535;\n");
64 io
.stdout
:write("else dst[i] = tmp[i];\n");
65 io
.stdout
:write("}\n");
68 emit_fn
= function(name
, srcsize
, dstsize
, alpha
, b8f
)
69 emit_fn_prologue(name
, dstsize
, b8f
);
70 for i
= 0, dstsize
- 1 do
71 emit_pixel(i
, srcsize
, dstsize
, alpha
)
73 emit_fn_epilogue(dstsize
, b8f
);
76 emit_fn(fnname
, src
, dest
, a
, bits8
);