]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: allow patch to negative x,y
authorSeven Du <dujinfang@gmail.com>
Sun, 19 Apr 2015 00:34:21 +0000 (08:34 +0800)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:22 +0000 (12:47 -0500)
src/switch_core_video.c

index fc50fa883b2b5fa61aa21cecd22dab82c4d73ba6..29b2752e4e26a6062b4b14cac29e0c9321eb859b 100644 (file)
@@ -125,6 +125,7 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
 SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
 {
        int i, len, max_h;
+       int xoff = 0, yoff = 0;
 
        switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420);
 
@@ -152,15 +153,26 @@ SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img,
                return;
        }
 
-       max_h = MIN(y + img->d_h, IMG->d_h);
-       len = MIN(img->d_w, IMG->d_w - x);
+       if (x < 0) {
+               xoff = -x;
+               x = 0;
+       }
+
+       if (y < 0) {
+               yoff = -y;
+               y = 0;
+       }
+
+       max_h = MIN(y + img->d_h - yoff, IMG->d_h);
+       len = MIN(img->d_w - xoff, IMG->d_w - x);
+
 
        if (x & 0x1) { x++; len--; }
        if (y & 0x1) y++;
        if (len <= 0) return;
 
        for (i = y; i < max_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);
+               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 + yoff) + xoff, len);
        }
 
        if ((len & 1) && (x + len) < img->d_w - 1) len++;
@@ -168,8 +180,8 @@ SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img,
        len /= 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);
+               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 + yoff) / 2 + xoff / 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 + yoff) / 2 + xoff / 2, len);
        }
 }