From c956901a375167a1bb8b9167916a98b9a1a0a7b8 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:01:21 +0200 Subject: [PATCH] make combine_blend function blend alpha channels as well --- src/gfx/combine_image.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gfx/combine_image.cpp b/src/gfx/combine_image.cpp index 65edcd49..a1e2ff96 100644 --- a/src/gfx/combine_image.cpp +++ b/src/gfx/combine_image.cpp @@ -91,11 +91,17 @@ COMBINE_FUN(COMBINE_SYMMETRIC_OVERLAY, (Combine::f(a,b) + Combi /// The results are stored in the image A. template void combine_image_do(Image& a, Image b) { - UInt size = a.GetWidth() * a.GetHeight() * 3; + UInt size = a.GetWidth() * a.GetHeight(); Byte *dataA = a.GetData(), *dataB = b.GetData(); // for each pixel: apply function - for (UInt i = 0 ; i < size ; ++i) { + for (UInt i = 0 ; i < (size * 3); ++i) { dataA[i] = Combine::f(dataA[i], dataB[i]); + } + if (a.HasAlpha() && b.HasAlpha()) { + Byte* alphaA = a.GetAlpha(), * alphaB = b.GetAlpha(); + for (UInt i = 0; i < size; ++i) { + alphaA[i] = Combine::f(alphaA[i], alphaB[i]); + } } }