-- -- polar map correction, based on Paul Bourke's algo/details at -- http://local.wasp.uwa.edu.au/~pbourke/texture/polargrid/ -- converted to Lua/gluas by Philip Staiger, TheBest3D.com -- on November 8, 2006 in about 2 hours - that was fun! -- modified for Pixopedia 24 by Sinisa Petric, 2008 -- also did a little bit of optimizations to reduce repetitive -- calculations when indexing an array (using the 'indx' variable -- -- Note: in gluas, width and height are built-in variables, set -- automatically to the width and height of the image (in pixels of course) image_OUT = 0 image_INP = 1 PI = 3.1415926535 -- memories from college :-) TWOPI = 2 * PI local imageoutR = {vp24_height*vp24_width} -- preallocate buffers of desired size local imageoutG = {vp24_height*vp24_width} local imageoutB = {vp24_height*vp24_width} local x, y, r, g, b, a, x2 local i, j, theta, phi, phi2, indx -- let's get busy -- -- transform each pixel and temporarily store in the out buffers indx = 0 -- optimized for speed for y=0, vp24_height-1 do theta = PI * (y - (vp24_height-1)/2.0) / (vp24_height-1) for x=0, vp24_width-1 do phi = TWOPI * (x - vp24_width/2.0) / vp24_width phi2 = phi * math.cos(theta) x2 = phi2 * vp24_width / TWOPI + vp24_width/2 if ( ( x2 < 0 ) or ( x2 > vp24_width-1 ) ) then -- something bad happened - flag as red? - Should never happen r = 1.0 g = 0.0 b = 0.0 else r, g, b = fp24_getImageRGB(image_INP, x2, y ) end -- temporarily store the pixel in the out buffers imageoutR[indx] = r imageoutG[indx] = g imageoutB[indx] = b indx = indx + 1 -- optimized for speed end fp24_showProgress(y, vp24_height) end -- -- finally send stored 'out' image back out to the imaging system -- -- indx = 0 -- optimized for better speed for y = 0, vp24_height - 1 do for x = 0, vp24_width - 1 do r = imageoutR[indx] g = imageoutG[indx] b = imageoutB[indx] fp24_setImageRGB(image_OUT, x, y, r, g, b) indx = indx + 1 -- optimized for better speed end fp24_showProgress(y, vp24_height) end