--begin aspect-ratio.lua this.outlets = 3 dimx = 320 dimy = 240 outx = 0 outy = 0 offx = 0 offy = 0 S = .75 function dim(x,y) dimx = x dimy = y end function list(w,h) -- compute the new image shape outx = dimx outy = math.floor((dimx / w) * h) offx = 0 offy = (dimy - outy) / 2 --[[if this creates a y bigger than the origial image (i.e. if it would require letterboxing), than crop it the other way...]]-- if outy > dimy then outx = math.floor((dimy / h) * w) outy = dimy offx = (dimx - outx) / 2 offy = 0 end out() end function out() --output dim & offset messages to jit.submatrix output = {"dim",outx,outy} output1 = {"offset",offx,offy} --output size message to jit.pwindow output2 = {"size",math.floor(outx * S),math.floor(outy * S)} --output framerect message to jit.lcd output3 = {"framerect",offx,offy,outx + offx - 1,outy + offy - 1} outlet(0,output) outlet(0,output1) outlet(1,output2) outlet(2,"clear") outlet(2,output3) outlet(2,"bang") end function size(s) S = s out() end --end Lua