I added crappy anti-alias... :)
-- Parentscript "spherizeFilter"
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on new me
return me
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-- optional parameters tPercent, tCenter, tRadius
-- defaults: tPercent=100%, tCenter=center of image
on spherize me, tImage, tPercent, tCenter, tRadius
ms = the milliseconds
w = tImage.width
h = tImage.height
if voidP(tPercent) then tPercent=100.0
if voidP(tCenter) then tCenter = point(w/2, h/2)
if voidP(tRadius) then tRadius = min(w/2, h/2)
RadiusP2 = tRadius*tRadius --the power 2 of tRadius (For comparing non
sqrted value below)
newImage = tImage.duplicate()
centerX = tCenter[1]
centerY = tCenter[2]
rr = tRadius / sqrt(1- power(1-tPercent/100.0, 2) )
f = asin(me, tRadius/rr) -- 100%: pi/2
repeat with y = 0 to h-1
repeat with x = 0 to w-1
deltaX = x - centerX
deltaY = y - centerY
d0b = (deltaX*deltaX) + (deltaY*deltaY)
if d0b<RadiusP2 then -- same as d0<tRadius
if d0b>0 then --same as d0>0
d0 = sqrt(d0b) --Do the sqrt only if neccesary
d1 = tRadius * asin(me, d0/rr)
k = d1/d0/f
xNew = centerX + (deltaX * k)
yNew = centerY + (deltaY * k)
newImage.setPixel(x, y, interpolateCol(xNew, yNew, tImage))
end if
end if
end repeat
end repeat
tImage.copyPixels(newImage, newImage.rect, newImage.rect)
put the milliseconds - ms
end
-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
on interpolateCol(xNew, yNew, tImage)
maxX = tImage.width - 1
maxY = tImage.height - 1
xLow = 0
xHi = 0
yLow = 0
yHi = 0
if xNew > 0 Then
xLow = floor(xNew)
end if
if xNew < maxX then
xHi = ceil(xNew)
else
xHi = xLow
end if
if yNew > 0 then
yLow = floor(yNew)
end if
if yNew < maxY then
yHi = ceil(yNew)
else
yHi = yLow
end if
col1 = tImage.getPixel(xLow, yLow)
col2 = tImage.getPixel(xHi, yLow)
col3 = tImage.getPixel(xLow, yHi)
col4 = tImage.getPixel(xHi, yHi)
colR1 = col1.red
colR2 = col2.red
colR3 = col3.red
colR4 = col4.red
colRA = (colR1 + colR2 + colR3 + colR4) / 4
colG1 = col1.green
colG2 = col2.green
colG3 = col3.green
colG4 = col4.green
colGA = (colG1 + colG2 + colG3 + colG4) / 4
colB1 = col1.blue
colB2 = col2.blue
colB3 = col3.blue
colB4 = col4.blue
colBA = (colB1 + colB2 + colB3 + colB4) / 4
colAVG = color(#rgb, colRA, colGA, colBA)
return colAVG
end
on floor val
if val < integer(val) then
val = integer(val) - 1
else
val = integer(val)
end if
return val
end
on ceil val
if val < integer(val) then
val = integer(val)
else
val = integer(val) + 1
end if
return val
end
on asin me, ratio
if ratio < 1 and ratio > -1 then
RETURN atan(ratio/sqrt(1.0 - (ratio * ratio)))
else if ratio = 1 then
RETURN pi()/2
else if ratio = -1 then
RETURN -pi()/2
end if
end
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Alex da Franca
Verzonden: dinsdag 9 mei 2006 8:16
Aan: Lingo programming discussion list
Onderwerp: Re: <lingo-l> spheroid distortion
Am 08.05.2006 um 23:22 schrieb Christoffer Enedahl:
>
>>
>> here's what gave me the best results:
> I did a small optimization that made it even faster! (Avoiding one
> sqrt() in some cases)
good idea !
thanks.
---------------------------
|||
a¿ex
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[email protected] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[email protected] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]