mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-13 12:40:17 +00:00
FS-7500: refactor switch_img_patch, it was made complicated than it should be
This commit is contained in:
parent
ba9c2f38a7
commit
2842dedc21
@ -72,38 +72,33 @@ 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
|
||||
SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
|
||||
{
|
||||
int i, j, k;
|
||||
int W = IMG->d_w;
|
||||
int H = IMG->d_h;
|
||||
int w = img->d_w;
|
||||
int h = img->d_h;
|
||||
int i, len;
|
||||
|
||||
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++) {
|
||||
for (j = x; j < (x + w) && j < W; j++) {
|
||||
IMG->planes[0][i * IMG->stride[0] + j] = img->planes[0][(i - y) * img->stride[0] + (j - x)];
|
||||
}
|
||||
len = MIN(img->d_w, IMG->d_w - x);
|
||||
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);
|
||||
}
|
||||
|
||||
for (i = y; i < (y + h) && i < H; i+=4) {
|
||||
for (j = x; j < (x + w) && j < W; j+=4) {
|
||||
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)
|
||||
{
|
||||
int i = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user