Skip to content

Commit

Permalink
Fix shadow text rendering on alpha buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
progweb committed Jul 31, 2023
1 parent b9f903e commit ab05328
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/libOpenImageIO/imagebufalgo_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
// If the buffer doesn't have an alpha, but the text color passed
// has 4 values, assume the last value is supposed to be alpha.
textalpha = textcolor[3];
}
alpha_channel = 3;
} else
alpha_channel = -1;

// Convert the UTF to 32 bit unicode
std::vector<uint32_t> utext;
Expand Down Expand Up @@ -1009,8 +1011,14 @@ ImageBufAlgo::render_text(ImageBuf& R, int x, int y, string_view text,
float val = t[0];
float alpha = a[0] * textalpha;
R.getpixel(r.x(), r.y(), pixelcolor);
for (int c = 0; c < nchannels; ++c)
pixelcolor[c] = val * textcolor[c] + (1.0f - alpha) * pixelcolor[c];
if (alpha == 0.0)
continue;
for (int c = 0; c < nchannels; ++c) {
if (c == alpha_channel)
pixelcolor[c] = alpha + (1.0f - alpha) * pixelcolor[c];
else
pixelcolor[c] = (val * alpha * textcolor[c]) + (1.0f - alpha) * pixelcolor[c];
}
R.setpixel(r.x(), r.y(), pixelcolor);
}

Expand Down

0 comments on commit ab05328

Please sign in to comment.