I’m now trying to make a generalised JPEG-style encoder with a user-specified tile size. I want to use David’s trick of generating a image of individual IDCT tiles. I’ve tried doing it using at "idct"
, but with larger tile sizes it gets very slow. I want to generate the tiles directly from cosines but I’m not sure how. This one does both at the same time, and I want the first to be what the second is now.
rm
tw=8
th=8
{$tw^2},{$th^2},1,1
#slow
+f "!((x%("$tw"+1))||(y%("$th"+1)))?255" at. "idct",$tw,$th
#should eventually be the faster way
f[0] "begin(tw="$tw";th="$th");
tx=(x-(x%tw))/tw;
ty=(y-(y%th))/th;
cx=cos((x*tx/tw+(1*tx))*pi);
cy=cos((y*ty/th+(1*ty))*pi);
cx*cy
"
rv
nm[-2,-1] real,mine
n 0,255
I’ve got something which looks similar but it’s a bit off. I don’t know if there’s a square root involved…
rm
tw=8
th=8
{$tw^2},{$th^2},1,1
+f "!((x%("$tw"+1))||(y%("$th"+1)))?255" at. "idct",$tw,$th
f[0] "begin(tw="$tw";th="$th");
tx=(x-(x%tw))/tw;
ty=(y-(y%th))/th;
cx=cos((2*x+1)*tx*pi*0.5/tw)/sqrt(tw);
cy=cos((2*y+1)*ty*pi*0.5/th)/sqrt(th);
tx!=0?(cx*=sqrt(2));
ty!=0?(cy*=sqrt(2));
val=cx*cy;
((tx+ty)%2)?(val*=-1);
val
"