Commit af8e2648 authored by Imdad Sardharwalla's avatar Imdad Sardharwalla Committed by Debargha Mukherjee

Don't calculate chroma data in monochrome mode

Encoder: Prior to this patch, some chroma data was calculated and
later discarded when in monochrome mode. This patch ensures that
the chroma planes are left uninitialised and that chroma
calculations are not performed.

Decoder: Prior to this patch, some chroma calculations were still
being performed in monochrome mode (e.g. loop filtering). This
patch ensures that calculations are only performed on the y
plane, with the chroma planes being set to a constant.

Change-Id: I394c0c9fc50f884e76a65e6131bd6598b8b21b10
parent b08544de
......@@ -18,6 +18,6 @@ extern void aom_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
unsigned char *temp_area, unsigned char temp_height,
unsigned int hscale, unsigned int hratio,
unsigned int vscale, unsigned int vratio,
unsigned int interlaced);
unsigned int interlaced, const int num_planes);
#endif // AOM_SCALE_AOM_SCALE_H_
......@@ -26,9 +26,9 @@ if (aom_config("CONFIG_SPATIAL_RESAMPLING") eq "yes") {
add_proto qw/void aom_vertical_band_2_1_scale_i/, "unsigned char *source, int src_pitch, unsigned char *dest, int dest_pitch, unsigned int dest_width";
}
add_proto qw/void aom_yv12_extend_frame_borders/, "struct yv12_buffer_config *ybf";
add_proto qw/void aom_yv12_extend_frame_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
add_proto qw/void aom_yv12_copy_frame/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc";
add_proto qw/void aom_yv12_copy_frame/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc, const int num_planes";
add_proto qw/void aom_yv12_copy_y/, "const struct yv12_buffer_config *src_ybc, struct yv12_buffer_config *dst_ybc";
......@@ -37,10 +37,10 @@ add_proto qw/void aom_yv12_copy_u/, "const struct yv12_buffer_config *src_bc, st
add_proto qw/void aom_yv12_copy_v/, "const struct yv12_buffer_config *src_bc, struct yv12_buffer_config *dst_bc";
if (aom_config("CONFIG_AV1") eq "yes") {
add_proto qw/void aom_extend_frame_borders/, "struct yv12_buffer_config *ybf";
add_proto qw/void aom_extend_frame_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
specialize qw/aom_extend_frame_borders dspr2/;
add_proto qw/void aom_extend_frame_inner_borders/, "struct yv12_buffer_config *ybf";
add_proto qw/void aom_extend_frame_inner_borders/, "struct yv12_buffer_config *ybf, const int num_planes";
specialize qw/aom_extend_frame_inner_borders dspr2/;
add_proto qw/void aom_extend_frame_borders_y/, "struct yv12_buffer_config *ybf";
......
......@@ -475,11 +475,11 @@ void aom_scale_frame(YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
unsigned char *temp_area, unsigned char temp_height,
unsigned int hscale, unsigned int hratio,
unsigned int vscale, unsigned int vratio,
unsigned int interlaced) {
unsigned int interlaced, const int num_planes) {
const int dw = (hscale - 1 + src->y_width * hratio) / hscale;
const int dh = (vscale - 1 + src->y_height * vratio) / vscale;
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int plane_dw = dw >> is_uv;
const int plane_dh = dh >> is_uv;
......
......@@ -98,7 +98,8 @@ static void extend_plane_high(uint8_t *const src8, int src_stride, int width,
}
}
void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf,
const int num_planes) {
assert(ybf->border % 2 == 0);
assert(ybf->y_height - ybf->y_crop_height < 16);
assert(ybf->y_width - ybf->y_crop_width < 16);
......@@ -106,7 +107,7 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
assert(ybf->y_width - ybf->y_crop_width >= 0);
if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int plane_border = ybf->border >> is_uv;
extend_plane_high(
......@@ -117,7 +118,7 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
}
return;
}
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int plane_border = ybf->border >> is_uv;
extend_plane(ybf->buffers[plane], ybf->strides[is_uv],
......@@ -129,7 +130,8 @@ void aom_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
}
#if CONFIG_AV1
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size,
const int num_planes) {
const int ss_x = ybf->uv_width < ybf->y_width;
const int ss_y = ybf->uv_height < ybf->y_height;
......@@ -139,7 +141,7 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
assert(ybf->y_width - ybf->y_crop_width >= 0);
if (ybf->flags & YV12_FLAG_HIGHBITDEPTH) {
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int top = ext_size >> (is_uv ? ss_y : 0);
const int left = ext_size >> (is_uv ? ss_x : 0);
......@@ -151,7 +153,7 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
}
return;
}
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const int is_uv = plane > 0;
const int top = ext_size >> (is_uv ? ss_y : 0);
const int left = ext_size >> (is_uv ? ss_x : 0);
......@@ -163,15 +165,16 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
}
}
void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) {
extend_frame(ybf, ybf->border);
void aom_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, const int num_planes) {
extend_frame(ybf, ybf->border, num_planes);
}
void aom_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf) {
void aom_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf,
const int num_planes) {
const int inner_bw = (ybf->border > AOMINNERBORDERINPIXELS)
? AOMINNERBORDERINPIXELS
: ybf->border;
extend_frame(ybf, inner_bw);
extend_frame(ybf, inner_bw, num_planes);
}
void aom_extend_frame_borders_y_c(YV12_BUFFER_CONFIG *ybf) {
......@@ -205,7 +208,7 @@ static void memcpy_short_addr(uint8_t *dst8, const uint8_t *src8, int num) {
// destination's UMV borders.
// Note: The frames are assumed to be identical in size.
void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
YV12_BUFFER_CONFIG *dst_bc) {
YV12_BUFFER_CONFIG *dst_bc, const int num_planes) {
#if 0
/* These assertions are valid in the codec, but the libaom-tester uses
* this code slightly differently.
......@@ -218,7 +221,7 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
(dst_bc->flags & YV12_FLAG_HIGHBITDEPTH));
if (src_bc->flags & YV12_FLAG_HIGHBITDEPTH) {
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const uint8_t *plane_src = src_bc->buffers[plane];
uint8_t *plane_dst = dst_bc->buffers[plane];
const int is_uv = plane > 0;
......@@ -229,10 +232,10 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
plane_dst += dst_bc->strides[is_uv];
}
}
aom_yv12_extend_frame_borders_c(dst_bc);
aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
return;
}
for (int plane = 0; plane < 3; ++plane) {
for (int plane = 0; plane < num_planes; ++plane) {
const uint8_t *plane_src = src_bc->buffers[plane];
uint8_t *plane_dst = dst_bc->buffers[plane];
const int is_uv = plane > 0;
......@@ -243,7 +246,7 @@ void aom_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_bc,
plane_dst += dst_bc->strides[is_uv];
}
}
aom_yv12_extend_frame_borders_c(dst_bc);
aom_yv12_extend_frame_borders_c(dst_bc, num_planes);
}
void aom_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc,
......
......@@ -126,14 +126,16 @@ static void extend_frame(YV12_BUFFER_CONFIG *const ybf, int ext_size) {
extend_plane(ybf->v_buffer, ybf->uv_stride, c_w, c_h, c_et, c_el, c_eb, c_er);
}
void aom_extend_frame_borders_dspr2(YV12_BUFFER_CONFIG *ybf) {
extend_frame(ybf, ybf->border);
void aom_extend_frame_borders_dspr2(YV12_BUFFER_CONFIG *ybf,
const int num_planes) {
extend_frame(ybf, ybf->border, num_planes);
}
void aom_extend_frame_inner_borders_dspr2(YV12_BUFFER_CONFIG *ybf) {
void aom_extend_frame_inner_borders_dspr2(YV12_BUFFER_CONFIG *ybf,
const int num_planes) {
const int inner_bw = (ybf->border > AOMINNERBORDERINPIXELS)
? AOMINNERBORDERINPIXELS
: ybf->border;
extend_frame(ybf, inner_bw);
extend_frame(ybf, inner_bw, num_planes);
}
#endif
......@@ -98,8 +98,8 @@ void mismatch_move_frame_idx_w() {
}
}
void mismatch_reset_frame() {
for (int plane = 0; plane < 3; ++plane) {
void mismatch_reset_frame(int num_planes) {
for (int plane = 0; plane < num_planes; ++plane) {
memset(frame_pre[frame_buf_idx_w][plane], 0,
sizeof(frame_pre[frame_buf_idx_w][plane][0]) * frame_size);
memset(frame_tx[frame_buf_idx_w][plane], 0,
......
......@@ -46,7 +46,7 @@ void bitstream_queue_set_skip_read(int skip);
#if CONFIG_MISMATCH_DEBUG
void mismatch_move_frame_idx_w();
void mismatch_move_frame_idx_r();
void mismatch_reset_frame();
void mismatch_reset_frame(int num_planes);
void mismatch_record_block_pre(const uint8_t *src, int src_stride, int plane,
int pixel_c, int pixel_r, int blk_w, int blk_h);
void mismatch_record_block_tx(const uint8_t *src, int src_stride, int plane,
......
......@@ -886,6 +886,7 @@ static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
#if CONFIG_EXT_TILE
const int num_planes = av1_num_planes(cm);
if (cm->single_tile_decoding &&
frame_worker_data->pbi->dec_tile_row >= 0) {
const int tile_row =
......@@ -894,9 +895,11 @@ static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
const int ssy = ctx->img.y_chroma_shift;
int plane;
ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0];
for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
ctx->img.planes[plane] +=
mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
if (num_planes > 1) {
for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
ctx->img.planes[plane] +=
mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
}
}
ctx->img.d_h =
AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE;
......@@ -910,8 +913,10 @@ static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
const int ssx = ctx->img.x_chroma_shift;
int plane;
ctx->img.planes[0] += mi_col * MI_SIZE;
for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx);
if (num_planes > 1) {
for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx);
}
}
ctx->img.d_w =
AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE;
......
......@@ -109,7 +109,8 @@ void av1_free_ref_frame_buffers(BufferPool *pool) {
#if CONFIG_LOOP_RESTORATION
// Assumes cm->rst_info[p].restoration_unit_size is already initialized
void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
for (int p = 0; p < MAX_MB_PLANE; ++p)
const int num_planes = av1_num_planes(cm);
for (int p = 0; p < num_planes; ++p)
av1_alloc_restoration_struct(cm, &cm->rst_info[p], p > 0);
aom_free(cm->rst_tmpbuf);
CHECK_MEM_ERROR(cm, cm->rst_tmpbuf,
......@@ -148,7 +149,7 @@ void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
#endif // CONFIG_HORZONLY_FRAME_SUPERRES
const int use_highbd = cm->use_highbitdepth ? 1 : 0;
for (int p = 0; p < MAX_MB_PLANE; ++p) {
for (int p = 0; p < num_planes; ++p) {
const int is_uv = p > 0;
const int ss_x = is_uv && cm->subsampling_x;
const int plane_w = ((frame_w + ss_x) >> ss_x) + 2 * RESTORATION_EXTRA_HORZ;
......@@ -170,13 +171,14 @@ void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
}
void av1_free_restoration_buffers(AV1_COMMON *cm) {
const int num_planes = av1_num_planes(cm);
int p;
for (p = 0; p < MAX_MB_PLANE; ++p)
for (p = 0; p < num_planes; ++p)
av1_free_restoration_struct(&cm->rst_info[p]);
aom_free(cm->rst_tmpbuf);
cm->rst_tmpbuf = NULL;
#if CONFIG_STRIPED_LOOP_RESTORATION
for (p = 0; p < MAX_MB_PLANE; ++p) {
for (p = 0; p < num_planes; ++p) {
RestorationStripeBoundaries *boundaries = &cm->rst_info[p].boundaries;
aom_free(boundaries->stripe_boundary_above);
aom_free(boundaries->stripe_boundary_below);
......@@ -188,6 +190,7 @@ void av1_free_restoration_buffers(AV1_COMMON *cm) {
#endif // CONFIG_LOOP_RESTORATION
void av1_free_context_buffers(AV1_COMMON *cm) {
const int num_planes = av1_num_planes(cm);
int i;
cm->free_mi(cm);
......@@ -198,7 +201,7 @@ void av1_free_context_buffers(AV1_COMMON *cm) {
#if !CONFIG_SEGMENT_PRED_LAST
free_seg_map(cm);
#endif
for (i = 0; i < MAX_MB_PLANE; i++) {
for (i = 0; i < num_planes; i++) {
aom_free(cm->above_context[i]);
cm->above_context[i] = NULL;
}
......@@ -208,13 +211,14 @@ void av1_free_context_buffers(AV1_COMMON *cm) {
aom_free(cm->above_txfm_context);
cm->above_txfm_context = NULL;
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (i = 0; i < num_planes; ++i) {
aom_free(cm->top_txfm_context[i]);
cm->top_txfm_context[i] = NULL;
}
}
int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) {
const int num_planes = av1_num_planes(cm);
int new_mi_size;
av1_set_mb_mi(cm, width, height);
......@@ -250,7 +254,7 @@ int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) {
ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2);
int i;
for (i = 0; i < MAX_MB_PLANE; i++) {
for (i = 0; i < num_planes; i++) {
aom_free(cm->above_context[i]);
cm->above_context[i] = (ENTROPY_CONTEXT *)aom_calloc(
aligned_mi_cols << (MI_SIZE_LOG2 - tx_size_wide_log2[0]),
......@@ -268,7 +272,7 @@ int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) {
aligned_mi_cols << TX_UNIT_WIDE_LOG2, sizeof(*cm->above_txfm_context));
if (!cm->above_txfm_context) goto fail;
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (i = 0; i < num_planes; ++i) {
aom_free(cm->top_txfm_context[i]);
cm->top_txfm_context[i] =
(TXFM_CONTEXT *)aom_calloc(aligned_mi_cols << TX_UNIT_WIDE_LOG2,
......
......@@ -2394,6 +2394,7 @@ static void av1_filter_block_plane_horz(
void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
struct macroblockd_plane *planes, int start, int stop,
int y_only) {
const int num_planes = av1_num_planes(cm);
#if CONFIG_LOOPFILTER_LEVEL
// y_only no longer has its original meaning.
// Here it means which plane to filter
......@@ -2402,9 +2403,9 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
const int plane_start = y_only;
const int plane_end = plane_start + 1;
#else
const int num_planes = y_only ? 1 : MAX_MB_PLANE;
const int nplanes = y_only ? 1 : num_planes;
const int plane_start = 0;
const int plane_end = num_planes;
const int plane_end = nplanes;
#endif // CONFIG_LOOPFILTER_LEVEL
#if CONFIG_PARALLEL_DEBLOCKING
const int col_start = 0;
......@@ -2414,11 +2415,11 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
int plane;
#if !CONFIG_PARALLEL_DEBLOCKING
for (int i = 0; i < MAX_MB_PLANE; ++i)
for (int i = 0; i < nplanes; ++i)
memset(cm->top_txfm_context[i], TX_32X32, cm->mi_cols << TX_UNIT_WIDE_LOG2);
for (mi_row = start; mi_row < stop; mi_row += cm->mib_size) {
MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
for (int i = 0; i < MAX_MB_PLANE; ++i)
for (int i = 0; i < nplanes; ++i)
memset(cm->left_txfm_context[i], TX_32X32,
MAX_MIB_SIZE << TX_UNIT_HIGH_LOG2);
for (mi_col = 0; mi_col < cm->mi_cols; mi_col += cm->mib_size) {
......@@ -2437,7 +2438,8 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
// filter all vertical edges in every 64x64 super block
for (mi_row = start; mi_row < stop; mi_row += MAX_MIB_SIZE) {
for (mi_col = col_start; mi_col < col_end; mi_col += MAX_MIB_SIZE) {
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col,
num_planes);
for (plane = plane_start; plane < plane_end; ++plane) {
av1_filter_block_plane_vert(cm, plane, &planes[plane], mi_row, mi_col);
}
......@@ -2447,7 +2449,8 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
// filter all horizontal edges in every 64x64 super block
for (mi_row = start; mi_row < stop; mi_row += MAX_MIB_SIZE) {
for (mi_col = col_start; mi_col < col_end; mi_col += MAX_MIB_SIZE) {
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col,
num_planes);
for (plane = plane_start; plane < plane_end; ++plane) {
av1_filter_block_plane_horz(cm, plane, &planes[plane], mi_row, mi_col);
}
......
......@@ -85,10 +85,8 @@ void av1_foreach_transformed_block_in_plane(
void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col,
foreach_transformed_block_visitor visit,
void *arg) {
int plane;
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
void *arg, const int num_planes) {
for (int plane = 0; plane < num_planes; ++plane) {
if (!is_chroma_reference(mi_row, mi_col, bsize,
xd->plane[plane].subsampling_x,
xd->plane[plane].subsampling_y))
......@@ -136,14 +134,14 @@ void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
}
}
void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
BLOCK_SIZE bsize) {
BLOCK_SIZE bsize, const int num_planes) {
int i;
int nplanes;
int chroma_ref;
chroma_ref =
is_chroma_reference(mi_row, mi_col, bsize, xd->plane[1].subsampling_x,
xd->plane[1].subsampling_y);
nplanes = 1 + (MAX_MB_PLANE - 1) * chroma_ref;
nplanes = 1 + (num_planes - 1) * chroma_ref;
for (i = 0; i < nplanes; i++) {
struct macroblockd_plane *const pd = &xd->plane[i];
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
......@@ -155,18 +153,19 @@ void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
}
#if CONFIG_LOOP_RESTORATION
void av1_reset_loop_restoration(MACROBLOCKD *xd) {
for (int p = 0; p < MAX_MB_PLANE; ++p) {
void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes) {
for (int p = 0; p < num_planes; ++p) {
set_default_wiener(xd->wiener_info + p);
set_default_sgrproj(xd->sgrproj_info + p);
}
}
#endif // CONFIG_LOOP_RESTORATION
void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y) {
void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y,
const int num_planes) {
int i;
for (i = 0; i < MAX_MB_PLANE; i++) {
for (i = 0; i < num_planes; i++) {
xd->plane[i].plane_type = get_plane_type(i);
xd->plane[i].subsampling_x = i ? ss_x : 0;
xd->plane[i].subsampling_y = i ? ss_y : 0;
......
......@@ -990,7 +990,8 @@ static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
return intra_type;
}
void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y,
const int num_planes);
static INLINE int bsize_to_max_depth(BLOCK_SIZE bsize, int is_inter) {
TX_SIZE tx_size = get_max_rect_tx_size(bsize, is_inter);
......@@ -1055,10 +1056,10 @@ static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
}
void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
BLOCK_SIZE bsize);
BLOCK_SIZE bsize, const int num_planes);
#if CONFIG_LOOP_RESTORATION
void av1_reset_loop_restoration(MACROBLOCKD *xd);
void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes);
#endif // CONFIG_LOOP_RESTORATION
typedef void (*foreach_transformed_block_visitor)(int plane, int block,
......@@ -1074,7 +1075,7 @@ void av1_foreach_transformed_block_in_plane(
void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col,
foreach_transformed_block_visitor visit,
void *arg);
void *arg, const int num_planes);
#endif
void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
......
......@@ -150,6 +150,7 @@ static INLINE void copy_rect(uint16_t *dst, int dstride, const uint16_t *src,
void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
MACROBLOCKD *xd) {
const int num_planes = av1_num_planes(cm);
DECLARE_ALIGNED(16, uint16_t, src[CDEF_INBUF_SIZE]);
uint16_t *linebuf[3];
uint16_t *colbuf[3];
......@@ -163,22 +164,21 @@ void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
int xdec[3];
int ydec[3];
int coeff_shift = AOMMAX(cm->bit_depth - 8, 0);
int nplanes = av1_num_planes(cm);
const int nvfb = (cm->mi_rows + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
const int nhfb = (cm->mi_cols + MI_SIZE_64X64 - 1) / MI_SIZE_64X64;
av1_setup_dst_planes(xd->plane, cm->sb_size, frame, 0, 0);
av1_setup_dst_planes(xd->plane, cm->sb_size, frame, 0, 0, num_planes);
row_cdef = aom_malloc(sizeof(*row_cdef) * (nhfb + 2) * 2);
memset(row_cdef, 1, sizeof(*row_cdef) * (nhfb + 2) * 2);
prev_row_cdef = row_cdef + 1;
curr_row_cdef = prev_row_cdef + nhfb + 2;
for (int pli = 0; pli < nplanes; pli++) {
for (int pli = 0; pli < num_planes; pli++) {
xdec[pli] = xd->plane[pli].subsampling_x;
ydec[pli] = xd->plane[pli].subsampling_y;
mi_wide_l2[pli] = MI_SIZE_LOG2 - xd->plane[pli].subsampling_x;
mi_high_l2[pli] = MI_SIZE_LOG2 - xd->plane[pli].subsampling_y;
}
const int stride = (cm->mi_cols << MI_SIZE_LOG2) + 2 * CDEF_HBORDER;
for (int pli = 0; pli < nplanes; pli++) {
for (int pli = 0; pli < num_planes; pli++) {
linebuf[pli] = aom_malloc(sizeof(*linebuf) * CDEF_VBORDER * stride);
colbuf[pli] =
aom_malloc(sizeof(*colbuf) *
......@@ -186,7 +186,7 @@ void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
CDEF_HBORDER);
}
for (int fbr = 0; fbr < nvfb; fbr++) {
for (int pli = 0; pli < nplanes; pli++) {
for (int pli = 0; pli < num_planes; pli++) {
const int block_height =
(MI_SIZE_64X64 << mi_high_l2[pli]) + 2 * CDEF_VBORDER;
fill_rect(colbuf[pli], CDEF_HBORDER, block_height, CDEF_HBORDER,
......@@ -276,7 +276,7 @@ void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
}
curr_row_cdef[fbc] = 1;
for (int pli = 0; pli < nplanes; pli++) {
for (int pli = 0; pli < num_planes; pli++) {
int coffset;
int rend, cend;
int pri_damping = cm->cdef_pri_damping;
......@@ -423,7 +423,7 @@ void av1_cdef_frame(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
}
}
aom_free(row_cdef);
for (int pli = 0; pli < nplanes; pli++) {
for (int pli = 0; pli < num_planes; pli++) {
aom_free(linebuf[pli]);
aom_free(colbuf[pli]);
}
......
......@@ -14,13 +14,14 @@
typedef void (*overlappable_nb_visitor_t)(MACROBLOCKD *xd, int rel_mi_pos,
uint8_t nb_mi_size, MODE_INFO *nb_mi,
void *fun_ctxt);
void *fun_ctxt, const int num_planes);
static INLINE void foreach_overlappable_nb_above(const AV1_COMMON *cm,
MACROBLOCKD *xd, int mi_col,
int nb_max,
overlappable_nb_visitor_t fun,
void *fun_ctxt) {
const int num_planes = av1_num_planes(cm);
if (!xd->up_available) return;
int nb_count = 0;
......@@ -49,7 +50,7 @@ static INLINE void foreach_overlappable_nb_above(const AV1_COMMON *cm,
if (is_neighbor_overlappable(above_mbmi)) {
++nb_count;
fun(xd, above_mi_col - mi_col, AOMMIN(xd->n8_w, mi_step), *above_mi,
fun_ctxt);
fun_ctxt, num_planes);
}
}
}
......@@ -59,6 +60,7 @@ static INLINE void foreach_overlappable_nb_left(const AV1_COMMON *cm,
int nb_max,
overlappable_nb_visitor_t fun,
void *fun_ctxt) {
const int num_planes = av1_num_planes(cm);
if (!xd->left_available) return;
int nb_count = 0;
......@@ -82,7 +84,7 @@ static INLINE void foreach_overlappable_nb_left(const AV1_COMMON *cm,
if (is_neighbor_overlappable(left_mbmi)) {
++nb_count;
fun(xd, left_mi_row - mi_row, AOMMIN(xd->n8_h, mi_step), *left_mi,
fun_ctxt);
fun_ctxt, num_planes);
}
}
}
......
......@@ -757,7 +757,8 @@ static INLINE int av1_num_planes(const AV1_COMMON *cm) {
static INLINE void av1_init_macroblockd(AV1_COMMON *cm, MACROBLOCKD *xd,
tran_low_t *dqcoeff) {
for (int i = 0; i < MAX_MB_PLANE; ++i) {
const int num_planes = av1_num_planes(cm);
for (int i = 0; i < num_planes; ++i) {
xd->plane[i].dqcoeff = dqcoeff;
xd->above_context[i] = cm->above_context[i];
if (xd->plane[i].plane_type == PLANE_TYPE_Y) {
......@@ -807,11 +808,12 @@ static INLINE void av1_init_macroblockd(AV1_COMMON *cm, MACROBLOCKD *xd,
#endif
}
static INLINE void set_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col) {
static INLINE void set_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
const int num_planes) {
int i;
int row_offset = mi_row;
int col_offset = mi_col;
for (i = 0; i < MAX_MB_PLANE; ++i) {
for (i = 0; i < num_planes; ++i) {
struct macroblockd_plane *const pd = &xd->plane[i];
// Offset the buffer pointer
const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
......@@ -832,9 +834,10 @@ static INLINE int calc_mi_size(int len) {
return len + MAX_MIB_SIZE;
}
static INLINE void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh) {
static INLINE void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh,
const int num_planes) {
int i;
for (i = 0; i < MAX_MB_PLANE; i++) {
for (i = 0; i < num_planes; i++) {
xd->plane[i].width = (bw * MI_SIZE) >> xd->plane[i].subsampling_x;
xd->plane[i].height = (bh * MI_SIZE) >> xd->plane[i].subsampling_y;
......@@ -1160,6 +1163,7 @@ static INLINE int max_intra_block_height(const MACROBLOCKD *xd,
static INLINE void av1_zero_above_context(AV1_COMMON *const cm,
int mi_col_start, int mi_col_end) {
const int num_planes = av1_num_planes(cm);
const int width = mi_col_end - mi_col_start;
const int aligned_width = ALIGN_POWER_OF_TWO(width, cm->mib_size_log2);
......@@ -1169,8 +1173,10 @@ static INLINE void av1_zero_above_context(AV1_COMMON *const cm,