From 061bcb063a9858093ac9c3f63208e32ee4931f9b Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 13 Feb 2015 10:37:35 +0800 Subject: [PATCH] FS-7500: fix patch and fill on an odd position --- src/switch_core_video.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 2651b6ee75..80132b6950 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -81,21 +81,27 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img) // simple implementation to patch a small img to a big IMG at position x,y SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y) { - int i, len; + int i, len, max_h; switch_assert(img->fmt == SWITCH_IMG_FMT_I420); switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420); + max_h = MIN(y + img->d_h, IMG->d_h); len = MIN(img->d_w, IMG->d_w - x); + + if (x & 0x1) { x++; len--; } + if (y & 0x1) y++; if (len <= 0) return; for (i = y; i < (y + img->d_h) && i < IMG->d_h; i++) { memcpy(IMG->planes[SWITCH_PLANE_Y] + IMG->stride[SWITCH_PLANE_Y] * i + x, img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * (i - y), len); } + if ((len & 1) && (x + len) < img->d_w) len++; + len /= 2; - for (i = y; i < (y + img->d_h) && i < IMG->d_h; i += 2) { + for (i = y; i < max_h; i += 2) { memcpy(IMG->planes[SWITCH_PLANE_U] + IMG->stride[SWITCH_PLANE_U] * i / 2 + x / 2, img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i - y) / 2, len); memcpy(IMG->planes[SWITCH_PLANE_V] + IMG->stride[SWITCH_PLANE_V] * i / 2 + x / 2, img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i - y) / 2, len); } @@ -177,23 +183,29 @@ SWITCH_DECLARE(void) switch_img_draw_pixel(switch_image_t *img, int x, int y, sw SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color) { - int len, i; + int len, i, max_h; switch_yuv_color_t yuv_color; if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return; switch_color_rgb2yuv(color, &yuv_color); + 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; for (i = y; i < (y + h) && i < img->d_h; i++) { memset(img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * i + x, yuv_color.y, len); } + if ((len & 1) && (x + len) < img->d_w) len++; + len /= 2; - for (i = y; i < (y + h) && i < img->d_h; i += 2) { + for (i = y; i < max_h; i += 2) { memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * i / 2 + x / 2, yuv_color.u, len); memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * i / 2 + x / 2, yuv_color.v, len); }