]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: add overlay func
authorSeven Du <dujinfang@gmail.com>
Fri, 13 Feb 2015 12:08:31 +0000 (20:08 +0800)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:02 +0000 (12:47 -0500)
src/include/switch_core_video.h
src/switch_core_video.c

index 9b31aea2123bb3fed9acc146b292f876378370ed..00a7ee1620fa10daf0e912777c7ba1c6e69409df 100644 (file)
@@ -197,6 +197,13 @@ SWITCH_DECLARE(void) switch_img_patch_hole(switch_image_t *IMG, switch_image_t *
 SWITCH_DECLARE(switch_image_t *) switch_img_read_png(const char* file_name);
 SWITCH_DECLARE(void) switch_img_write_png(switch_image_t *img, char* file_name);
 
+SWITCH_DECLARE(void) switch_img_get_yuv_pixel(switch_image_t *img, switch_yuv_color_t *yuv, int x, int y);
+
+SWITCH_DECLARE(void) switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_color_t *rgb, int x, int y);
+
+SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t alpha);
+
+
 /** @} */
 
 SWITCH_END_EXTERN_C
index 9021336d027677a2b05be61634d76e937a2905cd..c5c0dd232b07c5fd4438c9ae3ef80bc56efa5362 100644 (file)
@@ -215,6 +215,52 @@ SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, i
        }
 }
 
+SWITCH_DECLARE(void) switch_img_get_yuv_pixel(switch_image_t *img, switch_yuv_color_t *yuv, int x, int y)
+{
+       yuv->y = *(img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * y + x);
+       yuv->u = *(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * y / 2 + x / 2);
+       yuv->v = *(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * y / 2 + x / 2);
+}
+
+SWITCH_DECLARE(void) switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_color_t *rgb, int x, int y)
+{
+       switch_yuv_color_t yuv;
+
+       switch_img_get_yuv_pixel(img, &yuv, x, y);
+       switch_color_yuv2rgb(&yuv, rgb);
+}
+
+SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t alpha)
+{
+       int i, j, len, max_h;
+       switch_rgb_color_t RGB, rgb, c;
+       switch_yuv_color_t yuv;
+
+       switch_assert(img->fmt == SWITCH_IMG_FMT_I420);
+       switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420);
+
+       max_h = MIN(y + img->d_h, IMG->d_h);
+       len = MIN(img->d_w, IMG->d_w - x);
+
+       if (x & 1) { x++; len--; }
+       if (y & 1) y++;
+       if (len <= 0) return;
+
+       for (i = y; i < max_h; i++) {
+               for (j = 0; j < len; j++) {
+                       switch_img_get_rgb_pixel(IMG, &RGB, x + j, i);
+                       switch_img_get_rgb_pixel(img, &rgb, j, i - y);
+
+                       c.r = ((RGB.r * alpha) >> 8) + ((rgb.r * (255 - alpha)) >> 8);
+                       c.g = ((RGB.g * alpha) >> 8) + ((rgb.g * (255 - alpha)) >> 8);
+                       c.b = ((RGB.b * alpha) >> 8) + ((rgb.b * (255 - alpha)) >> 8);
+
+                       switch_color_rgb2yuv(&c, &yuv);
+                       switch_img_draw_pixel(IMG, x + j, i, &yuv);
+               }
+       }
+}
+
 static uint8_t scv_art[14][16] = {
        {0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
        {0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},