]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10205: [freeswitch-core,mod_conference,mod_video_filter] Add 8 bit filter #resolve
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 1 Apr 2017 01:21:40 +0000 (20:21 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 1 Apr 2017 01:21:45 +0000 (20:21 -0500)
src/include/switch_core_video.h
src/mod/applications/mod_conference/conference_video.c
src/mod/applications/mod_video_filter/mod_video_filter.c
src/switch_core_video.c

index 6fb06f5ab3571dd4c99e89bca9aeaadcbdbf04e7..6d96b3b4724244f344f0d1113e2b21e5e9f80d71 100644 (file)
@@ -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);
index f7b55588df13c05adc79552231aeb74ed22effe7..1d4238c61433bd402430a308fe699286250d8a58 100644 (file)
@@ -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;
index de220d58ccaf699e2507a3aa81df3a0db9a731d2..0208094d9269c2f33facc88860b525f89150e0d6 100644 (file)
@@ -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;
 
index 6a3fe05f692023e4352cf5988b292cfdd11d45b2..f5a6695811ce3e8f3c33de54cb703c14b476b5d5 100644 (file)
@@ -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;
+       }
 }