Skip to content

Commit

Permalink
Fixed incorrect value for fully transparent pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed Feb 21, 2022
1 parent fab2c93 commit fbc7233
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/SFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,19 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co
const Uint8* src = srcPixels + j * 4;
Uint8* dst = dstPixels + j * 4;

// Interpolate RGBA components using the alpha value of the source pixel
Uint8 alpha = src[3];
dst[0] = static_cast<Uint8>((src[0] * alpha + dst[0] * (255 - alpha)) / 255);
dst[1] = static_cast<Uint8>((src[1] * alpha + dst[1] * (255 - alpha)) / 255);
dst[2] = static_cast<Uint8>((src[2] * alpha + dst[2] * (255 - alpha)) / 255);
dst[3] = static_cast<Uint8>(alpha + dst[3] * (255 - alpha) / 255);
// Interpolate RGBA components using the alpha values of the destination and source pixels
Uint8 src_alpha = src[3];
Uint8 dst_alpha = dst[3];
Uint8 out_alpha = static_cast<Uint8>(src_alpha + dst_alpha - src_alpha * dst_alpha / 255);

dst[3] = out_alpha;

if (out_alpha)
for (int k = 0; k < 3; k++)
dst[k] = static_cast<Uint8>((src[k] * src_alpha + dst[k] * (out_alpha - src_alpha)) / out_alpha);
else
for (int k = 0; k < 3; k++)
dst[k] = src[k];
}

srcPixels += srcStride;
Expand Down

0 comments on commit fbc7233

Please sign in to comment.