Skip to content

Commit f28a9a5

Browse files
committed
Fix shadow text rendering on alpha buffer
1 parent 6e60347 commit f28a9a5

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
@@ -1078,7 +1078,9 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
10781078
// If the buffer doesn't have an alpha, but the text color passed
10791079
// has 4 values, assume the last value is supposed to be alpha.
10801080
textalpha = textcolor[3];
1081-
}
1081+
alpha_channel = 3;
1082+
} else
1083+
alpha_channel = -1;
10821084

10831085
// Convert the UTF to 32 bit unicode
10841086
std::vector<uint32_t> utext;
@@ -1162,8 +1164,14 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
11621164
float val = t[0];
11631165
float alpha = a[0] * textalpha;
11641166
R.getpixel(r.x(), r.y(), pixelcolor);
1165-
for (int c = 0; c < nchannels; ++c)
1166-
pixelcolor[c] = val * textcolor[c] + (1.0f - alpha) * pixelcolor[c];
1167+
if (alpha == 0.0)
1168+
continue;
1169+
for (int c = 0; c < nchannels; ++c) {
1170+
if (c == alpha_channel)
1171+
pixelcolor[c] = alpha + (1.0f - alpha) * pixelcolor[c];
1172+
else
1173+
pixelcolor[c] = (val * alpha * textcolor[c]) + (1.0f - alpha) * pixelcolor[c];
1174+
}
11671175
R.setpixel(r.x(), r.y(), pixelcolor);
11681176
}
11691177

0 commit comments

Comments
 (0)