From e26e873268e023ed58e6b3a176d7a9c945bc7a50 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 31 Mar 2017 20:21:40 -0500 Subject: [PATCH] FS-10205: [freeswitch-core,mod_conference,mod_video_filter] Add 8 bit filter #resolve --- src/include/switch_core_video.h | 4 +- .../mod_conference/conference_video.c | 9 +++ .../mod_video_filter/mod_video_filter.c | 11 ++++ src/switch_core_video.c | 57 +++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index 6fb06f5ab3..6d96b3b472 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -50,7 +50,8 @@ typedef enum { SCV_FILTER_GRAY_FG = (1 << 0), SCV_FILTER_GRAY_BG = (1 << 1), SCV_FILTER_SEPIA_FG = (1 << 2), - SCV_FILTER_SEPIA_BG = (1 << 3) + SCV_FILTER_SEPIA_BG = (1 << 3), + SCV_FILTER_8BIT_FG = (1 << 4) } switch_core_video_filter_t; @@ -322,6 +323,7 @@ SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, uint3 * \param[in] color RGB color */ 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_8bit(switch_image_t *img); SWITCH_DECLARE(void) switch_img_gray(switch_image_t *img, int x, int y, int w, int h); SWITCH_DECLARE(void) switch_img_sepia(switch_image_t *img, int x, int y, int w, int h); diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index f7b55588df..1d4238c614 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -2586,6 +2586,15 @@ void conference_video_pop_next_image(conference_member_t *member, switch_image_t if (member->video_filters & SCV_FILTER_SEPIA_FG) { switch_img_sepia(img, 0, 0, img->d_w, img->d_h); } + + if (member->video_filters & SCV_FILTER_8BIT_FG) { + switch_image_t *tmp = NULL; + int w = img->d_w, h = img->d_h; + + switch_img_scale(img, &tmp, w/8 ,h/8); + switch_img_scale(tmp, &img, w,h); + switch_img_8bit(img); + } } *imgP = img; diff --git a/src/mod/applications/mod_video_filter/mod_video_filter.c b/src/mod/applications/mod_video_filter/mod_video_filter.c index de220d58cc..0208094d92 100644 --- a/src/mod/applications/mod_video_filter/mod_video_filter.c +++ b/src/mod/applications/mod_video_filter/mod_video_filter.c @@ -318,6 +318,16 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi patch_data = context->data; + if (context->video_filters & SCV_FILTER_8BIT_FG) { + switch_image_t *tmp = NULL; + int w = frame->img->d_w, h = frame->img->d_h; + + switch_img_scale(frame->img, &tmp, w/8 ,h/8); + switch_img_scale(tmp, &frame->img, w,h); + switch_img_8bit(frame->img); + } + + switch_img_to_raw(frame->img, context->data, frame->img->d_w * 4, SWITCH_IMG_FMT_ARGB); img = switch_img_wrap(NULL, SWITCH_IMG_FMT_ARGB, frame->img->d_w, frame->img->d_h, 1, context->data); @@ -333,6 +343,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi switch_img_sepia(img, 0, 0, img->d_w, img->d_h); } + if (context->bgimg) { switch_image_t *tmp = NULL; diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 6a3fe05f69..f5a6695811 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -1419,6 +1419,59 @@ SWITCH_DECLARE(void) switch_img_fill_noalpha(switch_image_t *img, int x, int y, #endif } +SWITCH_DECLARE(void) switch_img_8bit(switch_image_t *img) +{ +#ifdef SWITCH_HAVE_YUV + int i; + + if (img->fmt == SWITCH_IMG_FMT_ARGB) { + int max_w = img->d_w; + int max_h = img->d_h; + int j; + switch_rgb_color_t *rgb; + uint32_t *bytes; + + for (i = 0; i < max_h; i++) { + for (j = 0; j < max_w; j++) { + rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4); + //if (rgb); + + + if (!rgb->a) continue;; + + //rgb->r = rgb->r & 0xE0, rgb->g = rgb->g & 0xE0, rgb->b = rgb->b & 0xC0; + bytes = (uint32_t *) rgb; + +#if SWITCH_BYTE_ORDER == __BIG_ENDIAN + *bytes = *bytes & 0xE0E0C0FF; +#else + *bytes = *bytes & 0xFFC0E0E0; +#endif + + } + } + } else if (img->fmt == SWITCH_IMG_FMT_I420) { + switch_image_t *tmp_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, img->d_w, img->d_h, 1); + + I420ToARGB(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y], + img->planes[SWITCH_PLANE_U], img->stride[SWITCH_PLANE_U], + img->planes[SWITCH_PLANE_V], img->stride[SWITCH_PLANE_V], + tmp_img->planes[SWITCH_PLANE_PACKED], tmp_img->stride[SWITCH_PLANE_PACKED], + img->d_w, img->d_h); + + switch_img_8bit(tmp_img); + + ARGBToI420(tmp_img->planes[SWITCH_PLANE_PACKED], tmp_img->stride[SWITCH_PLANE_PACKED], + img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y], + img->planes[SWITCH_PLANE_U], img->stride[SWITCH_PLANE_U], + img->planes[SWITCH_PLANE_V], img->stride[SWITCH_PLANE_V], + tmp_img->d_w, tmp_img->d_h); + + switch_img_free(&tmp_img); + } +#endif +} + SWITCH_DECLARE(void) switch_img_sepia(switch_image_t *img, int x, int y, int w, int h) { #ifdef SWITCH_HAVE_YUV @@ -3331,6 +3384,10 @@ SWITCH_DECLARE(void) switch_core_video_parse_filter_string(switch_core_video_fil if (switch_stristr("bg-sepia", filter_str)) { *filters |= SCV_FILTER_SEPIA_BG; } + + if (switch_stristr("fg-8bit", filter_str)) { + *filters |= SCV_FILTER_8BIT_FG; + } }