Skip to content

Commit ab05328

Browse files
committed
Fix shadow text rendering on alpha buffer
1 parent b9f903e commit ab05328

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/libOpenImageIO/imagebufalgo_draw.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
930930
// If the buffer doesn't have an alpha, but the text color passed
931931
// has 4 values, assume the last value is supposed to be alpha.
932932
textalpha = textcolor[3];
933-
}
933+
alpha_channel = 3;
934+
} else
935+
alpha_channel = -1;
934936

935937
// Convert the UTF to 32 bit unicode
936938
std::vector<uint32_t> utext;
@@ -1009,8 +1011,14 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
10091011
float val = t[0];
10101012
float alpha = a[0] * textalpha;
10111013
R.getpixel(r.x(), r.y(), pixelcolor);
1012-
for (int c = 0; c < nchannels; ++c)
1013-
pixelcolor[c] = val * textcolor[c] + (1.0f - alpha) * pixelcolor[c];
1014+
if (alpha == 0.0)
1015+
continue;
1016+
for (int c = 0; c < nchannels; ++c) {
1017+
if (c == alpha_channel)
1018+
pixelcolor[c] = alpha + (1.0f - alpha) * pixelcolor[c];
1019+
else
1020+
pixelcolor[c] = (val * alpha * textcolor[c]) + (1.0f - alpha) * pixelcolor[c];
1021+
}
10141022
R.setpixel(r.x(), r.y(), pixelcolor);
10151023
}
10161024

0 commit comments

Comments
 (0)