Farbflash projects: Imaging lingo table | 3-D scene list | Find all | Handler menu | Lingo message window

Ignore:
Timestamp:
10/24/08 12:12:09 (4 years ago)
Author:
alex
Message:

updated movie to incorporate new version of library scripts

File:
1 edited

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--  
    531-- change 22.08.03 
    632-- existing alphachannel now will be preserved 
     
    935-- New Flash Bitmap filter if script "FlashBitmapFilterPS" is present and version > 10.10 => flash bitmap filter was introduced with 10.11 
    1036 
    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 
    4442 
    4543on new me 
     
    5149 
    5250on 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" 
    5452   
    5553  put RETURN & "-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" after str 
    5654  put RETURN & "-- xxxxxxxxxxxxxxxxxx Description" after str 
    57   put RETURN & "on mGetShadowImage me, theImg, shadowColor, shadowDistance, winkel, blur, exponent, theStyle, returnMask, alphaLevel" after str 
     55  put RETURN & "on mGetShadowImage me, theImage, shadowColor, shadowDistance, shadowAngle, blur, exponent, theStyle, returnMask, alphaLevel, dontTrimWhiteSpace" after str 
    5856  put RETURN & "" after str 
    5957   
     
    6462-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
    6563 
    66 on mGetShadowImage me, theImg, shadowColor, shadowDistance, winkel, blur, exponent, theStyle, returnMask, alphaLevel 
    67    
    68   if ilk(theImg) <> #image then return [] 
     64on 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 [] 
    6996  if ilk(shadowColor) <> #color then shadowColor = rgb(0,0,0) 
    7097  if ilk(shadowDistance, #number) = 0 then shadowDistance = 14 
    7198  if ilk(blur, #number) = 0 then blur = 14 
    72   if ilk(winkel, #number) = 0 then winkel = 45 
     99  if ilk(shadowAngle, #number) = 0 then shadowAngle = 45 
    73100   
    74101   
     
    82109  if theStyle <> #cutout then 
    83110    cms = mGetXscript() 
    84     if voidP(cms) then scr = mGetInstance("FlashBitmapFilterPS") 
     111    if listP(cms) then scr = mGetInstance("FlashBitmapFilterPS") 
    85112    else scr = call(#mGetInstance, cms, "FlashBitmapFilterPS") 
    86113    if ilk(scr) = #instance then 
     
    96123            if xlist[n].getaprop(#name) = #ActionScriptObjects then 
    97124              prodVers = xlist[n].getaprop(#version) 
    98               vn = call(#mGetFloatVersionNumber, [mGetXscript()], prodVers) 
     125              vn = call(#mGetFloatVersionNumber, mGetXscript(), prodVers) 
    99126              if ilk(vn, #number) = 1 then flash8XtraPresent = (vn > 10.1) 
    100127              exit repeat 
     
    112139        --      if theStyle = #cutout then 
    113140        --        if not(returnMask) then 
    114         --          winkel = winkel + 180 
    115         --          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) 
    117144        --          -- call(#mPut, [mGetXScript()], i) 
    118         --          theImg.copyPixels(i, i.rect, i.rect) 
     145          --          theImage.copyPixels(i, i.rect, i.rect) 
    119146        --          exit 
    120147        --        end if 
    121148        --      else 
    122149         
    123         rAlt = theImg.rect 
     150          rAlt = theImage.rect 
    124151         
    125152        blur = blur/3.0 
    126153        shadowDistance = shadowDistance / 3. 
    127154         
    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) 
    130157         
    131158        rNeu = i.rect 
     
    134161         
    135162         
     163          if dontTrimWhiteSpace then 
     164             
     165            m  = i.extractAlpha() 
     166            return [i, m, point(0,0)] 
     167             
     168          else 
    136169        -- get the cropped rect: 
    137170        --        croprect = call(#mGetCropRect, [mGetXscript(#ImageUtilityScripts)], i.extractAlpha()) 
     
    158191        return [i2, m, vers] 
    159192         
    160         --      end if 
     193          end if 
    161194         
    162195      end if 
     
    175208   
    176209  --  blur = min(blur, shadowDistance) 
    177   theRect = theImg.rect 
     210  theRect = theImage.rect 
    178211   
    179212  -- radialer verlauf 
     
    235268  pSchatten.fill(rect(blur, blur, (breite - blur), (hoehe - blur)), col) 
    236269   
    237   rad = pi()/180 * winkel 
     270  rad = pi()/180 * shadowAngle 
    238271  halbesblur = blur/2.0 
    239272   
     
    297330    t2.copyPixels(tempimg, theRect, theRect.offset(vhBild, vvBild), [#ink:2]) 
    298331    t2 = t2.createMask() 
    299     --    i2 = theImg.duplicate() 
    300     --    i3 = image(theRect.width, theRect.height, theImg.depth, 0) 
     332    --    i2 = theImage.duplicate() 
     333    --    i3 = image(theRect.width, theRect.height, theImage.depth, 0) 
    301334    --    i3.fill(i3.rect, shadowColor) 
    302335    --    i2.copyPixels(i3, theRect, theRect, [#maskImage:t2]) 
    303336    --    return i2 
    304337     
    305     i3 = image(theRect.width, theRect.height, theImg.depth, 0) 
     338    i3 = image(theRect.width, theRect.height, theImage.depth, 0) 
    306339    i3.fill(i3.rect, shadowColor) 
    307340     
     
    309342      return [t2, i3] 
    310343    else 
    311       theImg.copyPixels(i3, theRect, theRect, [#maskImage:t2]) 
     344      theImage.copyPixels(i3, theRect, theRect, [#maskImage:t2]) 
    312345    end if 
    313346     
    314347  else 
    315     if theImg.depth = 32 and theImg.useAlpha = 1 then 
    316       tempimg.copyPixels(theImg.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) 
    317350    else 
    318351      tempimg.fill(theRect.offset(vhBild, vvBild), rgb(0,0,0)) 
    319352    end if 
    320353     
    321     t2 = image((theRect.width + imgW), (theRect.height + imgH), theImg.depth, 0) 
     354    t2 = image((theRect.width + imgW), (theRect.height + imgH), theImage.depth, 0) 
    322355    t2.fill(t2.rect, shadowColor) 
    323     t2.copyPixels(theImg, theImg.rect.offset(vhBild, vvBild), theImg.rect) 
     356    t2.copyPixels(theImage, theImage.rect.offset(vhBild, vvBild), theImage.rect) 
    324357    return [t2, tempimg, point(vhBild, vvBild)] 
    325358  end if 
Note: See TracChangeset for help on using the changeset viewer.