Merge "Using single struct to represent scale factors."

This commit is contained in:
Dmitry Kovalev 2013-12-20 11:22:02 -08:00 committed by Gerrit Code Review
commit b3b9f4a4d0
12 changed files with 135 additions and 200 deletions

View File

@ -215,7 +215,7 @@ struct macroblockd_plane {
typedef struct macroblockd { typedef struct macroblockd {
struct macroblockd_plane plane[MAX_MB_PLANE]; struct macroblockd_plane plane[MAX_MB_PLANE];
struct scale_factors scale_factor[2]; const struct scale_factors *scale_factors[2];
MODE_INFO *last_mi; MODE_INFO *last_mi;
int mode_info_stride; int mode_info_stride;

View File

@ -123,7 +123,6 @@ typedef struct VP9Common {
// Each frame can reference REFS_PER_FRAME buffers // Each frame can reference REFS_PER_FRAME buffers
int active_ref_idx[REFS_PER_FRAME]; int active_ref_idx[REFS_PER_FRAME];
struct scale_factors active_ref_scale[REFS_PER_FRAME]; struct scale_factors active_ref_scale[REFS_PER_FRAME];
struct scale_factors_common active_ref_scale_comm[REFS_PER_FRAME];
int new_fb_idx; int new_fb_idx;
YV12_BUFFER_CONFIG post_proc_buffer; YV12_BUFFER_CONFIG post_proc_buffer;

View File

@ -66,11 +66,11 @@ static void inter_predictor(const uint8_t *src, int src_stride,
uint8_t *dst, int dst_stride, uint8_t *dst, int dst_stride,
const int subpel_x, const int subpel_x,
const int subpel_y, const int subpel_y,
const struct scale_factors *scale, const struct scale_factors *sf,
int w, int h, int ref, int w, int h, int ref,
const struct subpix_fn_table *subpix, const struct subpix_fn_table *subpix,
int xs, int ys) { int xs, int ys) {
scale->sfc->predict[subpel_x != 0][subpel_y != 0][ref]( sf->predict[subpel_x != 0][subpel_y != 0][ref](
src, src_stride, dst, dst_stride, src, src_stride, dst, dst_stride,
subpix->filter_x[subpel_x], xs, subpix->filter_x[subpel_x], xs,
subpix->filter_y[subpel_y], ys, subpix->filter_y[subpel_y], ys,
@ -80,7 +80,7 @@ static void inter_predictor(const uint8_t *src, int src_stride,
void vp9_build_inter_predictor(const uint8_t *src, int src_stride, void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
uint8_t *dst, int dst_stride, uint8_t *dst, int dst_stride,
const MV *src_mv, const MV *src_mv,
struct scale_factors *scale, const struct scale_factors *sf,
int w, int h, int ref, int w, int h, int ref,
const struct subpix_fn_table *subpix, const struct subpix_fn_table *subpix,
enum mv_precision precision, enum mv_precision precision,
@ -88,19 +88,14 @@ void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
const int is_q4 = precision == MV_PRECISION_Q4; const int is_q4 = precision == MV_PRECISION_Q4;
const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2, const MV mv_q4 = { is_q4 ? src_mv->row : src_mv->row * 2,
is_q4 ? src_mv->col : src_mv->col * 2 }; is_q4 ? src_mv->col : src_mv->col * 2 };
const struct scale_factors_common *sfc = scale->sfc; MV32 mv = vp9_scale_mv(&mv_q4, x, y, sf);
int subpel_x, subpel_y; const int subpel_x = mv.col & SUBPEL_MASK;
MV32 mv; const int subpel_y = mv.row & SUBPEL_MASK;
sfc->set_scaled_offsets(scale, y, x);
mv = sfc->scale_mv(&mv_q4, scale);
subpel_x = mv.col & SUBPEL_MASK;
subpel_y = mv.row & SUBPEL_MASK;
src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS); src += (mv.row >> SUBPEL_BITS) * src_stride + (mv.col >> SUBPEL_BITS);
inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y, inter_predictor(src, src_stride, dst, dst_stride, subpel_x, subpel_y,
scale, w, h, ref, subpix, sfc->x_step_q4, sfc->y_step_q4); sf, w, h, ref, subpix, sf->x_step_q4, sf->y_step_q4);
} }
static INLINE int round_mv_comp_q4(int value) { static INLINE int round_mv_comp_q4(int value) {
@ -158,7 +153,7 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
int ref; int ref;
for (ref = 0; ref < 1 + is_compound; ++ref) { for (ref = 0; ref < 1 + is_compound; ++ref) {
struct scale_factors *const scale = &xd->scale_factor[ref]; const struct scale_factors *const sf = xd->scale_factors[ref];
struct buf_2d *const pre_buf = &pd->pre[ref]; struct buf_2d *const pre_buf = &pd->pre[ref];
struct buf_2d *const dst_buf = &pd->dst; struct buf_2d *const dst_buf = &pd->dst;
uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
@ -185,12 +180,11 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
MV32 scaled_mv; MV32 scaled_mv;
int xs, ys, subpel_x, subpel_y; int xs, ys, subpel_x, subpel_y;
if (vp9_is_scaled(scale->sfc)) { if (vp9_is_scaled(sf)) {
pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, scale); pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
scale->sfc->set_scaled_offsets(scale, mi_y + y, mi_x + x); scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
scaled_mv = scale->sfc->scale_mv(&mv_q4, scale); xs = sf->x_step_q4;
xs = scale->sfc->x_step_q4; ys = sf->y_step_q4;
ys = scale->sfc->y_step_q4;
} else { } else {
pre = pre_buf->buf + (y * pre_buf->stride + x); pre = pre_buf->buf + (y * pre_buf->stride + x);
scaled_mv.row = mv_q4.row; scaled_mv.row = mv_q4.row;
@ -203,7 +197,7 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
+ (scaled_mv.col >> SUBPEL_BITS); + (scaled_mv.col >> SUBPEL_BITS);
inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride, inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride,
subpel_x, subpel_y, scale, w, h, ref, &xd->subpix, xs, ys); subpel_x, subpel_y, sf, w, h, ref, &xd->subpix, xs, ys);
} }
} }
@ -262,7 +256,7 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
int ref; int ref;
for (ref = 0; ref < 1 + is_compound; ++ref) { for (ref = 0; ref < 1 + is_compound; ++ref) {
struct scale_factors *const scale = &xd->scale_factor[ref]; const struct scale_factors *const sf = xd->scale_factors[ref];
struct buf_2d *const pre_buf = &pd->pre[ref]; struct buf_2d *const pre_buf = &pd->pre[ref];
struct buf_2d *const dst_buf = &pd->dst; struct buf_2d *const dst_buf = &pd->dst;
uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x;
@ -310,16 +304,15 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
x0_16 = x0 << SUBPEL_BITS; x0_16 = x0 << SUBPEL_BITS;
y0_16 = y0 << SUBPEL_BITS; y0_16 = y0 << SUBPEL_BITS;
if (vp9_is_scaled(scale->sfc)) { if (vp9_is_scaled(sf)) {
scale->sfc->set_scaled_offsets(scale, mi_y + y, mi_x + x); scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
scaled_mv = scale->sfc->scale_mv(&mv_q4, scale); xs = sf->x_step_q4;
xs = scale->sfc->x_step_q4; ys = sf->y_step_q4;
ys = scale->sfc->y_step_q4;
// Get block position in the scaled reference frame. // Get block position in the scaled reference frame.
x0 = scale->sfc->scale_value_x(x0, scale->sfc); x0 = sf->scale_value_x(x0, sf);
y0 = scale->sfc->scale_value_y(y0, scale->sfc); y0 = sf->scale_value_y(y0, sf);
x0_16 = scale->sfc->scale_value_x(x0_16, scale->sfc); x0_16 = sf->scale_value_x(x0_16, sf);
y0_16 = scale->sfc->scale_value_y(y0_16, scale->sfc); y0_16 = sf->scale_value_y(y0_16, sf);
} else { } else {
scaled_mv.row = mv_q4.row; scaled_mv.row = mv_q4.row;
scaled_mv.col = mv_q4.col; scaled_mv.col = mv_q4.col;
@ -367,7 +360,7 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
} }
inter_predictor(buf_ptr, pre_buf->stride, dst, dst_buf->stride, subpel_x, inter_predictor(buf_ptr, pre_buf->stride, dst, dst_buf->stride, subpel_x,
subpel_y, scale, w, h, ref, &xd->subpix, xs, ys); subpel_y, sf, w, h, ref, &xd->subpix, xs, ys);
} }
} }
@ -402,15 +395,9 @@ void vp9_dec_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
void vp9_setup_scale_factors(VP9_COMMON *cm, int i) { void vp9_setup_scale_factors(VP9_COMMON *cm, int i) {
const int ref = cm->active_ref_idx[i]; const int ref = cm->active_ref_idx[i];
struct scale_factors *const sf = &cm->active_ref_scale[i]; struct scale_factors *const sf = &cm->active_ref_scale[i];
struct scale_factors_common *const sfc = &cm->active_ref_scale_comm[i]; YV12_BUFFER_CONFIG *const fb = &cm->yv12_fb[ref];
if (ref >= cm->fb_count) { vp9_setup_scale_factors_for_frame(sf,
vp9_zero(*sf); fb->y_crop_width, fb->y_crop_height,
vp9_zero(*sfc); cm->width, cm->height);
} else {
YV12_BUFFER_CONFIG *const fb = &cm->yv12_fb[ref];
vp9_setup_scale_factors_for_frame(sf, sfc,
fb->y_crop_width, fb->y_crop_height,
cm->width, cm->height);
}
} }

View File

@ -30,18 +30,16 @@ void vp9_dec_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col,
void vp9_build_inter_predictor(const uint8_t *src, int src_stride, void vp9_build_inter_predictor(const uint8_t *src, int src_stride,
uint8_t *dst, int dst_stride, uint8_t *dst, int dst_stride,
const MV *mv_q3, const MV *mv_q3,
struct scale_factors *scale, const struct scale_factors *sf,
int w, int h, int do_avg, int w, int h, int do_avg,
const struct subpix_fn_table *subpix, const struct subpix_fn_table *subpix,
enum mv_precision precision, enum mv_precision precision,
int x, int y); int x, int y);
static int scaled_buffer_offset(int x_offset, int y_offset, int stride, static int scaled_buffer_offset(int x_offset, int y_offset, int stride,
const struct scale_factors *scale) { const struct scale_factors *sf) {
const int x = scale ? scale->sfc->scale_value_x(x_offset, scale->sfc) : const int x = sf ? sf->scale_value_x(x_offset, sf) : x_offset;
x_offset; const int y = sf ? sf->scale_value_y(y_offset, sf) : y_offset;
const int y = scale ? scale->sfc->scale_value_y(y_offset, scale->sfc) :
y_offset;
return y * stride + x; return y * stride + x;
} }
@ -92,10 +90,10 @@ static void setup_pre_planes(MACROBLOCKD *xd, int i,
} }
} }
static void set_scale_factors(MACROBLOCKD *xd, int ref0, int ref1, static void set_scale_factors(VP9_COMMON *cm, MACROBLOCKD *xd,
struct scale_factors sf[MAX_REF_FRAMES]) { int ref0, int ref1) {
xd->scale_factor[0] = sf[ref0 >= 0 ? ref0 : 0]; xd->scale_factors[0] = &cm->active_ref_scale[ref0 >= 0 ? ref0 : 0];
xd->scale_factor[1] = sf[ref1 >= 0 ? ref1 : 0]; xd->scale_factors[1] = &cm->active_ref_scale[ref1 >= 0 ? ref1 : 0];
} }
void vp9_setup_scale_factors(VP9_COMMON *cm, int i); void vp9_setup_scale_factors(VP9_COMMON *cm, int i);

