DescriptionThe function wants to divide by 256 instead of 255 for obvious reasons. It finds a scale multiplier to make the colors in the range [0,256], however it scales the alpha first when finding the multiplier which makes it incorrect.
What this means is that if you have a pixel P with alpha=255, and you blit a color C over it with alpha=127, the resulting alpha is:
255*(256-128)/256+127
= 255*128/256+127
= 254
Wrong!
If we scale the destination values up to be in the range 256 we get
256*(256-128)/256+127
= 256*128/256+127
= 255
Right!
Also, this gives correct values for combinations of P alpha=0, C alpha=0, and P alpha=255, C alpha=255 and C alpha=127 (ie. 0.5). Test is included to verify this.
P=0 C=0
1*(256-1)/256+0 = 0
P=255 C=0
256*(256-1)/256+0 = 255
P=0 C=255
1*(256-256)/256+255 = 255
P=255 C=255
256*(256-256)/256+255 = 255
BUG=420
TEST=BlitRectTest.cpp
Patch Set 1 #Patch Set 2 : Get correct 0 and 255 values without extra addition (don't scale alpha twice). #Patch Set 3 : 80 columns #
Total comments: 3
Patch Set 4 : Catch 16-bit 565 blits and 32-bit non-SSE blits. #Patch Set 5 : 80 columns #
Total comments: 17
Patch Set 6 : Cover a few more functions with antialiasing. #Patch Set 7 : more complete #Patch Set 8 : addressed feedback, strengthened test #
Total comments: 2
MessagesTotal messages: 24
|