]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10050: [core] chromakey
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 4 Mar 2017 01:01:39 +0000 (19:01 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 4 Mar 2017 01:01:48 +0000 (19:01 -0600)
src/include/switch_core_video.h
src/mod/applications/mod_video_filter/mod_video_filter.c
src/switch_core_video.c

index 908911e92a03e3d9fc7f2ab277853474e2acf3b7..4a5be90cb48d339d183d29c04a818c9a1ffaa4bf 100644 (file)
@@ -223,6 +223,8 @@ SWITCH_DECLARE(int) switch_img_set_rect(switch_image_t  *img,
 */
 SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y);
 
+SWITCH_DECLARE(void) switch_img_attenuate(switch_image_t *img);
+
 /*!\brief patch a small img to a big IMG at position x,y
 *
 * Both IMG and img must be non-NULL
index e7d7250232f3a5b232a7d71a34da12c2d87af266..f7a9995c61b09f591e00a60eaa09d0e4b7631d93 100644 (file)
@@ -253,6 +253,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
        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);
 
+
        switch_assert(img);
        switch_chromakey_process(context->ck, img);
 
index 1924c13b99e2d0b06ae0b03adeabdac11b9a4a07..a9645c58021ccc768c90b25496d5c1a52870403f 100644 (file)
@@ -286,7 +286,9 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
                        gdImageDestroy((gdImagePtr)(*img)->user_priv);
 #endif
                } else {
-                       switch_safe_free((*img)->user_priv);
+                       if ((int)(intptr_t)(*img)->user_priv != 1) {
+                               switch_safe_free((*img)->user_priv);
+                       }
                }
                vpx_img_free((vpx_image_t *)*img);
                *img = NULL;
@@ -338,6 +340,16 @@ static void switch_img_patch_rgb_noalpha(switch_image_t *IMG, switch_image_t *im
        }
 }
 
+SWITCH_DECLARE(void) switch_img_attenuate(switch_image_t *img)
+{
+       if (img->fmt != SWITCH_IMG_FMT_ARGB) {
+               return;
+       }
+
+       ARGBAttenuate(img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], 
+                                 img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], img->d_w, img->d_h);
+}
+
 SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_bool_t noalpha)
 {
        int i;
@@ -358,7 +370,10 @@ SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *i
                int height = MIN(img->d_h, IMG->d_h - abs(y));
                void (*ARGBBlendRow)(const uint8* src_argb, const uint8* src_argb1, uint8* dst_argb, int width) = GetARGBBlend();
 
-               ARGBAttenuate(src_argb0, src_stride_argb0, src_argb0, src_stride_argb0, img->d_w, img->d_h);
+               if (!img->user_priv) {
+                       img->user_priv = (void *)(intptr_t)1;
+                       ARGBAttenuate(src_argb0, src_stride_argb0, src_argb0, src_stride_argb0, img->d_w, img->d_h);
+               }
 
                // Coalesce rows. we have same size images, treat as a single row
                if (src_stride_argb0 == width * 4 &&
@@ -384,7 +399,6 @@ SWITCH_DECLARE(void) switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *i
                        src_argb1 += src_stride_argb1;
                        dst_argb += dst_stride_argb;
                }
-               ARGBUnattenuate(img->planes[SWITCH_PLANE_PACKED], src_stride_argb0, img->planes[SWITCH_PLANE_PACKED], src_stride_argb0, img->d_w, img->d_h);
        }
 }