Merge pull request #14 from G-e-n-e-v-e-n-s-i-S/combine-blend-alpha

make combine_blend function blend alpha channels as well
This commit is contained in:
GenevensiS
2024-09-17 10:09:22 +02:00
committed by GitHub
+8 -2
View File
@@ -295,11 +295,17 @@ COMBINE_FUN(COMBINE_SMALLER_THAN_250, a < 250 ? b : a)
/// The results are stored in the image A. /// The results are stored in the image A.
template <ImageCombine combine> template <ImageCombine combine>
void combine_image_do(Image& a, Image b) { 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(); Byte *dataA = a.GetData(), *dataB = b.GetData();
// for each pixel: apply function // for each pixel: apply function
for (UInt i = 0 ; i < size ; ++i) { for (UInt i = 0 ; i < (size * 3); ++i) {
dataA[i] = Combine<combine>::f(dataA[i], dataB[i]); dataA[i] = Combine<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<combine>::f(alphaA[i], alphaB[i]);
}
} }
} }