2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
2012-12-23 16:20:10 +01:00
|
|
|
#include "./vpx_config.h"
|
2012-11-09 02:09:30 +01:00
|
|
|
#include "vp9_rtcd.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_quantize.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_reconintra.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_encodemb.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_invtrans.h"
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/encoder/vp9_encodeintra.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-02 23:50:40 +02:00
|
|
|
static void encode_intra4x4block(MACROBLOCK *x, int ib);
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_encode_intra(VP9_COMP *cpi, MACROBLOCK *x, int use_16x16_pred) {
|
2012-08-10 15:12:43 +02:00
|
|
|
MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
|
2012-07-14 00:21:29 +02:00
|
|
|
(void) cpi;
|
2011-06-14 12:39:06 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (use_16x16_pred) {
|
2012-08-10 15:12:43 +02:00
|
|
|
mbmi->mode = DC_PRED;
|
|
|
|
mbmi->uv_mode = DC_PRED;
|
|
|
|
mbmi->ref_frame = INTRA_FRAME;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-02-20 19:16:24 +01:00
|
|
|
vp9_encode_intra16x16mby(&cpi->common, x);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
2013-02-28 22:18:02 +01:00
|
|
|
int i;
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
x->e_mbd.block[i].bmi.as_mode.first = B_DC_PRED;
|
2013-04-02 23:50:40 +02:00
|
|
|
encode_intra4x4block(x, i);
|
2011-06-14 12:39:06 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-06-14 12:39:06 +02:00
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
return vp9_get_mb_ss(x->src_diff);
|
2011-06-14 12:39:06 +02:00
|
|
|
}
|
2011-05-20 03:37:13 +02:00
|
|
|
|
2013-04-02 23:50:40 +02:00
|
|
|
static void encode_intra4x4block(MACROBLOCK *x, int ib) {
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCKD *b = &x->e_mbd.block[ib];
|
|
|
|
BLOCK *be = &x->block[ib];
|
2013-04-02 23:50:40 +02:00
|
|
|
MACROBLOCKD * const xd = &x->e_mbd;
|
2012-10-16 01:41:41 +02:00
|
|
|
TX_TYPE tx_type;
|
2011-05-20 03:37:13 +02:00
|
|
|
|
2013-04-02 23:50:40 +02:00
|
|
|
assert(ib < 16);
|
|
|
|
|
2012-10-09 22:19:15 +02:00
|
|
|
#if CONFIG_NEWBINTRAMODES
|
2013-03-16 17:26:52 +01:00
|
|
|
b->bmi.as_mode.context = vp9_find_bpred_context(&x->e_mbd, b);
|
2012-10-09 22:19:15 +02:00
|
|
|
#endif
|
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_intra4x4_predict(&x->e_mbd, b, b->bmi.as_mode.first,
|
|
|
|
*(b->base_dst) + b->dst, b->dst_stride);
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_subtract_b(be, b, 16);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-03-06 00:18:06 +01:00
|
|
|
tx_type = get_tx_type_4x4(&x->e_mbd, ib);
|
2012-10-16 01:41:41 +02:00
|
|
|
if (tx_type != DCT_DCT) {
|
2013-02-26 03:19:55 +01:00
|
|
|
vp9_short_fht4x4(be->src_diff, be->coeff, 16, tx_type);
|
2013-02-27 19:00:24 +01:00
|
|
|
vp9_ht_quantize_b_4x4(x, ib, tx_type);
|
2013-04-02 23:50:40 +02:00
|
|
|
vp9_short_iht4x4(BLOCK_OFFSET(xd->plane[0].dqcoeff, ib, 16),
|
|
|
|
b->diff, 16, tx_type);
|
2012-10-22 20:55:29 +02:00
|
|
|
} else {
|
2013-02-12 06:14:46 +01:00
|
|
|
x->fwd_txm4x4(be->src_diff, be->coeff, 32);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_4x4(x, ib, 16);
|
|
|
|
vp9_inverse_transform_b_4x4(&x->e_mbd, xd->plane[0].eobs[ib],
|
2013-04-02 23:50:40 +02:00
|
|
|
BLOCK_OFFSET(xd->plane[0].dqcoeff, ib, 16),
|
|
|
|
b->diff, 32);
|
2012-09-10 07:42:35 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_recon_b(*(b->base_dst) + b->dst, b->diff,
|
|
|
|
*(b->base_dst) + b->dst, b->dst_stride);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra4x4mby(MACROBLOCK *mb) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 16; i++)
|
2013-04-02 23:50:40 +02:00
|
|
|
encode_intra4x4block(mb, i);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-02-20 19:16:24 +01:00
|
|
|
void vp9_encode_intra16x16mby(VP9_COMMON *const cm, MACROBLOCK *x) {
|
2012-10-13 18:27:54 +02:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
|
2011-11-04 19:29:51 +01:00
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_build_intra_predictors_sby_s(xd, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_subtract_sby_s_c(x->src_diff,
|
|
|
|
x->src.y_buffer, x->src.y_stride,
|
|
|
|
xd->dst.y_buffer, xd->dst.y_stride,
|
|
|
|
BLOCK_SIZE_MB16X16);
|
2011-11-04 19:29:51 +01:00
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
switch (tx_size) {
|
|
|
|
case TX_16X16:
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_transform_sby_16x16(x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_quantize_sby_16x16(x, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
if (x->optimize)
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_optimize_sby_16x16(cm, x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_inverse_transform_sby_16x16(xd, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
break;
|
|
|
|
case TX_8X8:
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_transform_sby_8x8(x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_quantize_sby_8x8(x, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
if (x->optimize)
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_optimize_sby_8x8(cm, x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_inverse_transform_sby_8x8(xd, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_transform_sby_4x4(x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_quantize_sby_4x4(x, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
if (x->optimize)
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_optimize_sby_4x4(cm, x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_inverse_transform_sby_4x4(xd, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
break;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 21:12:00 +02:00
|
|
|
vp9_recon_sby(xd, BLOCK_SIZE_MB16X16);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-02-20 19:16:24 +01:00
|
|
|
void vp9_encode_intra16x16mbuv(VP9_COMMON *const cm, MACROBLOCK *x) {
|
2012-10-13 18:27:54 +02:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
|
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_build_intra_predictors_sbuv_s(xd, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_subtract_sbuv_s_c(x->src_diff,
|
|
|
|
x->src.u_buffer, x->src.v_buffer, x->src.uv_stride,
|
|
|
|
xd->dst.u_buffer, xd->dst.v_buffer, xd->dst.uv_stride,
|
|
|
|
BLOCK_SIZE_MB16X16);
|
2012-10-28 18:38:23 +01:00
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
switch (tx_size) {
|
|
|
|
case TX_4X4:
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_transform_sbuv_4x4(x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_quantize_sbuv_4x4(x, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
if (x->optimize)
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_optimize_sbuv_4x4(cm, x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_inverse_transform_sbuv_4x4(xd, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
break;
|
|
|
|
default: // 16x16 or 8x8
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_transform_sbuv_8x8(x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_quantize_sbuv_8x8(x, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
if (x->optimize)
|
2013-04-11 19:57:16 +02:00
|
|
|
vp9_optimize_sbuv_8x8(cm, x, BLOCK_SIZE_MB16X16);
|
|
|
|
vp9_inverse_transform_sbuv_8x8(xd, BLOCK_SIZE_MB16X16);
|
2013-02-28 22:18:02 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_recon_intra_mbuv(xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra8x8(MACROBLOCK *x, int ib) {
|
2012-10-11 02:18:22 +02:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
|
|
|
BLOCKD *b = &xd->block[ib];
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCK *be = &x->block[ib];
|
|
|
|
const int iblock[4] = {0, 1, 4, 5};
|
|
|
|
int i;
|
2012-10-16 01:41:41 +02:00
|
|
|
TX_TYPE tx_type;
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_intra8x8_predict(xd, b, b->bmi.as_mode.first,
|
|
|
|
*(b->base_dst) + b->dst, b->dst_stride);
|
2012-11-16 00:14:38 +01:00
|
|
|
// generate residual blocks
|
|
|
|
vp9_subtract_4b_c(be, b, 16);
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2012-10-13 18:27:54 +02:00
|
|
|
if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) {
|
2012-08-01 19:18:25 +02:00
|
|
|
int idx = (ib & 0x02) ? (ib + 2) : ib;
|
2013-04-02 23:50:40 +02:00
|
|
|
int16_t * const dqcoeff = BLOCK_OFFSET(xd->plane[0].dqcoeff, idx, 16);
|
2012-08-01 19:18:25 +02:00
|
|
|
|
2013-04-02 23:50:40 +02:00
|
|
|
assert(idx < 16);
|
2013-03-06 00:18:06 +01:00
|
|
|
tx_type = get_tx_type_8x8(xd, ib);
|
2012-10-16 01:41:41 +02:00
|
|
|
if (tx_type != DCT_DCT) {
|
2013-02-26 03:19:55 +01:00
|
|
|
vp9_short_fht8x8(be->src_diff, (x->block + idx)->coeff, 16, tx_type);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_8x8(x, idx, tx_type, 16);
|
2013-04-02 23:50:40 +02:00
|
|
|
vp9_short_iht8x8(dqcoeff, xd->block[ib].diff,
|
2013-02-26 03:19:55 +01:00
|
|
|
16, tx_type);
|
2012-10-16 01:41:41 +02:00
|
|
|
} else {
|
2013-02-12 06:14:46 +01:00
|
|
|
x->fwd_txm8x8(be->src_diff, (x->block + idx)->coeff, 32);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_8x8(x, idx, DCT_DCT, 16);
|
2013-04-02 23:50:40 +02:00
|
|
|
vp9_short_idct8x8(dqcoeff, xd->block[ib].diff, 32);
|
2012-10-16 01:41:41 +02:00
|
|
|
}
|
2012-10-11 02:18:22 +02:00
|
|
|
} else {
|
2012-08-01 19:18:25 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
2013-04-02 23:50:40 +02:00
|
|
|
int idx = ib + iblock[i];
|
|
|
|
int16_t * const dqcoeff = BLOCK_OFFSET(xd->plane[0].dqcoeff, idx, 16);
|
|
|
|
|
|
|
|
assert(idx < 16);
|
2012-08-01 19:18:25 +02:00
|
|
|
b = &xd->block[ib + iblock[i]];
|
2012-10-11 02:18:22 +02:00
|
|
|
be = &x->block[ib + iblock[i]];
|
2013-03-06 00:18:06 +01:00
|
|
|
tx_type = get_tx_type_4x4(xd, ib + iblock[i]);
|
2012-11-16 00:14:38 +01:00
|
|
|
if (tx_type != DCT_DCT) {
|
2013-02-26 03:19:55 +01:00
|
|
|
vp9_short_fht4x4(be->src_diff, be->coeff, 16, tx_type);
|
2013-02-27 19:00:24 +01:00
|
|
|
vp9_ht_quantize_b_4x4(x, ib + iblock[i], tx_type);
|
2013-04-02 23:50:40 +02:00
|
|
|
vp9_short_iht4x4(dqcoeff, b->diff, 16, tx_type);
|
2013-03-06 00:18:06 +01:00
|
|
|
} else if (!(i & 1) &&
|
|
|
|
get_tx_type_4x4(xd, ib + iblock[i] + 1) == DCT_DCT) {
|
2013-02-12 06:14:46 +01:00
|
|
|
x->fwd_txm8x4(be->src_diff, be->coeff, 32);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_4x4_pair(x, ib + iblock[i], ib + iblock[i] + 1, 16);
|
|
|
|
vp9_inverse_transform_b_4x4(xd, xd->plane[0].eobs[ib + iblock[i]],
|
2013-04-02 23:50:40 +02:00
|
|
|
dqcoeff, b->diff, 32);
|
2013-04-04 21:03:27 +02:00
|
|
|
vp9_inverse_transform_b_4x4(xd, xd->plane[0].eobs[ib + iblock[i] + 1],
|
2013-04-02 23:50:40 +02:00
|
|
|
dqcoeff + 16, (b + 1)->diff, 32);
|
2013-02-06 23:13:05 +01:00
|
|
|
i++;
|
2012-11-16 00:14:38 +01:00
|
|
|
} else {
|
2013-02-12 06:14:46 +01:00
|
|
|
x->fwd_txm4x4(be->src_diff, be->coeff, 32);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_4x4(x, ib + iblock[i], 16);
|
|
|
|
vp9_inverse_transform_b_4x4(xd, xd->plane[0].eobs[ib + iblock[i]],
|
2013-04-02 23:50:40 +02:00
|
|
|
dqcoeff, b->diff, 32);
|
2012-11-16 00:14:38 +01:00
|
|
|
}
|
2012-08-01 19:18:25 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-11 02:18:22 +02:00
|
|
|
|
|
|
|
// reconstruct submacroblock
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
b = &xd->block[ib + iblock[i]];
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_recon_b_c(*(b->base_dst) + b->dst, b->diff, *(b->base_dst) + b->dst,
|
2012-10-11 02:18:22 +02:00
|
|
|
b->dst_stride);
|
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra8x8mby(MACROBLOCK *x) {
|
2013-02-28 22:18:02 +01:00
|
|
|
int i;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
vp9_encode_intra8x8(x, vp9_i8x8_block[i]);
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
static void encode_intra_uv4x4(MACROBLOCK *x, int ib, int mode) {
|
2013-04-02 23:50:40 +02:00
|
|
|
MACROBLOCKD * const xd = &x->e_mbd;
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCKD *b = &x->e_mbd.block[ib];
|
|
|
|
BLOCK *be = &x->block[ib];
|
2013-04-02 23:50:40 +02:00
|
|
|
int16_t * const dqcoeff = MB_SUBBLOCK_FIELD(xd, dqcoeff, ib);
|
2013-04-04 21:03:27 +02:00
|
|
|
const int plane = ib < 20 ? 1 : 2;
|
|
|
|
const int block = ib < 20 ? ib - 16 : ib - 20;
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2013-04-02 23:50:40 +02:00
|
|
|
assert(ib >= 16 && ib < 24);
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_intra_uv4x4_predict(&x->e_mbd, b, mode,
|
|
|
|
*(b->base_dst) + b->dst, b->dst_stride);
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_subtract_b(be, b, 8);
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2013-02-12 06:14:46 +01:00
|
|
|
x->fwd_txm4x4(be->src_diff, be->coeff, 16);
|
2013-04-04 21:03:27 +02:00
|
|
|
x->quantize_b_4x4(x, ib, 16);
|
|
|
|
vp9_inverse_transform_b_4x4(&x->e_mbd, xd->plane[plane].eobs[block],
|
2013-04-02 23:50:40 +02:00
|
|
|
dqcoeff, b->diff, 16);
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2013-04-15 18:31:27 +02:00
|
|
|
vp9_recon_uv_b_c(*(b->base_dst) + b->dst, b->diff, *(b->base_dst) + b->dst,
|
2012-11-01 00:09:17 +01:00
|
|
|
b->dst_stride);
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra8x8mbuv(MACROBLOCK *x) {
|
2013-02-28 22:18:02 +01:00
|
|
|
int i;
|
2012-10-13 18:27:54 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
2013-02-28 22:18:02 +01:00
|
|
|
BLOCKD *b = &x->e_mbd.block[vp9_i8x8_block[i]];
|
|
|
|
int mode = b->bmi.as_mode.first;
|
|
|
|
|
|
|
|
encode_intra_uv4x4(x, i + 16, mode); // u
|
|
|
|
encode_intra_uv4x4(x, i + 20, mode); // v
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|