diff options
| author | Ray <[email protected]> | 2018-04-03 12:42:22 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2018-04-03 12:42:22 +0200 |
| commit | 533780aadf1ba1b553ef69f191171f6a528ae894 (patch) | |
| tree | 5d0ad6d75657461122d825c3f1cebaa3a0b0bbe2 /src/textures.c | |
| parent | 0c0ff2802ea1bc260b563bb9ed871d324389757d (diff) | |
| download | raylib-533780aadf1ba1b553ef69f191171f6a528ae894.tar.gz raylib-533780aadf1ba1b553ef69f191171f6a528ae894.zip | |
Review ImageDraw() alpha blending
Not sure if math is ok... just left a commented piece of code that uses pre-multiplied alpha.
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/textures.c b/src/textures.c index 54055ce0..8e68df7e 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1337,11 +1337,30 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec) // Alpha blending implementation dstCol = dstPixels[j*dst->width + i]; srcCol = srcPixels[(j - dstRec.y)*dstRec.width + (i - dstRec.x)]; + + /* + // Pre-multiply alpha + Vector3 dstColf = { (float)dstCol.r/255.0f, (float)dstCol.g/255.0f, (float)dstCol.b/255.0f }; + dstColf = Vector3Multiply(dstColf, (float)dstCol.a/255.0f); + Vector3 srcColf = { (float)srcCol.r/255.0f, (float)srcCol.g/255.0f, (float)srcCol.b/255.0f }; + srcColf = Vector3Multiply(srcColf, (float)srcCol.a/255.0f); + + dstColf = Vector3Add(dstColf, srcColf); + + if (dstColf.x > 1.0f) dstColf.x = 1.0f; + if (dstColf.y > 1.0f) dstColf.y = 1.0f; + if (dstColf.z > 1.0f) dstColf.z = 1.0f; + + dstCol.r = (unsigned char)(dstColf.x*255.0f); + dstCol.g = (unsigned char)(dstColf.y*255.0f); + dstCol.b = (unsigned char)(dstColf.z*255.0f); + dstCol.a = srcCol.a; + */ dstCol.r = ((srcCol.a*(srcCol.r - dstCol.r)) >> 8) + dstCol.r; dstCol.g = ((srcCol.a*(srcCol.g - dstCol.g)) >> 8) + dstCol.g; dstCol.b = ((srcCol.a*(srcCol.b - dstCol.b)) >> 8) + dstCol.b; - dstCol.a = ((srcCol.a*(srcCol.a - dstCol.a)) >> 8) + dstCol.a; + dstCol.a = srcCol.a; dstPixels[j*dst->width + i] = dstCol; |
