]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10140: [core] add switch_img_grey, makes i420 switch_img_t image grey scale
authorMike Jerris <mike@jerris.com>
Thu, 16 Mar 2017 16:09:29 +0000 (11:09 -0500)
committerMike Jerris <mike@jerris.com>
Thu, 16 Mar 2017 16:09:29 +0000 (11:09 -0500)
src/include/switch_core_video.h
src/switch_core_video.c

index 17cf44f27e03f0ed5541829702308e2f08bc5eb7..b93bf20844650f5251159bd191862a1e3fc22166 100644 (file)
@@ -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
index a395825dcea23ea602f3151e3477363f08e45559..445382ca959d1c1072f6deba02702b4f834c6daa 100644 (file)
@@ -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