Bilinear interpolation: Difference between revisions
Content added Content deleted
(Tcl implementation added) |
(→{{header|Tcl}}: Added zkl) |
||
Line 359: | Line 359: | ||
</lang> |
</lang> |
||
=={{header|zkl}}== |
|||
{{trans|C}} |
|||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl. |
|||
Not fast enough to be called slow. |
|||
<lang zkl>fcn lerp(s,e,t){ s + (e-s)*t; } |
|||
fcn blerp(c00,c10,c01,c11, tx,ty){ lerp(lerp(c00,c10,tx), lerp(c01,c11,tx),ty) } |
|||
fcn scale(src, scaleX,scaleY){ |
|||
newWidth,newHeight := Int(scaleX*src.w), Int(scaleY*src.h); |
|||
dst:=PPM(newWidth,newHeight); |
|||
foreach y,x in ([0.0..newHeight-1],[0.0..newWidth-1]){ |
|||
gx:=x/newWidth *(src.w-1); |
|||
gy:=y/newHeight *(src.h-1); |
|||
gxi,gyi:=Int(gx), Int(gy); |
|||
// cxy=RGB, cxy.toBigEndian(3)-->(R,G,B) |
|||
c00,c10 := src[gxi,gyi].toBigEndian(3), src[gxi+1,gyi].toBigEndian(3); |
|||
c01 := src[gxi,gyi+1] .toBigEndian(3); |
|||
c11 := src[gxi+1,gyi+1].toBigEndian(3); |
|||
dst[x,y] = (3).pump(Data(), // Data is a byte bucket |
|||
'wrap(i){ blerp(c00[i],c10[i],c01[i],c11[i], gx-gxi, gy-gyi) }) |
|||
.toBigEndian(0,3); |
|||
} |
|||
dst |
|||
}</lang> |
|||
<lang zkl>img:=PPM.readPPMFile("lena.ppm"); |
|||
img=scale(img,1.5,1.5); |
|||
img.write(File("lena1.5.ppm","wb"));</lang> |
|||
{{out}} |
|||
http://home.comcast.net/~zenkinetic/Images/2Lenas.jpg |