From 8d4e72af166dc8b3f5f6fa5e7a61f7553e59a2d9 Mon Sep 17 00:00:00 2001 From: Mike Jerris Date: Thu, 16 Mar 2017 11:09:29 -0500 Subject: [PATCH] FS-10140: [core] add switch_img_grey, makes i420 switch_img_t image grey scale --- src/include/switch_core_video.h | 2 ++ src/switch_core_video.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index 17cf44f27e..b93bf20844 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -315,6 +315,8 @@ SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, uint3 */ SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color); +SWITCH_DECLARE(void) switch_img_grey(switch_image_t *img, int x, int y, int w, int h); + SWITCH_DECLARE(void) switch_img_fill_noalpha(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color); /*!\brief Set RGB color with a string diff --git a/src/switch_core_video.c b/src/switch_core_video.c index a395825dce..445382ca95 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -1410,6 +1410,33 @@ SWITCH_DECLARE(void) switch_img_fill_noalpha(switch_image_t *img, int x, int y, #endif } +SWITCH_DECLARE(void) switch_img_grey(switch_image_t *img, int x, int y, int w, int h) +{ +#ifdef SWITCH_HAVE_YUV + int len, i, max_h; + + if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return; + + if (img->fmt == SWITCH_IMG_FMT_I420) { + max_h = MIN(y + h, img->d_h); + len = MIN(w, img->d_w - x); + + if (x & 1) { x++; len--; } + if (y & 1) y++; + if (len <= 0) return; + + if ((len & 1) && (x + len) < img->d_w - 1) len++; + + len /= 2; + + for (i = y; i < max_h; i += 2) { + memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, 0, len); + memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, 0, len); + } + } +#endif +} + SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color) { #ifdef SWITCH_HAVE_YUV