FS-7904 #resolve #fixed #comment fixed alpha image patching

This commit is contained in:
Seven Du 2015-07-28 09:17:12 +08:00
parent 6c428c5afd
commit 7191e02f65
1 changed files with 13 additions and 5 deletions

View File

@ -205,16 +205,24 @@ SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img,
int max_h = MIN(img->d_h, IMG->d_h - abs(y)); int max_h = MIN(img->d_h, IMG->d_h - abs(y));
int j; int j;
uint8_t alpha; uint8_t alpha;
switch_rgb_color_t *rgb_color; switch_rgb_color_t *rgb;
for (i = 0; i < max_h; i++) { for (i = 0; i < max_h; i++) {
for (j = 0; j < max_w; j++) { for (j = 0; j < max_w; j++) {
alpha = img->planes[SWITCH_PLANE_PACKED][i * img->stride[SWITCH_PLANE_PACKED] + j * 4]; alpha = img->planes[SWITCH_PLANE_PACKED][i * img->stride[SWITCH_PLANE_PACKED] + j * 4];
// printf("%d, %d alpha: %d\n", j, i, alpha);
if (alpha > 127) { // todo: mux alpha with the underlying pixel ? if (alpha > 0) {
rgb_color = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4); switch_rgb_color_t RGB = { 0 };
switch_img_draw_pixel(IMG, x + j, y + i, rgb_color);
switch_img_get_rgb_pixel(IMG, &RGB, x + j, y + i);
rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4);
RGB.a = 255;
RGB.r = ((RGB.r * (255 - alpha)) >> 8) + ((rgb->r * alpha) >> 8);
RGB.g = ((RGB.g * (255 - alpha)) >> 8) + ((rgb->g * alpha) >> 8);
RGB.b = ((RGB.b * (255 - alpha)) >> 8) + ((rgb->b * alpha) >> 8);
switch_img_draw_pixel(IMG, x + j, y + i, &RGB);
} }
} }
} }