|
|
|
Composite Images with Alpha
Added on 11/29/2004
|
This behavior composites multiple image objects with alpha but does not suffer from the common problem of the images getting ragged or muddled alphas in the process.
--Copyright 2004-2005
--Chuck Neal
--MediaMacros, Inc.
--Enjoy ;)
on compositeImage vImage, vDestImage, vDestRect, vSourceRect, vBackColor
if vBackCOlor = void then vBackColor = rgb(0,0,0)
iDestImage = vDestImage.duplicate()
--Fill with a solid back color
iDestImage.fill(iDestImage.rect, vBackCOlor)
iSourceImage = vImage.duplicate()
-- get the original alpha channel
iAlphaBuffer = vDestImage.extractAlpha()
--get the composite alpha
if iSourceImage.depth = 32 then
iSourceAlphaBuffer = iSourceImage.extractALpha()
else
--create a new super image alpha
iSourceAlphaBuffer = image(iSourceImage.width, iSourceImage.height, 8, #grayscale)
iSourceAlphaBuffer.fill(iSourceAlphaBuffer.rect, rgb(0,0,0))
end if
--Disable both alphas for the copy pricess
vDestImage.useAlpha = FALSE
iSourceImage.useAlpha = FALSE
iDestMask = iAlphaBuffer.createMask()
iDestImage.copyPixels(vDestImage, vDestImage.rect, vDestImage.rect, [#maskimage : iDestMask, #ink : #add, #dither : 1969])
iSourceMask = iSourceImage.extractalpha().createMask()
iDestImage.copyPixels(iSourceImage, vDestRect, vSourceRect, [#maskimage : iSourceMask, #dither : 1969])
--reverse dark to light
iAlphaReverse = image(iSourceImage.width, iSourceImage.height, 8, #grayscale)
--alphatoAdd.duplicate()
iAlphaReverse.fill(iAlphaReverse.rect, rgb(0,0,0))
iAlphaReverse.copyPixels(iSourceAlphaBuffer, iAlphaReverse.rect, iSourceAlphaBuffer.rect, [#ink : #reverse])
iALphaBuffer.copyPixels(iAlphaReverse, vDestRect, vSourceRect, [#ink:#subtractpin])
-- apply the alpha changes
iDestImage.setAlpha(iALphaBuffer)
iDestImage.useAlpha = TRUE
return iDestImage
end
|
|