mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 14:56:36 +00:00
assrender: optimize blending
Skip empty source pixels when blending an image. There can be hundreds of images to blend at each frame, so this brings a nice performance boost. https://bugzilla.gnome.org/show_bug.cgi?id=753821
This commit is contained in:
parent
ecdc7bb37d
commit
3b1e095169
1 changed files with 20 additions and 14 deletions
|
@ -724,34 +724,40 @@ blit_bgra_premultiplied (GstAssRender * render, ASS_Image * ass_image,
|
||||||
dst_x = ass_image->dst_x + x_off;
|
dst_x = ass_image->dst_x + x_off;
|
||||||
dst_y = ass_image->dst_y + y_off;
|
dst_y = ass_image->dst_y + y_off;
|
||||||
|
|
||||||
if (dst_y >= height || dst_x >= width)
|
w = MIN (ass_image->w, width - dst_x);
|
||||||
|
h = MIN (ass_image->h, height - dst_y);
|
||||||
|
if (w <= 0 || h <= 0)
|
||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
alpha = 255 - (ass_image->color & 0xff);
|
alpha = 255 - (ass_image->color & 0xff);
|
||||||
|
if (!alpha)
|
||||||
|
goto next;
|
||||||
|
|
||||||
r = ((ass_image->color) >> 24) & 0xff;
|
r = ((ass_image->color) >> 24) & 0xff;
|
||||||
g = ((ass_image->color) >> 16) & 0xff;
|
g = ((ass_image->color) >> 16) & 0xff;
|
||||||
b = ((ass_image->color) >> 8) & 0xff;
|
b = ((ass_image->color) >> 8) & 0xff;
|
||||||
|
|
||||||
src = ass_image->bitmap;
|
src = ass_image->bitmap;
|
||||||
dst = data + dst_y * stride + dst_x * 4;
|
dst = data + dst_y * stride + dst_x * 4;
|
||||||
|
|
||||||
w = MIN (ass_image->w, width - dst_x);
|
|
||||||
h = MIN (ass_image->h, height - dst_y);
|
|
||||||
src_skip = ass_image->stride - w;
|
src_skip = ass_image->stride - w;
|
||||||
dst_skip = stride - w * 4;
|
dst_skip = stride - w * 4;
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
k = src[0] * alpha / 255;
|
if (src[0]) {
|
||||||
if (dst[3] == 0) {
|
k = src[0] * alpha / 255;
|
||||||
dst[3] = k;
|
if (dst[3] == 0) {
|
||||||
dst[2] = (k * r) / 255;
|
dst[3] = k;
|
||||||
dst[1] = (k * g) / 255;
|
dst[2] = (k * r) / 255;
|
||||||
dst[0] = (k * b) / 255;
|
dst[1] = (k * g) / 255;
|
||||||
} else {
|
dst[0] = (k * b) / 255;
|
||||||
dst[3] = k + (255 - k) * dst[3] / 255;
|
} else {
|
||||||
dst[2] = (k * r + (255 - k) * dst[2]) / 255;
|
dst[3] = k + (255 - k) * dst[3] / 255;
|
||||||
dst[1] = (k * g + (255 - k) * dst[1]) / 255;
|
dst[2] = (k * r + (255 - k) * dst[2]) / 255;
|
||||||
dst[0] = (k * b + (255 - k) * dst[0]) / 255;
|
dst[1] = (k * g + (255 - k) * dst[1]) / 255;
|
||||||
|
dst[0] = (k * b + (255 - k) * dst[0]) / 255;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src++;
|
src++;
|
||||||
dst += 4;
|
dst += 4;
|
||||||
|
|
Loading…
Reference in a new issue