Commit 45dc597a authored by hui su's avatar hui su Committed by Hui Su

Refactor ext-intra

Miscellaneous changes. Mostly code simplification and cleanup.

Make luma max angle delta depend on block size, which is the
way it was before the nextgenv2 branch merge.

Also some fixes for compatibility of ext-intra and alt-intra.

Change-Id: I2ce869e6ba7dee765a8dc4802f5e88040db3df22
parent f0602bba
......@@ -693,13 +693,31 @@ static const TX_TYPE filter_intra_mode_to_tx_type_lookup[FILTER_INTRA_MODES] = {
#endif // CONFIG_FILTER_INTRA
#if CONFIG_EXT_INTRA
#define ANGLE_STEP 3
#define MAX_ANGLE_DELTAS 3
#define MAX_ANGLE_DELTA_UV 2
#define ANGLE_STEP_UV 4
static const uint8_t av1_angle_step_y[TX_SIZES] = {
0, 4, 3, 3,
};
static const uint8_t av1_max_angle_delta_y[TX_SIZES] = {
0, 2, 3, 3,
};
extern const int16_t dr_intra_derivative[90];
static const uint8_t mode_to_angle_map[INTRA_MODES] = {
0, 90, 180, 45, 135, 111, 157, 203, 67, 0,
};
static INLINE int av1_get_angle_step(BLOCK_SIZE sb_type, int plane) {
const TX_SIZE max_tx_size = max_txsize_lookup[sb_type];
return plane ? ANGLE_STEP_UV : av1_angle_step_y[max_tx_size];
}
static INLINE int av1_get_max_angle_delta(BLOCK_SIZE sb_type, int plane) {
const TX_SIZE max_tx_size = max_txsize_lookup[sb_type];
return plane ? MAX_ANGLE_DELTA_UV : av1_max_angle_delta_y[max_tx_size];
}
#if CONFIG_INTRA_INTERP
// Returns whether filter selection is needed for a given
// intra prediction angle.
......@@ -763,14 +781,19 @@ static INLINE TX_TYPE get_tx_type(PLANE_TYPE plane_type, const MACROBLOCKD *xd,
return filter_intra_mode_to_tx_type_lookup[filter_intra_mode];
#endif // CONFIG_FILTER_INTRA
#if CONFIG_EXT_INTRA
if (mode == DC_PRED) {
return DCT_DCT;
} else if (mode == TM_PRED) {
return ADST_ADST;
} else {
#if CONFIG_ALT_INTRA
if (mode == SMOOTH_PRED) return ADST_ADST;
#endif // CONFIG_ALT_INTRA
if (mode == DC_PRED) return DCT_DCT;
if (mode == TM_PRED) return ADST_ADST;
{
int angle = mode_to_angle_map[mode];
const int angle_step = av1_get_angle_step(mbmi->sb_type, (int)plane_type);
assert(mode == D45_PRED || mode == D63_PRED || mode == D117_PRED ||
mode == D135_PRED || mode == D153_PRED || mode == D207_PRED ||
mode == V_PRED || mode == H_PRED);
if (mbmi->sb_type >= BLOCK_8X8)
angle += mbmi->angle_delta[plane_type] * ANGLE_STEP;
angle += mbmi->angle_delta[plane_type] * angle_step;
assert(angle > 0 && angle < 270);
if (angle == 135)
return ADST_ADST;
......
......@@ -117,8 +117,9 @@ static INTRA_FILTER get_ref_intra_filter(const MB_MODE_INFO *ref_mbmi) {
}
} else {
if (av1_is_directional_mode(mode, ref_mbmi->sb_type)) {
const int angle_step = av1_get_angle_step(ref_mbmi->sb_type, 0);
int p_angle =
mode_to_angle_map[mode] + ref_mbmi->angle_delta[0] * ANGLE_STEP;
mode_to_angle_map[mode] + ref_mbmi->angle_delta[0] * angle_step;
if (av1_is_intra_filter_switchable(p_angle)) {
ref_type = ref_mbmi->intra_filter;
}
......
......@@ -450,7 +450,7 @@ static void dr_prediction_z1(uint8_t *dst, ptrdiff_t stride, int bs,
(void)left;
(void)dy;
assert(dy == 1);
assert(dx < 0);
assert(dx > 0);
#if CONFIG_INTRA_INTERP
if (filter_type != INTRA_FILTER_LINEAR) {
......@@ -466,8 +466,8 @@ static void dr_prediction_z1(uint8_t *dst, ptrdiff_t stride, int bs,
memset(src + pad_size + 2 * bs, above[2 * bs - 1],
pad_size * sizeof(above[0]));
flags[0] = 1;
x = -dx;
for (r = 0; r < bs; ++r, dst += stride, x -= dx) {
x = dx;
for (r = 0; r < bs; ++r, dst += stride, x += dx) {
base = x >> 8;
shift = x & 0xFF;
shift = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
......@@ -513,8 +513,8 @@ static void dr_prediction_z1(uint8_t *dst, ptrdiff_t stride, int bs,
}
#endif // CONFIG_INTRA_INTERP
x = -dx;
for (r = 0; r < bs; ++r, dst += stride, x -= dx) {
x = dx;
for (r = 0; r < bs; ++r, dst += stride, x += dx) {
base = x >> 8;
shift = x & 0xFF;
......@@ -598,7 +598,7 @@ static void dr_prediction_z3(uint8_t *dst, ptrdiff_t stride, int bs,
(void)dx;
assert(dx == 1);
assert(dy < 0);
assert(dy > 0);
#if CONFIG_INTRA_INTERP
if (filter_type != INTRA_FILTER_LINEAR) {
......@@ -614,8 +614,8 @@ static void dr_prediction_z3(uint8_t *dst, ptrdiff_t stride, int bs,
for (i = 0; i < pad_size; ++i)
src[4 * (i + 2 * bs + pad_size)] = left[2 * bs - 1];
flags[0] = 1;
y = -dy;
for (c = 0; c < bs; ++c, y -= dy) {
y = dy;
for (c = 0; c < bs; ++c, y += dy) {
base = y >> 8;
shift = y & 0xFF;
shift = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
......@@ -671,8 +671,8 @@ static void dr_prediction_z3(uint8_t *dst, ptrdiff_t stride, int bs,
}
#endif // CONFIG_INTRA_INTERP
y = -dy;
for (c = 0; c < bs; ++c, y -= dy) {
y = dy;
for (c = 0; c < bs; ++c, y += dy) {
base = y >> 8;
shift = y & 0xFF;
......@@ -695,7 +695,7 @@ static void dr_prediction_z3(uint8_t *dst, ptrdiff_t stride, int bs,
// If angle > 180 && angle < 270, dx = 1;
static INLINE int get_dx(int angle) {
if (angle > 0 && angle < 90) {
return -dr_intra_derivative[angle];
return dr_intra_derivative[angle];
} else if (angle > 90 && angle < 180) {
return dr_intra_derivative[180 - angle];
} else {
......@@ -712,7 +712,7 @@ static INLINE int get_dy(int angle) {
if (angle > 90 && angle < 180) {
return dr_intra_derivative[angle - 90];
} else if (angle > 180 && angle < 270) {
return -dr_intra_derivative[270 - angle];
return dr_intra_derivative[270 - angle];
} else {
// In this case, we are not really going to use dy. We may return any value.
return 1;
......@@ -1357,6 +1357,8 @@ static void build_intra_predictors_high(
const uint16_t *above_ref = ref - ref_stride;
#if CONFIG_EXT_INTRA
int p_angle = 0;
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const int angle_step = av1_get_angle_step(mbmi->sb_type, plane);
const int is_dr_mode = av1_is_directional_mode(mode, xd->mi[0]->mbmi.sb_type);
#endif // CONFIG_EXT_INTRA
#if CONFIG_FILTER_INTRA
......@@ -1375,7 +1377,7 @@ static void build_intra_predictors_high(
#if CONFIG_EXT_INTRA
if (is_dr_mode) {
p_angle = mode_to_angle_map[mode] +
xd->mi[0]->mbmi.angle_delta[plane != 0] * ANGLE_STEP;
xd->mi[0]->mbmi.angle_delta[plane != 0] * angle_step;
if (p_angle <= 90)
need_above = 1, need_left = 0, need_above_left = 1;
else if (p_angle < 180)
......@@ -1521,7 +1523,9 @@ static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
int need_above_left = extend_modes[mode] & NEED_ABOVELEFT;
#if CONFIG_EXT_INTRA
int p_angle = 0;
const int is_dr_mode = av1_is_directional_mode(mode, xd->mi[0]->mbmi.sb_type);
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
const int angle_step = av1_get_angle_step(mbmi->sb_type, plane);
const int is_dr_mode = av1_is_directional_mode(mode, mbmi->sb_type);
#endif // CONFIG_EXT_INTRA
#if CONFIG_FILTER_INTRA
const FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
......@@ -1540,7 +1544,7 @@ static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
#if CONFIG_EXT_INTRA
if (is_dr_mode) {
p_angle = mode_to_angle_map[mode] +
xd->mi[0]->mbmi.angle_delta[plane != 0] * ANGLE_STEP;
xd->mi[0]->mbmi.angle_delta[plane != 0] * angle_step;
if (p_angle <= 90)
need_above = 1, need_left = 0, need_above_left = 1;
else if (p_angle < 180)
......
......@@ -18,6 +18,9 @@
#include "av1/common/mvref_common.h"
#include "av1/common/pred_common.h"
#include "av1/common/reconinter.h"
#if CONFIG_EXT_INTRA
#include "av1/common/reconintra.h"
#endif // CONFIG_EXT_INTRA
#include "av1/common/seg_common.h"
#if CONFIG_WARPED_MOTION
#include "av1/common/warped_motion.h"
......@@ -661,11 +664,13 @@ static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
(void)cm;
if (bsize < BLOCK_8X8) return;
if (mbmi->mode != DC_PRED && mbmi->mode != TM_PRED) {
if (av1_is_directional_mode(mbmi->mode, bsize)) {
const int max_angle_delta = av1_get_max_angle_delta(mbmi->sb_type, 0);
mbmi->angle_delta[0] =
read_uniform(r, 2 * MAX_ANGLE_DELTAS + 1) - MAX_ANGLE_DELTAS;
read_uniform(r, 2 * max_angle_delta + 1) - max_angle_delta;
#if CONFIG_INTRA_INTERP
p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP;
p_angle = mode_to_angle_map[mbmi->mode] +
mbmi->angle_delta[0] * av1_get_angle_step(mbmi->sb_type, 0);
if (av1_is_intra_filter_switchable(p_angle)) {
FRAME_COUNTS *counts = xd->counts;
mbmi->intra_filter = aom_read_tree(
......@@ -677,9 +682,9 @@ static void read_intra_angle_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
#endif // CONFIG_INTRA_INTERP
}
if (mbmi->uv_mode != DC_PRED && mbmi->uv_mode != TM_PRED) {
if (av1_is_directional_mode(mbmi->uv_mode, bsize)) {
mbmi->angle_delta[1] =
read_uniform(r, 2 * MAX_ANGLE_DELTAS + 1) - MAX_ANGLE_DELTAS;
read_uniform(r, 2 * MAX_ANGLE_DELTA_UV + 1) - MAX_ANGLE_DELTA_UV;
}
}
#endif // CONFIG_EXT_INTRA
......
......@@ -36,6 +36,9 @@
#include "av1/common/odintrin.h"
#include "av1/common/pred_common.h"
#include "av1/common/reconinter.h"
#if CONFIG_EXT_INTRA
#include "av1/common/reconintra.h"
#endif // CONFIG_EXT_INTRA
#include "av1/common/seg_common.h"
#include "av1/common/tile_common.h"
......@@ -1043,11 +1046,13 @@ static void write_intra_angle_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
(void)cm;
if (bsize < BLOCK_8X8) return;
if (mbmi->mode != DC_PRED && mbmi->mode != TM_PRED) {
write_uniform(w, 2 * MAX_ANGLE_DELTAS + 1,
MAX_ANGLE_DELTAS + mbmi->angle_delta[0]);
if (av1_is_directional_mode(mbmi->mode, bsize)) {
const int max_angle_delta = av1_get_max_angle_delta(mbmi->sb_type, 0);
write_uniform(w, 2 * max_angle_delta + 1,
max_angle_delta + mbmi->angle_delta[0]);
#if CONFIG_INTRA_INTERP
p_angle = mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP;
p_angle = mode_to_angle_map[mbmi->mode] +
mbmi->angle_delta[0] * av1_get_angle_step(mbmi->sb_type, 0);
if (av1_is_intra_filter_switchable(p_angle)) {
av1_write_token(w, av1_intra_filter_tree,
cm->fc->intra_filter_probs[intra_filter_ctx],
......@@ -1056,9 +1061,9 @@ static void write_intra_angle_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
#endif // CONFIG_INTRA_INTERP
}
if (mbmi->uv_mode != DC_PRED && mbmi->uv_mode != TM_PRED) {
write_uniform(w, 2 * MAX_ANGLE_DELTAS + 1,
MAX_ANGLE_DELTAS + mbmi->angle_delta[1]);
if (av1_is_directional_mode(mbmi->uv_mode, bsize)) {
write_uniform(w, 2 * MAX_ANGLE_DELTA_UV + 1,
MAX_ANGLE_DELTA_UV + mbmi->angle_delta[1]);
}
}
#endif // CONFIG_EXT_INTRA
......
......@@ -5308,11 +5308,11 @@ static void encode_superblock(const AV1_COMP *const cpi, ThreadData *td,
#endif // CONFIG_FILTER_INTRA
#if CONFIG_EXT_INTRA
#if CONFIG_INTRA_INTERP
if (mbmi->mode != DC_PRED && mbmi->mode != TM_PRED) {
if (av1_is_directional_mode(mbmi->mode, bsize)) {
int p_angle;
const int intra_filter_ctx = av1_get_pred_context_intra_interp(xd);
p_angle =
mode_to_angle_map[mbmi->mode] + mbmi->angle_delta[0] * ANGLE_STEP;
p_angle = mode_to_angle_map[mbmi->mode] +
mbmi->angle_delta[0] * av1_get_angle_step(mbmi->sb_type, 0);
if (av1_is_intra_filter_switchable(p_angle))
++counts->intra_filter[intra_filter_ctx][mbmi->intra_filter];
}
......
This diff is collapsed.
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