Changeset 18 for trunk/lingosource/castlib3/DropShadowPScript.ls
- Timestamp:
- 10/24/08 12:12:09 (4 years ago)
- File:
-
- 1 edited
-
trunk/lingosource/castlib3/DropShadowPScript.ls (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lingosource/castlib3/DropShadowPScript.ls
r14 r18 1 -- Drop Shadow and Cutout 2 -- Alex da Franca ©2002 3 -- da.franca@online.de 4 1 -- DropShadowPScript 2 ----------------------------------- 3 -- CREATED: 4 -- Alex da Franca c2002 - alex@farbflash.de 5 -- 6 -- DESCRIPTION: 7 -- Apply a Drop Shadow or Cutout to an image object. 8 -- It started as drop shadow for rectangles using plain lingo. 9 -- In D10.1 Flash filters appeared and since then we can do much faster 10 -- and much better blur and therefore drop shadows. 11 -- My frontend to flash filters is the script "FlashBitmapFilterPS" 12 -- So as soon as this script is found in one of the castlibs, the flash bitmap filters are used 13 -- instead of the slower and limited to rects lingo solution. 14 -- 15 -- REQUIRES: 16 -- script "commonMovieScript" 17 -- optional: script "FlashBitmapFilterPS" 18 -- 19 -- USAGE: 20 -- There is only one single function: mGetShadowImage 21 -- Use that function to pply a shadow to an image object. 22 -- EXAMPLE: 23 -- 24 -- imgList = xscr(#DropShadowPScript).mGetShadowImage(myImageObject, rgb(0,0,0), 6, 55, 18, 1, #shadow) 25 -- newShadowImage = imgList[1] 26 -- maskeImage = imgList[2] 27 -- shadowOffset = imgList[3] 28 -- 29 -- HISTORY: 30 -- 5 31 -- change 22.08.03 6 32 -- existing alphachannel now will be preserved … … 9 35 -- New Flash Bitmap filter if script "FlashBitmapFilterPS" is present and version > 10.10 => flash bitmap filter was introduced with 10.11 10 36 11 ----------- 12 -- Accepts: 13 ----------- 14 -- theImg = [#format:#imageObject, #comment:"source image"] 15 -- shadowColor = [#format:#color, #default:rgb(0,0,0), #comment:"Shadow Color"] 16 -- shadowDistance = [#format:#integer, #default:14, #range:[#min:2, #max:40], #comment:"Schattenhoehe:"] 17 -- winkel = [#format:#integer, #default:45, #range:[#min:0, #max:360], #comment:"Winkel:"] 18 -- blur = [#format:#integer, #default:14, #range:[#min:2, #max:40], #comment:"Schatten Blur:"] 19 -- exponent = [#format:#boolean, #default:1, #comment:"exponentiale grauverteilung:"] 20 -- theStyle = [#format:#symbol, #default:#shadow, #range:[#shadow, #cutout], #comment:"Shadow style:"] 21 -- returnMask = [#format:#boolean, #default:0, #comment:"if style = #cutout return image and mask instead of drawing into iamge"] 22 -- alphaLevel = [#format:#float #integer, #default:1.0, #range:[#min:0.0, #max:1.0], #comment:"Only used for flash filters: alphalevel (if integer is used -> range => 0 - 100)"] 23 24 ----------- 25 -- Returns: 26 ----------- 27 -- if <theStyle> = #shadow then returns linear list with: 28 -- imageObject, the original image copied onto a border for the drop shadow 29 -- imageObject (8-bit #grayscale), to use as mask for the shadow 30 -- point, the offset of the returned image from top left 31 32 -- if <theStyle> = #cutout then returns nothing, but rather draws the shadow directly into the imageObject <theImg>, which was passed to the function 33 -- except when <returnMask> is true 34 35 36 ----------- 37 -- Requires: 38 ----------- 39 -- script "commonMovieScript" 40 -- optional: script "FlashBitmapFilterPS" 41 42 43 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 37 -- Scriptmarker (15.10.2008 at 10:34 Uhr): alex changes // Scriptmarker 38 -- added paramater to prevent trimwhitespace, when using flash bitmap filters for drop shadows 39 ----------------------------------- 40 41 44 42 45 43 on new me … … 51 49 52 50 on interface me 53 str = "DropShadowPScript by alex da franca ©2003 -- alex@farbflash.de -- all rigths reserved"51 str = "DropShadowPScript by alex da franca c2003 -- alex@farbflash.de -- all rigths reserved" 54 52 55 53 put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str 56 54 put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str 57 put RETURN & "on mGetShadowImage me, theIm g, shadowColor, shadowDistance, winkel, blur, exponent, theStyle, returnMask, alphaLevel" after str55 put RETURN & "on mGetShadowImage me, theImage, shadowColor, shadowDistance, shadowAngle, blur, exponent, theStyle, returnMask, alphaLevel, dontTrimWhiteSpace" after str 58 56 put RETURN & "" after str 59 57 … … 64 62 -- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 65 63 66 on mGetShadowImage me, theImg, shadowColor, shadowDistance, winkel, blur, exponent, theStyle, returnMask, alphaLevel 67 68 if ilk(theImg) <> #image then return [] 64 on mGetShadowImage me, theImage, shadowColor, shadowDistance, shadowAngle, blur, exponent, theStyle, returnMask, alphaLevel, dontTrimWhiteSpace 65 ----------------------------------- 66 -- ACTION: Apply a Drop Shadow or Cutout to an image object. 67 -- As soon as this script is found in one of the castlibs, the flash bitmap filters are used 68 -- instead of the slower and limited to rects lingo solution. 69 -- INPUT: 70 -- <theImage> = [#format:#imageObject, #comment:"source image"] 71 -- <shadowColor> = [#format:#color, #default:rgb(0,0,0), #comment:"Shadow Color"] 72 -- <shadowDistance> = [#format:#integer, #default:14, #range:[#min:2, #max:40], #comment:"Schattenhoehe:"] 73 -- <shadowAngle> = [#format:#integer, #default:45, #range:[#min:0, #max:360], #comment:"shadowAngle:"] 74 -- <blur> = [#format:#integer, #default:14, #range:[#min:2, #max:40], #comment:"Schatten Blur:"] 75 -- <exponent> = [#format:#boolean, #default:1, #comment:"exponentiale grauverteilung:"] 76 -- <theStyle> = [#format:#symbol, #default:#shadow, #range:[#shadow, #cutout], #comment:"Shadow style:"] 77 -- <returnMask> = [#format:#boolean, #default:0, #comment:"if style = #cutout return image and mask instead of drawing into image"] 78 -- <alphaLevel> = [#format:#float #integer, #default:1.0, #range:[#min:0.0, #max:1.0], #comment:"Only used for flash filters: alphalevel (if integer is used -> range => 0 - 100)"] 79 -- <dontTrimWhiteSpace> = [#format:#boolean, #default:0, #comment:"If using flash bitmap filters, flag to NOT trimwhitespace, so that the image object will retain its size"] 80 -- RETURNS: 81 -- if <theStyle> = #shadow then returns linear list with: 82 -- imageObject, the original image copied onto a border for the drop shadow 83 -- imageObject (8-bit #grayscale), to use as mask for the shadow 84 -- point, the offset of the returned image from top left 85 -- 86 -- if <theStyle> = #cutout then returns nothing, but rather draws the shadow directly into the imageObject <theImage>, which was passed to the function 87 -- except when <returnMask> is true 88 -- EXAMPLE: 89 -- imgList = xscr(#DropShadowPScript).mGetShadowImage(myImageObject, rgb(0,0,0), 6, 55, 18, 1, #shadow) 90 -- newShadowImage = imgList[1] 91 -- maskeImage = imgList[2] 92 -- shadowOffset = imgList[3] 93 ----------------------------------- 94 95 if ilk(theImage) <> #image then return [] 69 96 if ilk(shadowColor) <> #color then shadowColor = rgb(0,0,0) 70 97 if ilk(shadowDistance, #number) = 0 then shadowDistance = 14 71 98 if ilk(blur, #number) = 0 then blur = 14 72 if ilk( winkel, #number) = 0 then winkel= 4599 if ilk(shadowAngle, #number) = 0 then shadowAngle = 45 73 100 74 101 … … 82 109 if theStyle <> #cutout then 83 110 cms = mGetXscript() 84 if voidP(cms) then scr = mGetInstance("FlashBitmapFilterPS")111 if listP(cms) then scr = mGetInstance("FlashBitmapFilterPS") 85 112 else scr = call(#mGetInstance, cms, "FlashBitmapFilterPS") 86 113 if ilk(scr) = #instance then … … 96 123 if xlist[n].getaprop(#name) = #ActionScriptObjects then 97 124 prodVers = xlist[n].getaprop(#version) 98 vn = call(#mGetFloatVersionNumber, [mGetXscript()], prodVers)125 vn = call(#mGetFloatVersionNumber, mGetXscript(), prodVers) 99 126 if ilk(vn, #number) = 1 then flash8XtraPresent = (vn > 10.1) 100 127 exit repeat … … 112 139 -- if theStyle = #cutout then 113 140 -- if not(returnMask) then 114 -- winkel = winkel+ 180115 -- shdparams = [#distance: shadowDistance, #angle: winkel, #alpha: alphaLevel, #quality: 3, #blurX: blur, #blurY: blur, #shadowcolor: shadowColor, #highlightalpha:0.0, #type:"inner"]116 -- i = call(#mBevel, [scr], theImg, shdparams)141 -- shadowAngle = shadowAngle + 180 142 -- shdparams = [#distance: shadowDistance, #angle: shadowAngle, #alpha: alphaLevel, #quality: 3, #blurX: blur, #blurY: blur, #shadowcolor: shadowColor, #highlightalpha:0.0, #type:"inner"] 143 -- i = call(#mBevel, [scr], theImage, shdparams) 117 144 -- -- call(#mPut, [mGetXScript()], i) 118 -- theImg.copyPixels(i, i.rect, i.rect)145 -- theImage.copyPixels(i, i.rect, i.rect) 119 146 -- exit 120 147 -- end if 121 148 -- else 122 149 123 rAlt = theImg.rect150 rAlt = theImage.rect 124 151 125 152 blur = blur/3.0 126 153 shadowDistance = shadowDistance / 3. 127 154 128 shdparams = [#distance: shadowDistance, #angle: winkel, #alpha: alphaLevel, #quality: 3, #blurX: blur, #blurY: blur, #color: shadowColor]129 i = call(#mDropShadow, scr, theImg, shdparams)155 shdparams = [#distance: shadowDistance, #angle: shadowAngle, #alpha: alphaLevel, #quality: 3, #blurX: blur, #blurY: blur, #color: shadowColor] 156 i = call(#mDropShadow, scr, theImage, shdparams) 130 157 131 158 rNeu = i.rect … … 134 161 135 162 163 if dontTrimWhiteSpace then 164 165 m = i.extractAlpha() 166 return [i, m, point(0,0)] 167 168 else 136 169 -- get the cropped rect: 137 170 -- croprect = call(#mGetCropRect, [mGetXscript(#ImageUtilityScripts)], i.extractAlpha()) … … 158 191 return [i2, m, vers] 159 192 160 --end if193 end if 161 194 162 195 end if … … 175 208 176 209 -- blur = min(blur, shadowDistance) 177 theRect = theIm g.rect210 theRect = theImage.rect 178 211 179 212 -- radialer verlauf … … 235 268 pSchatten.fill(rect(blur, blur, (breite - blur), (hoehe - blur)), col) 236 269 237 rad = pi()/180 * winkel270 rad = pi()/180 * shadowAngle 238 271 halbesblur = blur/2.0 239 272 … … 297 330 t2.copyPixels(tempimg, theRect, theRect.offset(vhBild, vvBild), [#ink:2]) 298 331 t2 = t2.createMask() 299 -- i2 = theIm g.duplicate()300 -- i3 = image(theRect.width, theRect.height, theIm g.depth, 0)332 -- i2 = theImage.duplicate() 333 -- i3 = image(theRect.width, theRect.height, theImage.depth, 0) 301 334 -- i3.fill(i3.rect, shadowColor) 302 335 -- i2.copyPixels(i3, theRect, theRect, [#maskImage:t2]) 303 336 -- return i2 304 337 305 i3 = image(theRect.width, theRect.height, theIm g.depth, 0)338 i3 = image(theRect.width, theRect.height, theImage.depth, 0) 306 339 i3.fill(i3.rect, shadowColor) 307 340 … … 309 342 return [t2, i3] 310 343 else 311 theIm g.copyPixels(i3, theRect, theRect, [#maskImage:t2])344 theImage.copyPixels(i3, theRect, theRect, [#maskImage:t2]) 312 345 end if 313 346 314 347 else 315 if theIm g.depth = 32 and theImg.useAlpha = 1 then316 tempimg.copyPixels(theIm g.extractalpha(), theRect.offset(vhBild, vvBild), theRect)348 if theImage.depth = 32 and theImage.useAlpha = 1 then 349 tempimg.copyPixels(theImage.extractalpha(), theRect.offset(vhBild, vvBild), theRect) 317 350 else 318 351 tempimg.fill(theRect.offset(vhBild, vvBild), rgb(0,0,0)) 319 352 end if 320 353 321 t2 = image((theRect.width + imgW), (theRect.height + imgH), theIm g.depth, 0)354 t2 = image((theRect.width + imgW), (theRect.height + imgH), theImage.depth, 0) 322 355 t2.fill(t2.rect, shadowColor) 323 t2.copyPixels(theIm g, theImg.rect.offset(vhBild, vvBild), theImg.rect)356 t2.copyPixels(theImage, theImage.rect.offset(vhBild, vvBild), theImage.rect) 324 357 return [t2, tempimg, point(vhBild, vvBild)] 325 358 end if
Note: See TracChangeset
for help on using the changeset viewer.
