In 2d if you are trying to perform alpha blending (transparency) then you will need to use the writepixelfast/readpixelfast commands - first read the background image's pixel color components (it may be stored in a bank or array for a reasonable speed increase), read the pixel color of the pixel in the image you want to alpha blend, calculate the new red/green/blue components values based on these figures and the alpha value for the pixel (this could also be all stored in an array or bank for a reasonable speed increase) then you will need to draw the resulting pixel with writepixelfast.
This obviously means you have to iterate through all the pixels in the image - however one way you can optimise it by not performing the calculation for pixels which are completely transparent or completely opaque.
something like this :
(I may have taken some of this from the code archives a long time ago, it is very useful)
RGB=readpixelfast(x,y,imagebuffer(your image handle goes here))
BRGB=readpixelfast(x,y,backbuffer()) ;background rgb value
Alpha#=0.5 ;for example 50% transparent.
;if you want each pixel to have its own Alpha value you will need to store this yourself as blitz3d/blitzplus in 2d cannot read the alpha values using the readpixel commands, however you can store them in a bank by either creating your own image format or by obtaining the alpha values from the image files directly when loading
bR = (BRGB Shr 16) And 255
bG = (BRGB Shr 8 ) And 255
bB = (BRGB ) And 255
dR = Float(((RGB Shr 16) And 255) - bR)*Alpha#
dG = Float(((RGB Shr 8 ) And 255) - bG)*Alpha#
dB = Float(((RGB ) And 255) - bB)*Alpha#
RGB=((bR+dR) Shl 16) Or ((bG+dG) Shl 8) Or (bB+dB)
writepixelfast x,y,RGB,backbuffer()
Something like that should get you started..
|