View File

@ -12,47 +12,19 @@
#include "vp9/common/vp9_filter.h" #include "vp9/common/vp9_filter.h"
#include "vp9/common/vp9_scale.h" #include "vp9/common/vp9_scale.h"
static INLINE int scaled_x(int val, const struct scale_factors_common *sfc) { static INLINE int scaled_x(int val, const struct scale_factors *sf) {
return val * sfc->x_scale_fp >> REF_SCALE_SHIFT; return val * sf->x_scale_fp >> REF_SCALE_SHIFT;
} }
static INLINE int scaled_y(int val, const struct scale_factors_common *sfc) { static INLINE int scaled_y(int val, const struct scale_factors *sf) {
return val * sfc->y_scale_fp >> REF_SCALE_SHIFT; return val * sf->y_scale_fp >> REF_SCALE_SHIFT;
} }
static int unscaled_value(int val, const struct scale_factors_common *sfc) { static int unscaled_value(int val, const struct scale_factors *sf) {
(void) sfc; (void) sf;
return val; return val;
} }
static MV32 scaled_mv(const MV *mv, const struct scale_factors *scale) {
const MV32 res = {
scaled_y(mv->row, scale->sfc) + scale->y_offset_q4,
scaled_x(mv->col, scale->sfc) + scale->x_offset_q4
};
return res;
}
static MV32 unscaled_mv(const MV *mv, const struct scale_factors *scale) {
const MV32 res = {
mv->row,
mv->col
};
return res;
}
static void set_offsets_with_scaling(struct scale_factors *scale,
int row, int col) {
scale->x_offset_q4 = scaled_x(col << SUBPEL_BITS, scale->sfc) & SUBPEL_MASK;
scale->y_offset_q4 = scaled_y(row << SUBPEL_BITS, scale->sfc) & SUBPEL_MASK;
}
static void set_offsets_without_scaling(struct scale_factors *scale,
int row, int col) {
scale->x_offset_q4 = 0;
scale->y_offset_q4 = 0;
}
static int get_fixed_point_scale_factor(int other_size, int this_size) { static int get_fixed_point_scale_factor(int other_size, int this_size) {
// Calculate scaling factor once for each reference frame // Calculate scaling factor once for each reference frame
// and use fixed point scaling factors in decoding and encoding routines. // and use fixed point scaling factors in decoding and encoding routines.
@ -69,31 +41,36 @@ static int check_scale_factors(int other_w, int other_h,
this_h <= 16 * other_h; this_h <= 16 * other_h;
} }
void vp9_setup_scale_factors_for_frame(struct scale_factors *scale, MV32 vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf) {
struct scale_factors_common *scale_comm, const int x_off_q4 = scaled_x(x << SUBPEL_BITS, sf) & SUBPEL_MASK;
const int y_off_q4 = scaled_y(y << SUBPEL_BITS, sf) & SUBPEL_MASK;
const MV32 res = {
scaled_y(mv->row, sf) + y_off_q4,
scaled_x(mv->col, sf) + x_off_q4
};
return res;
}
void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
int other_w, int other_h, int other_w, int other_h,
int this_w, int this_h) { int this_w, int this_h) {
if (!check_scale_factors(other_w, other_h, this_w, this_h)) { if (!check_scale_factors(other_w, other_h, this_w, this_h)) {
scale_comm->x_scale_fp = REF_INVALID_SCALE; sf->x_scale_fp = REF_INVALID_SCALE;
scale_comm->y_scale_fp = REF_INVALID_SCALE; sf->y_scale_fp = REF_INVALID_SCALE;
return; return;
} }
scale_comm->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w); sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
scale_comm->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h); sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
scale_comm->x_step_q4 = scaled_x(16, scale_comm); sf->x_step_q4 = scaled_x(16, sf);
scale_comm->y_step_q4 = scaled_y(16, scale_comm); sf->y_step_q4 = scaled_y(16, sf);
if (vp9_is_scaled(scale_comm)) { if (vp9_is_scaled(sf)) {
scale_comm->scale_value_x = scaled_x; sf->scale_value_x = scaled_x;
scale_comm->scale_value_y = scaled_y; sf->scale_value_y = scaled_y;
scale_comm->set_scaled_offsets = set_offsets_with_scaling;
scale_comm->scale_mv = scaled_mv;
} else { } else {
scale_comm->scale_value_x = unscaled_value; sf->scale_value_x = unscaled_value;
scale_comm->scale_value_y = unscaled_value; sf->scale_value_y = unscaled_value;
scale_comm->set_scaled_offsets = set_offsets_without_scaling;
scale_comm->scale_mv = unscaled_mv;
} }
// TODO(agrange): Investigate the best choice of functions to use here // TODO(agrange): Investigate the best choice of functions to use here
@ -102,48 +79,44 @@ void vp9_setup_scale_factors_for_frame(struct scale_factors *scale,
// applied in one direction only, and not at all for 0,0, seems to give the // applied in one direction only, and not at all for 0,0, seems to give the
// best quality, but it may be worth trying an additional mode that does // best quality, but it may be worth trying an additional mode that does
// do the filtering on full-pel. // do the filtering on full-pel.
if (scale_comm->x_step_q4 == 16) { if (sf->x_step_q4 == 16) {
if (scale_comm->y_step_q4 == 16) { if (sf->y_step_q4 == 16) {
// No scaling in either direction. // No scaling in either direction.
scale_comm->predict[0][0][0] = vp9_convolve_copy; sf->predict[0][0][0] = vp9_convolve_copy;
scale_comm->predict[0][0][1] = vp9_convolve_avg; sf->predict[0][0][1] = vp9_convolve_avg;
scale_comm->predict[0][1][0] = vp9_convolve8_vert; sf->predict[0][1][0] = vp9_convolve8_vert;
scale_comm->predict[0][1][1] = vp9_convolve8_avg_vert; sf->predict[0][1][1] = vp9_convolve8_avg_vert;
scale_comm->predict[1][0][0] = vp9_convolve8_horiz; sf->predict[1][0][0] = vp9_convolve8_horiz;
scale_comm->predict[1][0][1] = vp9_convolve8_avg_horiz; sf->predict[1][0][1] = vp9_convolve8_avg_horiz;
} else { } else {
// No scaling in x direction. Must always scale in the y direction. // No scaling in x direction. Must always scale in the y direction.
scale_comm->predict[0][0][0] = vp9_convolve8_vert; sf->predict[0][0][0] = vp9_convolve8_vert;
scale_comm->predict[0][0][1] = vp9_convolve8_avg_vert; sf->predict[0][0][1] = vp9_convolve8_avg_vert;
scale_comm->predict[0][1][0] = vp9_convolve8_vert; sf->predict[0][1][0] = vp9_convolve8_vert;
scale_comm->predict[0][1][1] = vp9_convolve8_avg_vert; sf->predict[0][1][1] = vp9_convolve8_avg_vert;
scale_comm->predict[1][0][0] = vp9_convolve8; sf->predict[1][0][0] = vp9_convolve8;
scale_comm->predict[1][0][1] = vp9_convolve8_avg; sf->predict[1][0][1] = vp9_convolve8_avg;
} }
} else { } else {
if (scale_comm->y_step_q4 == 16) { if (sf->y_step_q4 == 16) {
// No scaling in the y direction. Must always scale in the x direction. // No scaling in the y direction. Must always scale in the x direction.
scale_comm->predict[0][0][0] = vp9_convolve8_horiz; sf->predict[0][0][0] = vp9_convolve8_horiz;
scale_comm->predict[0][0][1] = vp9_convolve8_avg_horiz; sf->predict[0][0][1] = vp9_convolve8_avg_horiz;
scale_comm->predict[0][1][0] = vp9_convolve8; sf->predict[0][1][0] = vp9_convolve8;
scale_comm->predict[0][1][1] = vp9_convolve8_avg; sf->predict[0][1][1] = vp9_convolve8_avg;
scale_comm->predict[1][0][0] = vp9_convolve8_horiz; sf->predict[1][0][0] = vp9_convolve8_horiz;
scale_comm->predict[1][0][1] = vp9_convolve8_avg_horiz; sf->predict[1][0][1] = vp9_convolve8_avg_horiz;
} else { } else {
// Must always scale in both directions. // Must always scale in both directions.
scale_comm->predict[0][0][0] = vp9_convolve8; sf->predict[0][0][0] = vp9_convolve8;
scale_comm->predict[0][0][1] = vp9_convolve8_avg; sf->predict[0][0][1] = vp9_convolve8_avg;
scale_comm->predict[0][1][0] = vp9_convolve8; sf->predict[0][1][0] = vp9_convolve8;
scale_comm->predict[0][1][1] = vp9_convolve8_avg; sf->predict[0][1][1] = vp9_convolve8_avg;
scale_comm->predict[1][0][0] = vp9_convolve8; sf->predict[1][0][0] = vp9_convolve8;
scale_comm->predict[1][0][1] = vp9_convolve8_avg; sf->predict[1][0][1] = vp9_convolve8_avg;
} }
} }
// 2D subpel motion always gets filtered in both directions // 2D subpel motion always gets filtered in both directions
scale_comm->predict[1][1][0] = vp9_convolve8; sf->predict[1][1][0] = vp9_convolve8;
scale_comm->predict[1][1][1] = vp9_convolve8_avg; sf->predict[1][1][1] = vp9_convolve8_avg;
scale->sfc = scale_comm;
scale->x_offset_q4 = 0; // calculated per block
scale->y_offset_q4 = 0; // calculated per block
} }

View File

@ -18,40 +18,32 @@
#define REF_NO_SCALE (1 << REF_SCALE_SHIFT) #define REF_NO_SCALE (1 << REF_SCALE_SHIFT)
#define REF_INVALID_SCALE -1 #define REF_INVALID_SCALE -1
struct scale_factors; struct scale_factors {
struct scale_factors_common {
int x_scale_fp; // horizontal fixed point scale factor int x_scale_fp; // horizontal fixed point scale factor
int y_scale_fp; // vertical fixed point scale factor int y_scale_fp; // vertical fixed point scale factor
int x_step_q4; int x_step_q4;
int y_step_q4; int y_step_q4;
int (*scale_value_x)(int val, const struct scale_factors_common *sfc); int (*scale_value_x)(int val, const struct scale_factors *sf);
int (*scale_value_y)(int val, const struct scale_factors_common *sfc); int (*scale_value_y)(int val, const struct scale_factors *sf);
void (*set_scaled_offsets)(struct scale_factors *scale, int row, int col);
MV32 (*scale_mv)(const MV *mv, const struct scale_factors *scale);
convolve_fn_t predict[2][2][2]; // horiz, vert, avg convolve_fn_t predict[2][2][2]; // horiz, vert, avg
}; };
struct scale_factors { MV32 vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf);
int x_offset_q4;
int y_offset_q4;
const struct scale_factors_common *sfc;
};
void vp9_setup_scale_factors_for_frame(struct scale_factors *scale, void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
struct scale_factors_common *scale_comm,
int other_w, int other_h, int other_w, int other_h,
int this_w, int this_h); int this_w, int this_h);
static int vp9_is_valid_scale(const struct scale_factors_common *sfc) { static int vp9_is_valid_scale(const struct scale_factors *sf) {
return sfc->x_scale_fp != REF_INVALID_SCALE && return sf->x_scale_fp != REF_INVALID_SCALE &&
sfc->y_scale_fp != REF_INVALID_SCALE; sf->y_scale_fp != REF_INVALID_SCALE;
} }
static int vp9_is_scaled(const struct scale_factors_common *sfc) { static int vp9_is_scaled(const struct scale_factors *sf) {
return sfc->x_scale_fp != REF_NO_SCALE || return sf->x_scale_fp != REF_NO_SCALE ||
sfc->y_scale_fp != REF_NO_SCALE; sf->y_scale_fp != REF_NO_SCALE;
} }
#endif // VP9_COMMON_VP9_SCALE_H_ #endif // VP9_COMMON_VP9_SCALE_H_

View File

@ -380,15 +380,15 @@ static void set_ref(VP9_COMMON *const cm, MACROBLOCKD *const xd,
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
const int ref = mbmi->ref_frame[idx] - LAST_FRAME; const int ref = mbmi->ref_frame[idx] - LAST_FRAME;
const YV12_BUFFER_CONFIG *cfg = get_frame_ref_buffer(cm, ref); const YV12_BUFFER_CONFIG *cfg = get_frame_ref_buffer(cm, ref);
const struct scale_factors_common *sfc = &cm->active_ref_scale_comm[ref]; const struct scale_factors *sf = &cm->active_ref_scale[ref];
xd->ref_buf[idx] = cfg; xd->ref_buf[idx] = cfg;
if (!vp9_is_valid_scale(sfc)) if (!vp9_is_valid_scale(sf))
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
"Invalid scale factors"); "Invalid scale factors");
xd->scale_factor[idx].sfc = sfc; xd->scale_factors[idx] = sf;
setup_pre_planes(xd, idx, cfg, mi_row, mi_col, &xd->scale_factor[idx]); setup_pre_planes(xd, idx, cfg, mi_row, mi_col, xd->scale_factors[idx]);
xd->corrupted |= cfg->corrupted; xd->corrupted |= cfg->corrupted;
} }
@ -1201,7 +1201,7 @@ static size_t read_uncompressed_header(VP9D_COMP *pbi,
for (i = 0; i < REFS_PER_FRAME; ++i) { for (i = 0; i < REFS_PER_FRAME; ++i) {
vp9_setup_scale_factors(cm, i); vp9_setup_scale_factors(cm, i);
if (vp9_is_scaled(&cm->active_ref_scale_comm[i])) if (vp9_is_scaled(&cm->active_ref_scale[i]))
vp9_extend_frame_borders(&cm->yv12_fb[cm->active_ref_idx[i]], vp9_extend_frame_borders(&cm->yv12_fb[cm->active_ref_idx[i]],
cm->subsampling_x, cm->subsampling_y); cm->subsampling_x, cm->subsampling_y);
} }

View File

@ -2594,10 +2594,9 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled,
assert(cm->frame_type != KEY_FRAME); assert(cm->frame_type != KEY_FRAME);
setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, setup_pre_planes(xd, 0, ref_fb, mi_row, mi_col, xd->scale_factors[0]);
&xd->scale_factor[0]);
setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col, setup_pre_planes(xd, 1, second_ref_fb, mi_row, mi_col,
&xd->scale_factor[1]); xd->scale_factors[1]);
vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); vp9_build_inter_predictors_sb(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8));
} }

View File

@ -31,11 +31,11 @@ void vp9_setup_interp_filters(MACROBLOCKD *xd,
if (xd->mi_8x8 && xd->mi_8x8[0]) { if (xd->mi_8x8 && xd->mi_8x8[0]) {
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
set_scale_factors(xd, mbmi->ref_frame[0] - LAST_FRAME, set_scale_factors(cm, xd, mbmi->ref_frame[0] - LAST_FRAME,
mbmi->ref_frame[1] - LAST_FRAME, mbmi->ref_frame[1] - LAST_FRAME);
cm->active_ref_scale);
} else { } else {
set_scale_factors(xd, -1, -1, cm->active_ref_scale); set_scale_factors(cm, xd, -1, -1);
} }
xd->subpix.filter_x = xd->subpix.filter_y = xd->subpix.filter_x = xd->subpix.filter_y =

View File

@ -3550,7 +3550,7 @@ int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags,
// Calculate scaling factors for each of the 3 available references // Calculate scaling factors for each of the 3 available references
for (i = 0; i < REFS_PER_FRAME; ++i) { for (i = 0; i < REFS_PER_FRAME; ++i) {
vp9_setup_scale_factors(cm, i); vp9_setup_scale_factors(cm, i);
if (vp9_is_scaled(&cm->active_ref_scale_comm[i])) if (vp9_is_scaled(&cm->active_ref_scale[i]))
vp9_extend_frame_borders(&cm->yv12_fb[cm->active_ref_idx[i]], vp9_extend_frame_borders(&cm->yv12_fb[cm->active_ref_idx[i]],
cm->subsampling_x, cm->subsampling_y); cm->subsampling_x, cm->subsampling_y);
} }

View File

@ -1521,7 +1521,7 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
vp9_build_inter_predictor(pre, pd->pre[ref].stride, vp9_build_inter_predictor(pre, pd->pre[ref].stride,
dst, pd->dst.stride, dst, pd->dst.stride,
&mi->bmi[i].as_mv[ref].as_mv, &mi->bmi[i].as_mv[ref].as_mv,
&xd->scale_factor[ref], xd->scale_factors[ref],
width, height, ref, &xd->subpix, MV_PRECISION_Q3, width, height, ref, &xd->subpix, MV_PRECISION_Q3,
mi_col * MI_SIZE + 4 * (i % 2), mi_col * MI_SIZE + 4 * (i % 2),
mi_row * MI_SIZE + 4 * (i / 2)); mi_row * MI_SIZE + 4 * (i / 2));
@ -2257,23 +2257,18 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
int mi_row, int mi_col, int mi_row, int mi_col,
int_mv frame_nearest_mv[MAX_REF_FRAMES], int_mv frame_nearest_mv[MAX_REF_FRAMES],
int_mv frame_near_mv[MAX_REF_FRAMES], int_mv frame_near_mv[MAX_REF_FRAMES],
struct buf_2d yv12_mb[4][MAX_MB_PLANE], struct buf_2d yv12_mb[4][MAX_MB_PLANE]) {
struct scale_factors scale[MAX_REF_FRAMES]) {
VP9_COMMON *cm = &cpi->common; VP9_COMMON *cm = &cpi->common;
YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]]; YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]];
MACROBLOCKD *const xd = &x->e_mbd; MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
const struct scale_factors *const sf =
&cpi->common.active_ref_scale[frame_type - 1];
// set up scaling factors
scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1];
scale[frame_type].sfc->set_scaled_offsets(&scale[frame_type],
mi_row * MI_SIZE, mi_col * MI_SIZE);
// TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
// use the UV scaling factors. // use the UV scaling factors.
setup_pred_block(xd, yv12_mb[frame_type], yv12, mi_row, mi_col, setup_pred_block(xd, yv12_mb[frame_type], yv12, mi_row, mi_col, sf, sf);
&scale[frame_type], &scale[frame_type]);
// Gets an initial list of candidate vectors from neighbours and orders them // Gets an initial list of candidate vectors from neighbours and orders them
vp9_find_mv_refs(cm, xd, tile, xd->mi_8x8[0], vp9_find_mv_refs(cm, xd, tile, xd->mi_8x8[0],
@ -2290,7 +2285,7 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
// Further refinement that is encode side only to test the top few candidates // Further refinement that is encode side only to test the top few candidates
// in full and choose the best as the centre point for subsequent searches. // in full and choose the best as the centre point for subsequent searches.
// The current implementation doesn't support scaling. // The current implementation doesn't support scaling.
if (!vp9_is_scaled(scale[frame_type].sfc) && block_size >= BLOCK_8X8) if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8)
mv_pred(cpi, x, yv12_mb[frame_type][0].buf, yv12->y_stride, mv_pred(cpi, x, yv12_mb[frame_type][0].buf, yv12->y_stride,
frame_type, block_size); frame_type, block_size);
} }
@ -2516,7 +2511,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
ref_yv12[!id].stride, ref_yv12[!id].stride,
second_pred, pw, second_pred, pw,
&frame_mv[refs[!id]].as_mv, &frame_mv[refs[!id]].as_mv,
&xd->scale_factor[!id], xd->scale_factors[!id],
pw, ph, 0, pw, ph, 0,
&xd->subpix, MV_PRECISION_Q3, &xd->subpix, MV_PRECISION_Q3,
mi_col * MI_SIZE, mi_row * MI_SIZE); mi_col * MI_SIZE, mi_row * MI_SIZE);
@ -3126,7 +3121,6 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int64_t dist_uv[TX_SIZES]; int64_t dist_uv[TX_SIZES];
int skip_uv[TX_SIZES]; int skip_uv[TX_SIZES];
MB_PREDICTION_MODE mode_uv[TX_SIZES]; MB_PREDICTION_MODE mode_uv[TX_SIZES];
struct scale_factors scale_factor[4];
unsigned int ref_frame_mask = 0; unsigned int ref_frame_mask = 0;
unsigned int mode_mask = 0; unsigned int mode_mask = 0;
int64_t mode_distortions[MB_MODE_COUNT] = {-1}; int64_t mode_distortions[MB_MODE_COUNT] = {-1};
@ -3193,8 +3187,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
if (cpi->ref_frame_flags & flag_list[ref_frame]) { if (cpi->ref_frame_flags & flag_list[ref_frame]) {
setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame,
block_size, mi_row, mi_col, block_size, mi_row, mi_col,
frame_mv[NEARESTMV], frame_mv[NEARMV], frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb);
yv12_mb, scale_factor);
} }
frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
frame_mv[ZEROMV][ref_frame].as_int = 0; frame_mv[ZEROMV][ref_frame].as_int = 0;
@ -3307,7 +3300,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
continue; continue;
} }
set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); set_scale_factors(cm, xd, ref_frame - 1, second_ref_frame - 1);
mbmi->uv_mode = DC_PRED; mbmi->uv_mode = DC_PRED;
// Evaluate all sub-pel filters irrespective of whether we can use // Evaluate all sub-pel filters irrespective of whether we can use
@ -3319,7 +3312,6 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
continue; continue;
set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor);
mode_excluded = mode_excluded ? mode_excluded mode_excluded = mode_excluded ? mode_excluded
: cm->reference_mode == SINGLE_REFERENCE; : cm->reference_mode == SINGLE_REFERENCE;
} else { } else {
@ -3757,8 +3749,7 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
vp9_zero(best_tx_diff); vp9_zero(best_tx_diff);
} }
set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], set_scale_factors(cm, xd, mbmi->ref_frame[0] - 1, mbmi->ref_frame[1] - 1);
scale_factor);
store_coding_context(x, ctx, best_mode_index, store_coding_context(x, ctx, best_mode_index,
&mbmi->ref_mvs[mbmi->ref_frame[0]][0], &mbmi->ref_mvs[mbmi->ref_frame[0]][0],
&mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 :
@ -3812,7 +3803,6 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
int64_t dist_uv[TX_SIZES]; int64_t dist_uv[TX_SIZES];
int skip_uv[TX_SIZES]; int skip_uv[TX_SIZES];
MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 }; MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 };
struct scale_factors scale_factor[4];
int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex,
cpi->common.y_dc_delta_q); cpi->common.y_dc_delta_q);
int_mv seg_mvs[4][MAX_REF_FRAMES]; int_mv seg_mvs[4][MAX_REF_FRAMES];
@ -3847,7 +3837,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame,
block_size, mi_row, mi_col, block_size, mi_row, mi_col,
frame_mv[NEARESTMV], frame_mv[NEARMV], frame_mv[NEARESTMV], frame_mv[NEARMV],
yv12_mb, scale_factor); yv12_mb);
} }
frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
frame_mv[ZEROMV][ref_frame].as_int = 0; frame_mv[ZEROMV][ref_frame].as_int = 0;
@ -3944,14 +3934,14 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
// TODO(jingning, jkoleszar): scaling reference frame not supported for // TODO(jingning, jkoleszar): scaling reference frame not supported for
// sub8x8 blocks. // sub8x8 blocks.
if (ref_frame > 0 && if (ref_frame > 0 &&
vp9_is_scaled(scale_factor[ref_frame].sfc)) vp9_is_scaled(&cpi->common.active_ref_scale[ref_frame - 1]))
continue; continue;
if (second_ref_frame > 0 && if (second_ref_frame > 0 &&
vp9_is_scaled(scale_factor[second_ref_frame].sfc)) vp9_is_scaled(&cpi->common.active_ref_scale[second_ref_frame - 1]))
continue; continue;
set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); set_scale_factors(cm, xd, ref_frame - 1, second_ref_frame - 1);
mbmi->uv_mode = DC_PRED; mbmi->uv_mode = DC_PRED;
// Evaluate all sub-pel filters irrespective of whether we can use // Evaluate all sub-pel filters irrespective of whether we can use
@ -3962,7 +3952,6 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
if (comp_pred) { if (comp_pred) {
if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
continue; continue;
set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor);
mode_excluded = mode_excluded ? mode_excluded mode_excluded = mode_excluded ? mode_excluded
: cm->reference_mode == SINGLE_REFERENCE; : cm->reference_mode == SINGLE_REFERENCE;
@ -4498,8 +4487,7 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
vp9_zero(best_tx_diff); vp9_zero(best_tx_diff);
} }
set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], set_scale_factors(cm, xd, mbmi->ref_frame[0] - 1, mbmi->ref_frame[1] - 1);
scale_factor);
store_coding_context(x, ctx, best_mode_index, store_coding_context(x, ctx, best_mode_index,
&mbmi->ref_mvs[mbmi->ref_frame[0]][0], &mbmi->ref_mvs[mbmi->ref_frame[0]][0],
&mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 :

View File

@ -393,8 +393,7 @@ void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance) {
const int num_frames_forward = vp9_lookahead_depth(cpi->lookahead) const int num_frames_forward = vp9_lookahead_depth(cpi->lookahead)
- (num_frames_backward + 1); - (num_frames_backward + 1);
struct scale_factors scale; struct scale_factors sf;
struct scale_factors_common scale_comm;
switch (blur_type) { switch (blur_type) {
case 1: case 1:
@ -454,7 +453,7 @@ void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance) {
#endif #endif
// Setup scaling factors. Scaling on each of the arnr frames is not supported // Setup scaling factors. Scaling on each of the arnr frames is not supported
vp9_setup_scale_factors_for_frame(&scale, &scale_comm, vp9_setup_scale_factors_for_frame(&sf,
get_frame_new_buffer(cm)->y_crop_width, get_frame_new_buffer(cm)->y_crop_width,
get_frame_new_buffer(cm)->y_crop_height, get_frame_new_buffer(cm)->y_crop_height,
cm->width, cm->height); cm->width, cm->height);
@ -469,7 +468,7 @@ void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance) {
} }
temporal_filter_iterate_c(cpi, frames_to_blur, frames_to_blur_backward, temporal_filter_iterate_c(cpi, frames_to_blur, frames_to_blur_backward,
strength, &scale); strength, &sf);
} }
void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame, void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame,