2009-12-11, 12:15 AM
(This post was last modified: 2009-12-11, 12:24 AM by KajitiSouls.)
Alpha compositing images and getting the colors right has been proving to be a royal PITA for me. I've crunched numbers on paper and I've determined the formulas to be correct, +-1 for each of the values RGBA. Wiki's Alpha Compositing; I'm using the preferred method found in Photoshop and paint.NET.
An example of my problem is readily apparent when dealing with white color with low alpha (FF FF FF 11) on top of a completely transparent black (00 00 00 00) The result should be FF FF FF 11, yet when my code does the job, it turns out to be 11 11 11 11 instead, which is black with low alpha. Everything else generally turns out okay.
Below is the code tasked to merging images on top of each other. The stuff of most interest is at the end, where all the formula goodness is, with all the lines starting with newImage[index] = byte;.
And as a friendly reminder, Java doesn't support unsigned primitives. R3tarded, I know.
This is actually part of a much larger program, so the error(s) could be from somewhere else. But I figure the method is a good place to start and perhaps the most easily verifiable for errors. Especially since I can't imagine the input to be incorrect, and it'd be pretty dam hard to verify. Case in point, the program I'm working on outputs animated components separately, then combines animations for a final result and outputs that as well. The component-only animations turn out perfect, but the composite animation is botched.
Additional comments are appreciated xD
An example of my problem is readily apparent when dealing with white color with low alpha (FF FF FF 11) on top of a completely transparent black (00 00 00 00) The result should be FF FF FF 11, yet when my code does the job, it turns out to be 11 11 11 11 instead, which is black with low alpha. Everything else generally turns out okay.
Below is the code tasked to merging images on top of each other. The stuff of most interest is at the end, where all the formula goodness is, with all the lines starting with newImage[index] = byte;.
And as a friendly reminder, Java doesn't support unsigned primitives. R3tarded, I know.
mergeImage() method
This is actually part of a much larger program, so the error(s) could be from somewhere else. But I figure the method is a good place to start and perhaps the most easily verifiable for errors. Especially since I can't imagine the input to be incorrect, and it'd be pretty dam hard to verify. Case in point, the program I'm working on outputs animated components separately, then combines animations for a final result and outputs that as well. The component-only animations turn out perfect, but the composite animation is botched.
Additional comments are appreciated xD


