John Horn (Home) <[EMAIL PROTECTED]> wrote:
> I am unfamilar with imaging lingo, could you help to point me in
> the right direction, a few commands to look up or something.

Hi John,

Here is a chunk of unfinished code that I originally wrote for one of
the Paintbox behaviors in D8's Library Palette.  Its purpose was to make
a bitmap sprite appear transparent by copying all the image data from
the sprites behind it.  The sprites behind may have a variety of inks
(though you will see that I did not complete the treatment of "mask"
ink): to get a transparent effect you could use transparent,
background transparent or matte inks.

I realise that you may not be working directly from sprites but rather
from a set of members.  You could modify the handler so that, instead of
working through sprites 1 to (thisSprite - 1), it works through a list
with the format:

[[#member: < >, #rect: < >, #ink: < >, #blendLevel: < >, #color:  < >,
#bgColor: < >, ... ], ...]

"thatSprite" could take the value of each of the nested property lists
in turn (it might be worthwhile renaming the variable so that it makes
better sense).

Note that the handler uses mapStageToMember() which would be
inappropriate if you are not using sprites: you would have to rework
this section.  Note also that some member types do not have an "image"
property, and so cannot be dealt with in this way.  Shape members
(rects, lines, ovals, ...) can be faked using the draw() command.  Field
members need to be converted to text.

(This code was never used, since the Paintbox behaviors were already
sufficiently complex without dealing with painting on a "transparent"
canvas.  It has thus not been fully tested: I cannot guarantee its
usefulness).

Cheers,

James

------------------------------------------------------------------------
-

on getImageBehind(thisSprite)
  case ilk(thisSprite)of
    #sprite: spriteNumber = thisSprite.spriteNum
    #integer:
      if thisSprite <> the lastChannel then
        spriteNumber = thisSprite
        thisSprite = sprite(thisSprite)
      else
        return #notASprite
      end if
    otherwise
      return #notASprite
  end case

  thisRect = thisSprite.rect
  --Create a blank image the same color as the Stage
  imageData = image(thisRect.width, thisRect.height, the colordepth)
  colorOfStage = paletteIndex(the stageColor)
  colorOfStage.colorType = #rgb
  imageData.fill(imageData.rect, colorOfStage)

  hAdjust = -thisRect.left
  vAdjust = -thisRect.top
  previousSprite = spriteNumber - 1
  repeat with i = 1 to previousSprite
    -- Copy the appropriate part of the sprite into the blank image
    if sprite i intersects spriteNumber then
      thatSprite = sprite(i)
      thatMember = thatSprite.member
      case thatMember.type of
        #bitmap, #text: -- continue
        otherwise
          -- * Other member types don't (yet) have an #image property
          next repeat
      end case

      -- Find which part of thatSprite overlaps our blank image
      thatRect   = thatSprite.rect
      overlap    = intersect(thisRect, thatRect)
      -- Modify thatRect so that it represents the rect of the
      -- member concerned by this overlap.  (* This only works
      -- correctly with unstretched, unrotated and unquadded sprites)
      topLeft     = point(overlap.left, overlap.top)
      topLeft     = mapStageToMember(thatSprite, topLeft)
      bottomRight = point(overlap.right, overlap.bottom) - 1 -- * ??
      bottomRight = mapStageToMember(thatSprite, bottomRight) + 1 -- *
      thatRect    = rect(topLeft, bottomRight)

      -- Determine which options to use for the copyPixels command
      optionsList = [ \
#ink:        thatSprite.ink, \
#blendLevel: thatSprite.blendLevel, \
#color:      thatSprite.color, \
#bgColor:    thatSprite.bgColor \
]
      -- Prepare the image of thatSprite
      if thatSprite.ink = #mask then
        thatImage = getMaskedImage(thatSprite.member)
        optionsList.deleteProp(#ink)
      else
        thatImage = thatSprite.member.image
      end if

      -- Determine which part of imageData thatSprite covers
      destRect = offset(overlap, hAdjust, vAdjust)
      imageData.copyPixels(thatImage, destRect, thatRect, optionsList)
    end if
  end repeat

  return imageData
end getImageBehind


on getMaskedImage(maskedMember)
  -- This handler was never finished
  maskedImage = maskedMember.image

  return maskedImage
end getMaskedImage



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/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