FS-7513: fix math on image resizing

This commit is contained in:
Anthony Minessale 2015-02-06 18:00:35 -06:00 committed by Michael Jerris
parent 1aa66ef30a
commit 1deca68e37
1 changed files with 10 additions and 10 deletions

View File

@ -928,7 +928,7 @@ static void set_bgcolor(bgcolor_yuv_t *bgcolor, char *bgcolor_str)
bgcolor->v = v;
}
#define SCALE_FACTOR 360
#define SCALE_FACTOR 360.0f
static void reset_layer(mcu_canvas_t *canvas, mcu_layer_t *layer)
{
@ -938,8 +938,8 @@ static void reset_layer(mcu_canvas_t *canvas, mcu_layer_t *layer)
layer->tagged = 0;
screen_w = canvas->img->d_w * layer->geometry.scale / SCALE_FACTOR;
screen_h = canvas->img->d_h * layer->geometry.scale / SCALE_FACTOR;
screen_w = ceil(canvas->img->d_w * layer->geometry.scale / SCALE_FACTOR);
screen_h = ceil(canvas->img->d_h * layer->geometry.scale / SCALE_FACTOR);
x = canvas->img->d_w * layer->geometry.x / SCALE_FACTOR;
y = canvas->img->d_h * layer->geometry.y / SCALE_FACTOR;
@ -951,7 +951,7 @@ static void reset_layer(mcu_canvas_t *canvas, mcu_layer_t *layer)
if (!layer->img) {
layer->img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, screen_w, screen_h, 1);
}
switch_assert(layer->img);
reset_image(layer->img, &canvas->bgcolor);
@ -971,8 +971,8 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer)
int screen_w = 0, screen_h = 0, img_w = 0, img_h = 0;
double screen_aspect = 0, img_aspect = 0;
img_w = screen_w = IMG->d_w * layer->geometry.scale / SCALE_FACTOR;
img_h = screen_h = IMG->d_h * layer->geometry.scale / SCALE_FACTOR;
img_w = screen_w = ceil(IMG->d_w * layer->geometry.scale / SCALE_FACTOR);
img_h = screen_h = ceil(IMG->d_h * layer->geometry.scale / SCALE_FACTOR);
x = IMG->d_w * layer->geometry.x / SCALE_FACTOR;
y = IMG->d_h * layer->geometry.y / SCALE_FACTOR;
@ -981,10 +981,10 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer)
img_aspect = (double) img->d_w / img->d_h;
if (screen_aspect > img_aspect) {
img_w = img_aspect * screen_h;
img_w = ceil(img_aspect * screen_h);
x += (screen_w - img_w) / 2;
} else if (screen_aspect < img_aspect) {
img_h = screen_w / img_aspect;
img_h = ceil(screen_w / img_aspect);
y += (screen_h - img_h) / 2;
}
@ -1010,8 +1010,8 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer)
switch_assert(layer->img);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "RESIZE %dx%d to %dx%d to fit in %dx%d and insert at %d,%d\n",
img->d_w, img->d_h, img_w, img_h, screen_w, screen_h, x, y);
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RESIZE %dx%d to %dx%d to fit in %dx%d and insert at %d,%d\n",
// img->d_w, img->d_h, img_w, img_h, screen_w, screen_h, x, y);
ret = I420Scale(img->planes[0], img->stride[0],
img->planes[1], img->stride[1],