提交 2842dedc authored 作者: Seven Du's avatar Seven Du 提交者: Michael Jerris

FS-7500: refactor switch_img_patch, it was made complicated than it should be

上级 ba9c2f38
...@@ -72,37 +72,32 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img) ...@@ -72,37 +72,32 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
} }
} }
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
// simple implementation to patch a small img to a big IMG at position x,y // 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) SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
{ {
int i, j, k; int i, len;
int W = IMG->d_w;
int H = IMG->d_h;
int w = img->d_w;
int h = img->d_h;
switch_assert(img->fmt == SWITCH_IMG_FMT_I420); switch_assert(img->fmt == SWITCH_IMG_FMT_I420);
switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420); switch_assert(IMG->fmt == SWITCH_IMG_FMT_I420);
for (i = y; i < (y + h) && i < H; i++) { len = MIN(img->d_w, IMG->d_w - x);
for (j = x; j < (x + w) && j < W; j++) { if (len <= 0) return;
IMG->planes[0][i * IMG->stride[0] + j] = img->planes[0][(i - y) * img->stride[0] + (j - x)];
}
}
for (i = y; i < (y + h) && i < H; i+=4) { for (i = y; i < (y + img->d_h) && i < IMG->d_h; i++) {
for (j = x; j < (x + w) && j < W; j+=4) { 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);
for (k = 1; k <= 2; k++) {
IMG->planes[k][i/2 * IMG->stride[k] + j/2] = img->planes[k][(i-y)/2 * img->stride[k] + (j-x)/2];
IMG->planes[k][i/2 * IMG->stride[k] + j/2 + 1] = img->planes[k][(i-y)/2 * img->stride[k] + (j-x)/2 + 1];
IMG->planes[k][(i+2)/2 * IMG->stride[k] + j/2] = img->planes[k][(i+2-y)/2 * img->stride[k] + (j-x)/2];
IMG->planes[k][(i+2)/2 * IMG->stride[k] + j/2 + 1] = img->planes[k][(i+2-y)/2 * img->stride[k] + (j-x)/2 + 1];
}
}
} }
}
len /= 2;
for (i = y; i < (y + img->d_h) && i < IMG->d_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);
}
}
SWITCH_DECLARE(void) switch_img_copy(switch_image_t *img, switch_image_t **new_img) SWITCH_DECLARE(void) switch_img_copy(switch_image_t *img, switch_image_t **new_img)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论