Commit 50e54c11 authored by Dmitry Kovalev's avatar Dmitry Kovalev

Code cleanup.

Adding multiple16 function, removing redundant code, better formatting.

Change-Id: I50195b78ac8ab803e3d05c8fb05a7ca134fab386
parent e3955007
......@@ -19,17 +19,16 @@
#include "vp9/common/vp9_systemdependent.h"
void vp9_update_mode_info_border(VP9_COMMON *cpi, MODE_INFO *mi_base) {
int stride = cpi->mode_info_stride;
void vp9_update_mode_info_border(VP9_COMMON *cpi, MODE_INFO *mi) {
const int stride = cpi->mode_info_stride;
int i;
// Clear down top border row
vpx_memset(mi_base, 0, sizeof(MODE_INFO) * cpi->mode_info_stride);
vpx_memset(mi, 0, sizeof(MODE_INFO) * stride);
// Clear left border column
for (i = 1; i < cpi->mb_rows + 1; i++) {
vpx_memset(&mi_base[i * stride], 0, sizeof(MODE_INFO));
}
for (i = 1; i < cpi->mb_rows + 1; i++)
vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO));
}
void vp9_update_mode_info_in_image(VP9_COMMON *cpi, MODE_INFO *mi) {
......@@ -39,14 +38,14 @@ void vp9_update_mode_info_in_image(VP9_COMMON *cpi, MODE_INFO *mi) {
for (i = 0; i < cpi->mb_rows; i++) {
for (j = 0; j < cpi->mb_cols; j++) {
mi->mbmi.mb_in_image = 1;
mi++; // Next element in the row
mi++; // Next element in the row
}
mi++; // Step over border element at start of next row
mi++; // Step over border element at start of next row
}
}
void vp9_de_alloc_frame_buffers(VP9_COMMON *oci) {
void vp9_free_frame_buffers(VP9_COMMON *oci) {
int i;
for (i = 0; i < NUM_YV12_BUFFERS; i++)
......@@ -67,19 +66,18 @@ void vp9_de_alloc_frame_buffers(VP9_COMMON *oci) {
int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
int i;
int aligned_width, aligned_height;
vp9_de_alloc_frame_buffers(oci);
// Our internal buffers are always multiples of 16
const int aligned_width = multiple16(width);
const int aligned_height = multiple16(height);
/* our internal buffers are always multiples of 16 */
aligned_width = (width + 15) & ~15;
aligned_height = (height + 15) & ~15;
vp9_free_frame_buffers(oci);
for (i = 0; i < NUM_YV12_BUFFERS; i++) {
oci->fb_idx_ref_cnt[i] = 0;
if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height,
VP9BORDERINPIXELS) < 0) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
}
......@@ -97,13 +95,13 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16,
VP9BORDERINPIXELS) < 0) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height,
VP9BORDERINPIXELS) < 0) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
......@@ -114,7 +112,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
if (!oci->mip) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
......@@ -125,7 +123,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
if (!oci->prev_mip) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
......@@ -135,7 +133,7 @@ int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height) {
vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * (3 + oci->mb_cols), 1);
if (!oci->above_context) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
return 1;
}
......@@ -200,20 +198,18 @@ void vp9_create_common(VP9_COMMON *oci) {
oci->clr_type = REG_YUV;
oci->clamp_type = RECON_CLAMP_REQUIRED;
/* Initialise reference frame sign bias structure to defaults */
// Initialize reference frame sign bias structure to defaults
vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
oci->kf_ymode_probs_update = 0;
}
void vp9_remove_common(VP9_COMMON *oci) {
vp9_de_alloc_frame_buffers(oci);
vp9_free_frame_buffers(oci);
}
void vp9_initialize_common() {
vp9_coef_tree_initialize();
vp9_entropy_mode_init();
vp9_entropy_mv_init();
}
......@@ -14,13 +14,15 @@
#include "vp9/common/vp9_onyxc_int.h"
void vp9_update_mode_info_border(VP9_COMMON *cpi, MODE_INFO *mi);
void vp9_update_mode_info_in_image(VP9_COMMON *cpi, MODE_INFO *mi);
void vp9_create_common(VP9_COMMON *oci);
void vp9_remove_common(VP9_COMMON *oci);
void vp9_de_alloc_frame_buffers(VP9_COMMON *oci);
int vp9_alloc_frame_buffers(VP9_COMMON *oci, int width, int height);
void vp9_setup_version(VP9_COMMON *oci);
void vp9_free_frame_buffers(VP9_COMMON *oci);
void vp9_update_mode_info_border(VP9_COMMON *cpi, MODE_INFO *mi_base);
void vp9_update_mode_info_in_image(VP9_COMMON *cpi, MODE_INFO *mi);
void vp9_setup_version(VP9_COMMON *oci);
#endif // VP9_COMMON_VP9_ALLOCCOMMON_H_
......@@ -652,25 +652,28 @@ static void update_blockd_bmi(MACROBLOCKD *xd) {
}
static TX_SIZE get_uv_tx_size(const MACROBLOCKD *xd) {
TX_SIZE tx_size_uv;
if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB64X64) {
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
} else if (xd->mode_info_context->mbmi.sb_type == BLOCK_SIZE_SB32X32) {
if (xd->mode_info_context->mbmi.txfm_size == TX_32X32)
tx_size_uv = TX_16X16;
else
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
} else {
if (xd->mode_info_context->mbmi.txfm_size == TX_16X16)
tx_size_uv = TX_8X8;
else if (xd->mode_info_context->mbmi.txfm_size == TX_8X8 &&
(xd->mode_info_context->mbmi.mode == I8X8_PRED ||
xd->mode_info_context->mbmi.mode == SPLITMV))
tx_size_uv = TX_4X4;
else
tx_size_uv = xd->mode_info_context->mbmi.txfm_size;
MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
const TX_SIZE size = mbmi->txfm_size;
const MB_PREDICTION_MODE mode = mbmi->mode;
switch (mbmi->sb_type) {
case BLOCK_SIZE_SB64X64:
return size;
case BLOCK_SIZE_SB32X32:
if (size == TX_32X32)
return TX_16X16;
else
return size;
default:
if (size == TX_16X16)
return TX_8X8;
else if (size == TX_8X8 && (mode == I8X8_PRED || mode == SPLITMV))
return TX_4X4;
else
return size;
}
return tx_size_uv;
return size;
}
#if CONFIG_CODE_NONZEROCOUNT
......
......@@ -55,4 +55,8 @@ static INLINE int clamp(int value, int low, int high) {
return value < low ? low : (value > high ? high : value);
}
static INLINE int multiple16(int value) {
return (value + 15) & ~15;
}
#endif // VP9_COMMON_VP9_COMMON_H_
......@@ -88,10 +88,14 @@ const nmv_context vp9_default_nmv_context = {
};
MV_JOINT_TYPE vp9_get_mv_joint(MV mv) {
if (mv.row == 0 && mv.col == 0) return MV_JOINT_ZERO;
else if (mv.row == 0 && mv.col != 0) return MV_JOINT_HNZVZ;
else if (mv.row != 0 && mv.col == 0) return MV_JOINT_HZVNZ;
else return MV_JOINT_HNZVNZ;
if (mv.row == 0 && mv.col == 0)
return MV_JOINT_ZERO;
else if (mv.row == 0 && mv.col != 0)
return MV_JOINT_HNZVZ;
else if (mv.row != 0 && mv.col == 0)
return MV_JOINT_HZVNZ;
else
return MV_JOINT_HNZVNZ;
}
#define mv_class_base(c) ((c) ? (CLASS0_SIZE << (c + 2)) : 0)
......@@ -137,7 +141,8 @@ static void increment_nmv_component(int v,
int incr,
int usehp) {
int s, z, c, o, d, e, f;
if (!incr) return;
if (!incr)
return;
assert (v != 0); /* should not be zero */
s = v < 0;
mvcomp->sign[s] += incr;
......@@ -152,8 +157,8 @@ static void increment_nmv_component(int v,
if (c == MV_CLASS_0) {
mvcomp->class0[d] += incr;
} else {
int i, b;
b = c + CLASS0_BITS - 1; /* number of bits */
int i;
int b = c + CLASS0_BITS - 1; // number of bits
for (i = 0; i < b; ++i)
mvcomp->bits[i][((d >> i) & 1)] += incr;
}
......@@ -204,25 +209,22 @@ static void counts_to_context(nmv_component_counts *mvcomp, int usehp) {
void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx,
int usehp) {
MV_JOINT_TYPE j = vp9_get_mv_joint(*mv);
mvctx->joints[j]++;
const MV_JOINT_TYPE type = vp9_get_mv_joint(*mv);
mvctx->joints[type]++;
usehp = usehp && vp9_use_nmv_hp(ref);
if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) {
if (type == MV_JOINT_HZVNZ || type == MV_JOINT_HNZVNZ)
increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp);
}
if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) {
if (type == MV_JOINT_HNZVZ || type == MV_JOINT_HNZVNZ)
increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp);
}
}
static void adapt_prob(vp9_prob *dest, vp9_prob prep,
unsigned int ct[2]) {
int count = ct[0] + ct[1];
static void adapt_prob(vp9_prob *dest, vp9_prob prep, unsigned int ct[2]) {
const int count = MIN(ct[0] + ct[1], MV_COUNT_SAT);
if (count) {
vp9_prob newp = get_binary_prob(ct[0], ct[1]);
count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count;
*dest = weighted_prob(prep, newp,
MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT);
const vp9_prob newp = get_binary_prob(ct[0], ct[1]);
const int factor = MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT;
*dest = weighted_prob(prep, newp, factor);
} else {
*dest = prep;
}
......@@ -253,10 +255,12 @@ void vp9_counts_to_nmv_context(
branch_ct_joint,
nmv_count->joints, 0);
for (i = 0; i < 2; ++i) {
prob->comps[i].sign = get_binary_prob(nmv_count->comps[i].sign[0],
nmv_count->comps[i].sign[1]);
branch_ct_sign[i][0] = nmv_count->comps[i].sign[0];
branch_ct_sign[i][1] = nmv_count->comps[i].sign[1];
const uint32_t s0 = nmv_count->comps[i].sign[0];
const uint32_t s1 = nmv_count->comps[i].sign[1];
prob->comps[i].sign = get_binary_prob(s0, s1);
branch_ct_sign[i][0] = s0;
branch_ct_sign[i][1] = s1;
vp9_tree_probs_from_distribution(vp9_mv_class_tree,
prob->comps[i].classes,
branch_ct_classes[i],
......@@ -266,10 +270,12 @@ void vp9_counts_to_nmv_context(
branch_ct_class0[i],
nmv_count->comps[i].class0, 0);
for (j = 0; j < MV_OFFSET_BITS; ++j) {
prob->comps[i].bits[j] = get_binary_prob(nmv_count->comps[i].bits[j][0],
nmv_count->comps[i].bits[j][1]);
branch_ct_bits[i][j][0] = nmv_count->comps[i].bits[j][0];
branch_ct_bits[i][j][1] = nmv_count->comps[i].bits[j][1];
const uint32_t b0 = nmv_count->comps[i].bits[j][0];
const uint32_t b1 = nmv_count->comps[i].bits[j][1];
prob->comps[i].bits[j] = get_binary_prob(b0, b1);
branch_ct_bits[i][j][0] = b0;
branch_ct_bits[i][j][1] = b1;
}
}
for (i = 0; i < 2; ++i) {
......@@ -286,16 +292,18 @@ void vp9_counts_to_nmv_context(
}
if (usehp) {
for (i = 0; i < 2; ++i) {
prob->comps[i].class0_hp =
get_binary_prob(nmv_count->comps[i].class0_hp[0],
nmv_count->comps[i].class0_hp[1]);
branch_ct_class0_hp[i][0] = nmv_count->comps[i].class0_hp[0];
branch_ct_class0_hp[i][1] = nmv_count->comps[i].class0_hp[1];
prob->comps[i].hp = get_binary_prob(nmv_count->comps[i].hp[0],
nmv_count->comps[i].hp[1]);
branch_ct_hp[i][0] = nmv_count->comps[i].hp[0];
branch_ct_hp[i][1] = nmv_count->comps[i].hp[1];
const uint32_t c0_hp0 = nmv_count->comps[i].class0_hp[0];
const uint32_t c0_hp1 = nmv_count->comps[i].class0_hp[1];
const uint32_t hp0 = nmv_count->comps[i].hp[0];
const uint32_t hp1 = nmv_count->comps[i].hp[1];
prob->comps[i].class0_hp = get_binary_prob(c0_hp0, c0_hp1);
branch_ct_class0_hp[i][0] = c0_hp0;
branch_ct_class0_hp[i][1] = c0_hp1;
prob->comps[i].hp = get_binary_prob(hp0, hp1);
branch_ct_hp[i][0] = hp0;
branch_ct_hp[i][1] = hp1;
}
}
}
......
......@@ -191,11 +191,12 @@ void segment_via_mode_info(VP9_COMMON *oci, int how) {
// give new labels to regions
for (i = 1; i < label; i++)
if (labels[i].next->count > min_mbs_in_region && labels[labels[i].next->label].label == 0) {
if (labels[i].next->count > min_mbs_in_region &&
labels[labels[i].next->label].label == 0) {
segment_info *cs = &segments[label_count];
cs->label = label_count;
labels[labels[i].next->label].label = label_count++;
labels[labels[i].next->label].seg_value = labels[i].next->seg_value;
labels[labels[i].next->label].seg_value = labels[i].next->seg_value;
cs->seg_value = labels[labels[i].next->label].seg_value;
cs->min_x = oci->mb_cols;
cs->min_y = oci->mb_rows;
......@@ -204,24 +205,21 @@ void segment_via_mode_info(VP9_COMMON *oci, int how) {
cs->sum_x = 0;
cs->sum_y = 0;
cs->pixels = 0;
}
lp = labeling;
// this is just to gather stats...
for (i = 0; i < oci->mb_rows; i++, lp += pitch) {
for (j = 0; j < oci->mb_cols; j++) {
segment_info *cs;
int oldlab = labels[lp[j]].next->label;
int lab = labels[oldlab].label;
lp[j] = lab;
cs = &segments[lab];
cs->min_x = (j < cs->min_x ? j : cs->min_x);
cs->max_x = (j > cs->max_x ? j : cs->max_x);
cs->min_y = (i < cs->min_y ? i : cs->min_y);
cs->max_y = (i > cs->max_y ? i : cs->max_y);
const int old_lab = labels[lp[j]].next->label;
const int lab = labels[old_lab].label;
segment_info *cs = &segments[lab];
cs->min_x = MIN(cs->min_x, j);
cs->max_x = MAX(cs->max_x, j);
cs->min_y = MIN(cs->min_y, i);
cs->max_y = MAX(cs->max_y, i);
cs->sum_x += j;
cs->sum_y += i;
cs->pixels++;
......
This diff is collapsed.
......@@ -1308,9 +1308,8 @@ static void read_coef_probs(VP9D_COMP *pbi, BOOL_DECODER* const bc) {
static void update_frame_size(VP9D_COMP *pbi) {
VP9_COMMON *cm = &pbi->common;
/* our internal buffers are always multiples of 16 */
const int width = (cm->width + 15) & ~15;
const int height = (cm->height + 15) & ~15;
const int width = multiple16(cm->width);
const int height = multiple16(cm->height);
cm->mb_rows = height >> 4;
cm->mb_cols = width >> 4;
......
......@@ -326,7 +326,7 @@ static void dealloc_compressor_data(VP9_COMP *cpi) {
vpx_free(cpi->active_map);
cpi->active_map = 0;
vp9_de_alloc_frame_buffers(&cpi->common);
vp9_free_frame_buffers(&cpi->common);
vp8_yv12_de_alloc_frame_buffer(&cpi->last_frame_uf);
vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
......@@ -960,9 +960,8 @@ void vp9_alloc_compressor_data(VP9_COMP *cpi) {
static void update_frame_size(VP9_COMP *cpi) {
VP9_COMMON *cm = &cpi->common;
/* our internal buffers are always multiples of 16 */
int aligned_width = (cm->width + 15) & ~15;
int aligned_height = (cm->height + 15) & ~15;
const int aligned_width = multiple16(cm->width);
const int aligned_height = multiple16(cm->height);
cm->mb_rows = aligned_height >> 4;
cm->mb_cols = aligned_width >> 4;
......
......@@ -10,17 +10,15 @@
#ifndef VP9_VP9_IFACE_COMMON_H_
#define VP9_VP9_IFACE_COMMON_H_
static void yuvconfig2image(vpx_image_t *img,
const YV12_BUFFER_CONFIG *yv12,
void *user_priv) {
static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
void *user_priv) {
/** vpx_img_wrap() doesn't allow specifying independent strides for
* the Y, U, and V planes, nor other alignment adjustments that
* might be representable by a YV12_BUFFER_CONFIG, so we just
* initialize all the fields.*/
img->fmt = yv12->clrtype == REG_YUV ?
VPX_IMG_FMT_I420 : VPX_IMG_FMT_VPXI420;
img->fmt = yv12->clrtype == REG_YUV ? VPX_IMG_FMT_I420 : VPX_IMG_FMT_VPXI420;
img->w = yv12->y_stride;
img->h = (yv12->y_height + 2 * VP9BORDERINPIXELS + 15) & ~15;
img->h = multiple16(yv12->y_height + 2 * VP9BORDERINPIXELS);
img->d_w = yv12->y_width;
img->d_h = yv12->y_height;
img->x_chroma_shift = 1;
......@@ -40,4 +38,4 @@ static void yuvconfig2image(vpx_image_t *img,
img->self_allocd = 0;
}
#endif
#endif // VP9_VP9_IFACE_COMMON_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment