Last active
December 10, 2015 21:38
-
-
Save zero-is-one/4496027 to your computer and use it in GitHub Desktop.
Merging two images as if they are overlayed.....
Taken from: http://forum.openframeworks.cc/index.php?topic=4431.0
Some small bugs in the original code have been fixed. This assumes both images are the same size and each pixel has RGBA values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a and b are both RGBA images | |
int totalPixels = a.width * a.height; | |
unsigned char * aPixels = a.getPixels(); | |
unsigned char * bPixels = b.getPixels(); | |
for(int i=0; i<totalPixels; i++) { | |
int base = i*4; | |
// deal with r,g,b | |
float bAlpha = float(bPixels[base+3])/256.0f; | |
for (int j=0; j<3; j++ ) | |
aPixels[base+j] = (aPixels[base+j]*(1.0f-bAlpha) + bPixels[base+j]*bAlpha); | |
// full alpha (no transparency) | |
aPixels[base+3] = 255; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment