From 84a1f5f642d216670c22111f8b86c78ac4f20888 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 13 Feb 2015 20:08:31 +0800 Subject: [PATCH] FS-7500: add overlay func --- src/include/switch_core_video.h | 7 +++++ src/switch_core_video.c | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index 9b31aea212..00a7ee1620 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -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 diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 9021336d02..c5c0dd232b 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -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},