Adds support for DST1 transforms for inter blocks

Adds an additional transform in the ext_tx experiment that
is a 2d DST1-DST1 combination.

To enable use --enable-ext-tx --enable-dst1.

This needs to be later extended to combine DST1 with DCT
or ADST.

Change-Id: I6d29f1b778ef8294bcfb6a512a78fc5eda20723b
This commit is contained in:
Debargha Mukherjee
2015-07-23 13:14:39 -07:00
parent 188087202c
commit 23690fc5d1
10 changed files with 350 additions and 41 deletions

1
configure vendored
View File

@@ -304,6 +304,7 @@ EXPERIMENT_LIST="
wavelets
ext_partition
qctx_tprobs
dst1
"
CONFIG_LIST="
external_build

View File

@@ -500,6 +500,9 @@ static TX_TYPE ext_tx_to_txtype[EXT_TX_TYPES] = {
DCT_ADST,
FLIPADST_DCT,
DCT_FLIPADST,
#if CONFIG_DST1
DST_DST,
#endif
};
#if CONFIG_WAVELETS

View File

@@ -423,6 +423,39 @@ static const struct tx_probs default_tx_probs = {
};
#if CONFIG_EXT_TX
#if CONFIG_DST1
const vp9_tree_index vp9_ext_tx_tree[TREE_SIZE(EXT_TX_TYPES)] = {
-NORM, 2,
-ALT9, 4,
6, 12,
8, 10,
-ALT1, -ALT2,
-ALT3, -ALT4,
14, 16,
-ALT5, -ALT6,
-ALT7, -ALT8,
};
#if CONFIG_WAVELETS
static const vp9_prob default_ext_tx_prob[TX_SIZES][EXT_TX_TYPES - 1] = {
{ 240, 32, 128, 128, 128, 128, 128, 128, 128 },
{ 208, 32, 128, 128, 128, 128, 128, 128, 128 },
{ 176, 32, 128, 128, 128, 128, 128, 128, 128 },
{ 160, 32, 128, 128, 128, 128, 128, 128, 128 },
#if CONFIG_TX64X64
{ 160, 32, 128, 128, 128, 128, 128, 128, 128 },
#endif // CONFIG_TX64X64
};
#else
static const vp9_prob default_ext_tx_prob[3][EXT_TX_TYPES - 1] = {
{ 240, 32, 128, 128, 128, 128, 128, 128, 128 },
{ 208, 32, 128, 128, 128, 128, 128, 128, 128 },
{ 176, 32, 128, 128, 128, 128, 128, 128, 128 },
};
#endif // CONFIG_WAVELETS
#else // CONFIG_DST1
const vp9_tree_index vp9_ext_tx_tree[TREE_SIZE(EXT_TX_TYPES)] = {
-NORM, 2,
4, 10,
@@ -442,11 +475,7 @@ static const vp9_prob default_ext_tx_prob[TX_SIZES][EXT_TX_TYPES - 1] = {
{ 160, 128, 128, 128, 128, 128, 128, 128 },
#if CONFIG_TX64X64
{ 160, 128, 128, 128, 128, 128, 128, 128 },
#endif
};
const vp9_tree_index vp9_ext_tx_large_tree[TREE_SIZE(EXT_TX_TYPES_LARGE)] = {
-NORM, -ALT1,
#endif // CONFIG_TX64X64
};
#else // CONFIG_WAVELETS
static const vp9_prob default_ext_tx_prob[3][EXT_TX_TYPES - 1] = {
@@ -455,6 +484,14 @@ static const vp9_prob default_ext_tx_prob[3][EXT_TX_TYPES - 1] = {
{ 176, 128, 128, 128, 128, 128, 128, 128 },
};
#endif // CONFIG_WAVELETS
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
const vp9_tree_index vp9_ext_tx_large_tree[TREE_SIZE(EXT_TX_TYPES_LARGE)] = {
-NORM, -ALT1,
};
#endif // CONFIG_WAVELETS
#endif // CONFIG_EXT_TX
#if CONFIG_PALETTE

View File

@@ -124,8 +124,11 @@ typedef enum {
FLIPADST_FLIPADST = 6,
ADST_FLIPADST = 7,
FLIPADST_ADST = 8,
#if CONFIG_DST1
DST_DST,
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
WAVELET1_DCT_DCT = 9,
WAVELET1_DCT_DCT,
#endif // CONFIG_WAVELETS
TOTAL_TX_TYPES,
#endif // CONFIG_EXT_TX
@@ -145,6 +148,9 @@ typedef enum {
ALT6 = 6,
ALT7 = 7,
ALT8 = 8,
#if CONFIG_DST1
ALT9 = 9,
#endif // CONFIG_DST1
EXT_TX_TYPES
} EXT_TX_TYPE;
#endif // CONFIG_EXT_TX

View File

@@ -15,39 +15,173 @@
#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_idct.h"
void vp9_iwht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
/* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
0.5 shifts per pixel. */
int i;
tran_low_t output[16];
tran_high_t a1, b1, c1, d1, e1;
const tran_low_t *ip = input;
tran_low_t *op = output;
#if CONFIG_DST1
// Integers to represent double.
// The sine transform formula is: X{i} = Sum_{0<=j<N}( x_j *
// sin((i+1)*(j+1)/(N+1) * PI) ) * sqrt(2/(N+1))
// e.g. when N == 4, it is a series of sin(PI*i/5) and sqrt(2/5). Similar for
// N = 8 and 16.
// For integer calculation, we multiply 2^14.
// sin_pi_5 = sin(PI/5)*pow(2,14)
// sqrt_2_5 = sqrt(2/5)*pow(2,14)
for (i = 0; i < 4; i++) {
a1 = ip[0] >> UNIT_QUANT_SHIFT;
c1 = ip[1] >> UNIT_QUANT_SHIFT;
d1 = ip[2] >> UNIT_QUANT_SHIFT;
b1 = ip[3] >> UNIT_QUANT_SHIFT;
a1 += c1;
d1 -= b1;
e1 = (a1 - d1) >> 1;
b1 = e1 - b1;
c1 = e1 - c1;
a1 -= b1;
d1 += c1;
op[0] = WRAPLOW(a1, 8);
op[1] = WRAPLOW(b1, 8);
op[2] = WRAPLOW(c1, 8);
op[3] = WRAPLOW(d1, 8);
ip += 4;
op += 4;
// {sin(pi/5), sin(pi*2/5)}
int sinvalue_lookup_table_4[2] = { 9630, 15582 };
// {sin(pi/9), sin(pi*2/9), ..., sin(pi*4/9)}
int sinvalue_lookup_table_8[4] = { 5604, 10531, 14189, 16135 };
// {sin(pi/17), ...
int sinvalue_lookup_table_16[] = { 3011, 5919, 8625, 11038,
13075, 14666, 15759, 16314 };
void vp9_dst1d_type1(int64_t *in, int64_t *out, int N) {
int i, j;
for (i = 0; i < N; i++) {
int64_t sum = 0;
for (j = 0; j < N; j++) {
int64_t sinvalue = 0;
int idx = (i + 1) * (j + 1);
int sign = 0;
if (idx > N + 1) {
sign = idx / (N + 1);
sign = sign % 2 ? 1 : 0;
idx %= (N + 1);
}
idx = idx > N + 1 - idx ? N + 1 - idx : idx;
if (idx == 0) continue;
idx--;
if (N == 4)
sinvalue = sinvalue_lookup_table_4[idx];
else if (N == 8)
sinvalue = sinvalue_lookup_table_8[idx];
else if (N == 16)
sinvalue = sinvalue_lookup_table_16[idx];
else
assert(0 && "Invalid transform size.");
if (sign) sinvalue = -sinvalue;
sum += in[j] * sinvalue;
}
out[i] = sum;
}
}
static void idstNxN_add(const tran_low_t *input, uint8_t *output,
int stride, int N) {
const int val_2_5 = 6554;
const int val_2_9 = 3641;
const int val_2_17 = 1928;
int i, j;
int64_t *in = (int64_t *) malloc (N * sizeof(int64_t));
int64_t *inter = (int64_t *) malloc (N * sizeof(int64_t));
int64_t *mat = (int64_t *) malloc (N * N * sizeof(int64_t));
int64_t *mat2 = (int64_t *) malloc (N * N * sizeof(int64_t));
int64_t val;
// 1d dst: transform columns
for (j = 0; j < N; j++) {
for (i = 0; i < N; i++) {
in[i] = input[i * N + j];
}
vp9_dst1d_type1(in, inter, N);
for (i = 0; i < N; i++) {
mat2[i * N + j] = inter[i];
}
}
ip = output;
for (i = 0; i < 4; i++) {
a1 = ip[4 * 0];
c1 = ip[4 * 1];
// transpose
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
mat[i * N + j] = mat2[i + j * N];
switch (N) {
case 4:
val = val_2_5;
break;
case 8:
val = val_2_9;
break;
case 16:
val = val_2_17;
break;
default:
assert(0 && "Invalid transform size.");
return;
}
// 1d dst: transform rows
for (j = 0; j < N; j++) {
for (i = 0; i < N; i++) {
in[i] = mat[i * N + j];
}
vp9_dst1d_type1(in, inter, N);
for (i = 0; i < N; i++) {
int64_t tmp = inter[i];
tmp = tmp >> DCT_CONST_BITS;
tmp *= val;
mat[i*N + j] = tmp >> (2 * DCT_CONST_BITS);
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
tran_high_t tmp = mat[i * N + j];
tmp = WRAPLOW(tmp, 8);
output[i * stride + j] = clip_pixel_add(output[i * stride + j],
ROUND_POWER_OF_TWO(tmp, 3));
}
}
free(in);
free(inter);
free(mat);
free(mat2);
}
void vp9_idst4x4_add(const tran_low_t *input, uint8_t *dest, int stride) {
idstNxN_add(input, dest, stride, 4);
}
void vp9_idst8x8_add(const tran_low_t *input, uint8_t *dest, int stride) {
idstNxN_add(input, dest, stride, 8);
}
void vp9_idst16x16_add(const tran_low_t *input, uint8_t *dest, int stride) {
idstNxN_add(input, dest, stride, 16);
}
#endif // CONFIG_DST1
void vp9_iwht4x4_16_add_c(const tran_low_t *input, uint8_t *dest, int stride) {
/* 4-point reversible, orthonormal inverse Walsh-Hadamard in 3.5 adds,
0.5 shifts per pixel. */
int i;
tran_low_t output[16];
tran_high_t a1, b1, c1, d1, e1;
const tran_low_t *ip = input;
tran_low_t *op = output;
for (i = 0; i < 4; i++) {
a1 = ip[0] >> UNIT_QUANT_SHIFT;
c1 = ip[1] >> UNIT_QUANT_SHIFT;
d1 = ip[2] >> UNIT_QUANT_SHIFT;
b1 = ip[3] >> UNIT_QUANT_SHIFT;
a1 += c1;
d1 -= b1;
e1 = (a1 - d1) >> 1;
b1 = e1 - b1;
c1 = e1 - c1;
a1 -= b1;
d1 += c1;
op[0] = WRAPLOW(a1, 8);
op[1] = WRAPLOW(b1, 8);
op[2] = WRAPLOW(c1, 8);
op[3] = WRAPLOW(d1, 8);
ip += 4;
op += 4;
}
ip = output;
for (i = 0; i < 4; i++) {
a1 = ip[4 * 0];
c1 = ip[4 * 1];
d1 = ip[4 * 2];
b1 = ip[4 * 3];
a1 += c1;
@@ -322,7 +456,7 @@ static void iadst8(const tran_low_t *input, tran_low_t *output) {
if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7)) {
output[0] = output[1] = output[2] = output[3] = output[4]
= output[5] = output[6] = output[7] = 0;
= output[5] = output[6] = output[7] = 0;
return;
}
@@ -1531,6 +1665,10 @@ void vp9_iht4x4_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
if (tx_type == DCT_DCT) {
vp9_idct4x4_add(input, dest, stride, eob);
#if CONFIG_EXT_TX
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_idst4x4_add(input, dest, stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
flipud(dest, stride, 4);
vp9_iht4x4_16_add(input, dest, stride, ADST_DCT);
@@ -1562,6 +1700,10 @@ void vp9_iht8x8_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
if (tx_type == DCT_DCT) {
vp9_idct8x8_add(input, dest, stride, eob);
#if CONFIG_EXT_TX
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_idst8x8_add(input, dest, stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
flipud(dest, stride, 8);
vp9_iht8x8_64_add(input, dest, stride, ADST_DCT);
@@ -1593,6 +1735,10 @@ void vp9_iht16x16_add(TX_TYPE tx_type, const tran_low_t *input, uint8_t *dest,
if (tx_type == DCT_DCT) {
vp9_idct16x16_add(input, dest, stride, eob);
#if CONFIG_EXT_TX
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_idst16x16_add(input, dest, stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
flipud(dest, stride, 16);
vp9_iht16x16_256_add(input, dest, stride, ADST_DCT);

View File

@@ -199,11 +199,7 @@ static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
return clip_pixel_highbd(WRAPLOW(dest + trans, bd), bd);
}
#endif // CONFIG_VP9_HIGHBITDEPTH
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VP9_COMMON_VP9_IDCT_H_
#if CONFIG_TX_SKIP
void vp9_tx_identity_add_rect(const tran_low_t *input, uint8_t *dest,
int row, int col, int stride_in,
@@ -218,3 +214,16 @@ void vp9_highbd_tx_identity_add(const tran_low_t *input, uint8_t *dest,
int stride, int bs, int shift, int bd);
#endif // CONFIG_VP9_HIGHBITDEPTH
#endif // CONFIG_TX_SKIP
#if CONFIG_DST1
void vp9_dst1d_type1(int64_t *in, int64_t *out, int N);
void vp9_idst4x4_add(const tran_low_t *input, uint8_t *dest, int stride);
void vp9_idst8x8_add(const tran_low_t *input, uint8_t *dest, int stride);
void vp9_idst16x16_add(const tran_low_t *input, uint8_t *dest, int stride);
#endif
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VP9_COMMON_VP9_IDCT_H_

View File

@@ -4676,6 +4676,9 @@ const scan_order vp9_inter_scan_orders[TX_SIZES][TOTAL_TX_TYPES] = {
{default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
{default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
{default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
#if CONFIG_DST1
{default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
{default_scan_4x4, vp9_default_iscan_4x4, default_scan_4x4_neighbors},
#endif // CONFIG_WAVELETS
@@ -4689,6 +4692,9 @@ const scan_order vp9_inter_scan_orders[TX_SIZES][TOTAL_TX_TYPES] = {
{default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors},
{default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors},
{default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors},
#if CONFIG_DST1
{default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors},
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
{default_scan_8x8, vp9_default_iscan_8x8, default_scan_8x8_neighbors}
#endif // CONFIG_WAVELETS
@@ -4702,6 +4708,9 @@ const scan_order vp9_inter_scan_orders[TX_SIZES][TOTAL_TX_TYPES] = {
{default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
{default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
{default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
#if CONFIG_DST1
{default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors},
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
{default_scan_16x16, vp9_default_iscan_16x16, default_scan_16x16_neighbors}
#endif // CONFIG_WAVELETS
@@ -4715,6 +4724,9 @@ const scan_order vp9_inter_scan_orders[TX_SIZES][TOTAL_TX_TYPES] = {
{default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
{default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
{default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
#if CONFIG_DST1
{default_scan_32x32, vp9_default_iscan_32x32, default_scan_32x32_neighbors},
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
{dwtdct_scan_32x32, vp9_dwtdct_iscan_32x32, dwtdct_scan_32x32_neighbors},
#endif // CONFIG_WAVELETS
@@ -4729,6 +4741,9 @@ const scan_order vp9_inter_scan_orders[TX_SIZES][TOTAL_TX_TYPES] = {
{default_scan_64x64, vp9_default_iscan_64x64, default_scan_64x64_neighbors},
{default_scan_64x64, vp9_default_iscan_64x64, default_scan_64x64_neighbors},
{default_scan_64x64, vp9_default_iscan_64x64, default_scan_64x64_neighbors},
#if CONFIG_DST1
{default_scan_64x64, vp9_default_iscan_64x64, default_scan_64x64_neighbors},
#endif // CONFIG_DST1
#if CONFIG_WAVELETS
{dwtdct_scan_64x64, vp9_dwtdct_iscan_64x64, dwtdct_scan_64x64_neighbors},
#endif // CONFIG_WAVELETS

View File

@@ -27,6 +27,79 @@ static INLINE tran_high_t fdct_round_shift(tran_high_t input) {
return rv;
}
#if CONFIG_DST1
static void fdstNxN(const int16_t *input, tran_low_t *output,
int stride, int N) {
const int val_2_5 = 6554;
const int val_2_9 = 3641;
const int val_2_17 = 1928;
int i, j;
int64_t *in = (int64_t *) malloc (N * sizeof(int64_t));
int64_t *inter = (int64_t *) malloc (N * sizeof(int64_t));
int64_t *mat = (int64_t *) malloc (N * N * sizeof(int64_t));
int64_t *mat2 = (int64_t *) malloc (N * N * sizeof(int64_t));
int64_t val;
// 1d dst: transform columns
for (j = 0; j < N; j++) {
for (i = 0; i < N; i++) {
in[i] = input[i * stride + j];
}
vp9_dst1d_type1(in, inter, N);
for (i = 0; i < N; i++)
mat2[i * N + j] = inter[i];
}
// transpose
switch (N) {
case 4:
val = val_2_5;
break;
case 8:
val = val_2_9;
break;
case 16:
val = val_2_17;
break;
default:
return;
}
// 1d dst: transform rows
for (j = 0; j < N; j++) {
for (i = 0; i < N; i++) {
in[i] = mat[i * N + j];
}
vp9_dst1d_type1(in, inter, N);
for (i = 0; i < N; i++) {
int64_t tmp = inter[i];
tmp = tmp >> DCT_CONST_BITS;
tmp *= val;
mat[i * N + j] = tmp >> (2 * DCT_CONST_BITS - 3);
}
}
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
output[i * N + j] = WRAPLOW(mat[i * N + j], 8);
}
}
free(in);
free(inter);
free(mat);
free(mat2);
}
void vp9_fdst4x4(const int16_t *input, tran_low_t *output, int stride) {
fdstNxN(input, output, stride, 4);
}
void vp9_fdst8x8(const int16_t *input, tran_low_t *output, int stride) {
fdstNxN(input, output, stride, 8);
}
void vp9_fdst16x16(const int16_t *input, tran_low_t *output, int stride) {
fdstNxN(input, output, stride, 16);
}
#endif // CONFIG_DST1
void vp9_fdct4(const tran_low_t *input, tran_low_t *output) {
tran_high_t step[4];
tran_high_t temp1, temp2;

View File

@@ -33,6 +33,12 @@ void vp9_fdct16(const tran_low_t in[16], tran_low_t out[16]);
void vp9_fadst16(const tran_low_t *input, tran_low_t *output);
void vp9_fdct32(const tran_high_t *input, tran_high_t *output, int round);
#if CONFIG_DST1
void vp9_fdst4x4(const int16_t *input, tran_low_t *output, int stride);
void vp9_fdst8x8(const int16_t *input, tran_low_t *output, int stride);
void vp9_fdst16x16(const int16_t *input, tran_low_t *output, int stride);
#endif // CONFIG_DST1
static const transform_2d FHT_4[] = {
{ vp9_fdct4, vp9_fdct4 }, // DCT_DCT = 0
{ vp9_fadst4, vp9_fdct4 }, // ADST_DCT = 1

View File

@@ -19,6 +19,7 @@
#include "vp9/common/vp9_reconintra.h"
#include "vp9/common/vp9_systemdependent.h"
#include "vp9/encoder/vp9_dct.h"
#include "vp9/encoder/vp9_encodemb.h"
#include "vp9/encoder/vp9_quantize.h"
#include "vp9/encoder/vp9_rd.h"
@@ -612,6 +613,10 @@ static void forw_tx16x16(MACROBLOCK *x, int plane,
TX_TYPE tx_type = get_tx_type(plane, xd);
if (tx_type == DCT_DCT) {
vp9_fdct16x16(src_diff, coeff, diff_stride);
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_fdst16x16(src_diff, coeff, diff_stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
copy_flipud(src_diff, diff_stride, 16, src_diff2, 16);
vp9_fht16x16(src_diff2, coeff, 16, ADST_DCT);
@@ -640,6 +645,10 @@ static void forw_tx8x8(MACROBLOCK *x, int plane,
TX_TYPE tx_type = get_tx_type(plane, xd);
if (tx_type == DCT_DCT) {
vp9_fdct8x8(src_diff, coeff, diff_stride);
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_fdst8x8(src_diff, coeff, diff_stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
copy_flipud(src_diff, diff_stride, 8, src_diff2, 8);
vp9_fht8x8(src_diff2, coeff, 8, ADST_DCT);
@@ -668,6 +677,10 @@ static void forw_tx4x4(MACROBLOCK *x, int plane, int block,
TX_TYPE tx_type = get_tx_type_4x4(plane, xd, block);
if (tx_type == DCT_DCT) {
x->fwd_txm4x4(src_diff, coeff, diff_stride);
#if CONFIG_DST1
} else if (tx_type == DST_DST) {
vp9_fdst4x4(src_diff, coeff, diff_stride);
#endif // CONFIG_DST1
} else if (tx_type == FLIPADST_DCT) {
copy_flipud(src_diff, diff_stride, 4, src_diff2, 4);
vp9_fht4x4(src_diff2, coeff, 4, ADST_DCT);