here's what gave me the best results:
I did a small optimization that made it even faster! (Avoiding one sqrt() in some cases)
/Christoffer

-- 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, tImage.getPixel(xNew, yNew, #integer))
       end if
     end if
   end repeat
 end repeat

 tImage.copyPixels(newImage, newImage.rect, newImage.rect)
 put the milliseconds - ms
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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
[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!]

Reply via email to