I don't want to use Canvases.
So I coded my own function transparentPaste which uses getPixel and setPixel to combine the two:
Simplified, this is what it does for every pixel that overlaps:
Code: Select all
rDest,gDest,bDest,aDest = imgDataDest:getPixel(x,y)
rSource,gSource,bSource,aSource = imgDataSource:getPixel(x-posX,y-posY)
if aSource > 0 then
rSource,gSource,bSource,aSource = rSource/255,gSource/255,bSource/255,aSource/255
rDest,gDest,bDest,aDest = rDest/255,gDest/255,bDest/255,aDest/255
a = aSource + aDest*(1-aSource)
if a > 0 then
r = (rSource*aSource+rDest*aDest*(1-aSource))/a
g = (gSource*aSource+gDest*aDest*(1-aSource))/a
b = (bSource*aSource+bDest*aDest*(1-aSource))/a
else
r,g,b = 0,0,0
end
r,g,b,a = r*255,g*255,b*255,a*255
imgDataDest:setPixel(x, y, r, g, b, a)
end
Any ideas for a better method without canvases?
Why are programs like the GIMP so fast when doing pretty much exactly the same thing (for example when merging two layers)...