Skip to content

Commit

Permalink
Core (LV::Video): Add explanatory note on calculation in blit_overlay…
Browse files Browse the repository at this point in the history
…_alphasrc() per Sebastian (hartwork)'s suggestion.
  • Loading branch information
kaixiong committed Dec 26, 2024
1 parent 8cbfb5c commit 0e95069
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libvisual/libvisual/private/lv_video_blit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace LV {
for (int x = 0; x < src->m_impl->width; x++) {
uint8_t const src_alpha = src_pixel[3];

// NOTE: This is effectively
// "(src_alpha / 255) * src_pixel[i] + (1 - src_alpha / 255) * dst_pixel[i]"
// but with only a single multiplication, a single division by 256 rather than 255, for speed.
dst_pixel[0] = (src_alpha * (src_pixel[0] - dst_pixel[0]) >> 8) + dst_pixel[0];
dst_pixel[1] = (src_alpha * (src_pixel[1] - dst_pixel[1]) >> 8) + dst_pixel[1];
dst_pixel[2] = (src_alpha * (src_pixel[2] - dst_pixel[2]) >> 8) + dst_pixel[2];
Expand Down

0 comments on commit 0e95069

Please sign in to comment.