Bilinear interpolation: Difference between revisions

Content added Content deleted
Line 1,325: Line 1,325:


var Game = BilinearInterpolation.new("Lenna100.jpg", "Lenna100_larger.png", 1.6, 1.6)</lang>
var Game = BilinearInterpolation.new("Lenna100.jpg", "Lenna100_larger.png", 1.6, 1.6)</lang>

=={{header|Yabasic}}==
{{trans|Nim}}
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Bilinear_interpolation
// Adapted from Nim to Yabasic by Galileo, 01/2022

import ReadFromPPM2

sub lerp(s, e, t)
return s + (e - s) * t
end sub
sub blerp(c00, c10, c01, c11, tx, ty)
return lerp(lerp(c00, c10, tx), lerp(c01, c11, tx), ty)
end sub
sub scale(scaleX, scaleY)
local width, height, x, y, gx, gy, gxi, gyi, gxf, gyf, c00$, c10$, c01$, c11$
width = peek("winwidth")
height = peek("winheight")
let newWidth = int(width * scaleX)
let newHeight = int(height * scaleY)
dim result(newWidth, newHeight, 3)
for x = 1 to newWidth
for y = 1 to newHeight:
let gx = x * (width - 1) / newWidth
let gy = y * (height - 1) / newHeight
let gxi = int(gx)
let gyi = int(gy)
let gxf = gx - gxi
let gyf = gy - gyi
let c00$ = right$(getbit$(gxi, gyi, gxi, gyi), 6)
let c10$ = right$(getbit$(gxi + 1, gyi, gxi + 1, gyi), 6)
let c01$ = right$(getbit$(gxi, gyi + 1, gxi, gyi + 1), 6)
let c11$ = right$(getbit$(gxi + 1, gyi + 1, gxi + 1, gyi + 1), 6)
result(x, y, 1) = int(blerp(dec(left$(c00$, 2)), dec(left$(c10$, 2)), dec(left$(c01$, 2)), dec(left$(c11$, 2)), gxf, gyf))
result(x, y, 2) = int(blerp(dec(mid$(c00$, 3, 2)), dec(mid$(c10$, 3, 2)), dec(mid$(c01$, 3, 2)), dec(mid$(c11$, 3, 2)), gxf, gyf))
result(x, y, 3) = int(blerp(dec(right$(c00$, 2)), dec(right$(c10$, 2)), dec(right$(c01$, 2)), dec(right$(c11$, 2)), gxf, gyf))
next
next
end sub
readPPM("lena.ppm")
print "Be patient, please ..."
scale(1.6, 1.6)
close window
open window newWidth, newHeight
for x = 1 to newWidth
for y = 1 to newHeight
color result(x, y, 1), result(x, y, 2), result(x, y, 3)
dot x, y
next
next</lang>


=={{header|zkl}}==
=={{header|zkl}}==