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"
|
|
|
|
#include "vp9/common/vp9_reconintra4x4.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
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
int vp9_encode_intra(VP9_COMP *cpi, MACROBLOCK *x, int use_16x16_pred) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
|
|
|
int intra_pred_var = 0;
|
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
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_encode_intra16x16mby(x);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
x->e_mbd.block[i].bmi.as_mode.first = B_DC_PRED;
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_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
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
intra_pred_var = vp9_get_mb_ss(x->src_diff);
|
2011-06-14 12:39:06 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return intra_pred_var;
|
2011-06-14 12:39:06 +02:00
|
|
|
}
|
2011-05-20 03:37:13 +02:00
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_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];
|
2012-10-16 01:41:41 +02:00
|
|
|
TX_TYPE tx_type;
|
2011-05-20 03:37:13 +02:00
|
|
|
|
2012-10-09 22:19:15 +02:00
|
|
|
#if CONFIG_NEWBINTRAMODES
|
|
|
|
b->bmi.as_mode.context = vp9_find_bpred_context(b);
|
|
|
|
#endif
|
|
|
|
|
2013-01-14 23:37:53 +01:00
|
|
|
vp9_intra4x4_predict(b, b->bmi.as_mode.first, b->predictor);
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_subtract_b(be, b, 16);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-11-16 00:14:38 +01:00
|
|
|
tx_type = get_tx_type_4x4(&x->e_mbd, b);
|
2012-10-16 01:41:41 +02:00
|
|
|
if (tx_type != DCT_DCT) {
|
2012-10-31 17:38:51 +01:00
|
|
|
vp9_fht(be->src_diff, 32, be->coeff, tx_type, 4);
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_ht_quantize_b_4x4(be, b, tx_type);
|
2012-12-13 00:49:39 +01:00
|
|
|
vp9_ihtllm(b->dqcoeff, b->diff, 32, tx_type, 4, b->eob);
|
2012-10-22 20:55:29 +02:00
|
|
|
} else {
|
2012-10-30 22:25:33 +01:00
|
|
|
x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
|
2012-10-13 06:41:58 +02:00
|
|
|
x->quantize_b_4x4(be, b) ;
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_inverse_transform_b_4x4(&x->e_mbd, ib, 32);
|
2012-09-10 07:42:35 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_recon_b(b->predictor, 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++)
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_encode_intra4x4block(mb, i);
|
2012-07-14 00:21:29 +02:00
|
|
|
return;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra16x16mby(MACROBLOCK *x) {
|
2012-10-13 18:27:54 +02:00
|
|
|
MACROBLOCKD *xd = &x->e_mbd;
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCK *b = &x->block[0];
|
2012-10-13 18:27:54 +02:00
|
|
|
TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
|
2011-11-04 19:29:51 +01:00
|
|
|
|
2013-01-14 23:37:53 +01:00
|
|
|
vp9_build_intra_predictors_mby(xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_subtract_mby(x->src_diff, *(b->base_src), xd->predictor, b->src_stride);
|
2011-11-04 19:29:51 +01:00
|
|
|
|
2012-10-13 18:27:54 +02:00
|
|
|
if (tx_size == TX_16X16) {
|
2012-11-16 00:14:38 +01:00
|
|
|
vp9_transform_mby_16x16(x);
|
|
|
|
vp9_quantize_mby_16x16(x);
|
|
|
|
if (x->optimize)
|
|
|
|
vp9_optimize_mby_16x16(x);
|
|
|
|
vp9_inverse_transform_mby_16x16(xd);
|
2012-10-13 18:27:54 +02:00
|
|
|
} else if (tx_size == TX_8X8) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_transform_mby_8x8(x);
|
|
|
|
vp9_quantize_mby_8x8(x);
|
2012-10-13 18:27:54 +02:00
|
|
|
if (x->optimize)
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_optimize_mby_8x8(x);
|
|
|
|
vp9_inverse_transform_mby_8x8(xd);
|
2012-10-13 18:27:54 +02:00
|
|
|
} else {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_transform_mby_4x4(x);
|
|
|
|
vp9_quantize_mby_4x4(x);
|
2012-10-13 18:27:54 +02:00
|
|
|
if (x->optimize)
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_optimize_mby_4x4(x);
|
|
|
|
vp9_inverse_transform_mby_4x4(xd);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_recon_mby(xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 04:33:58 +01:00
|
|
|
void vp9_encode_intra16x16mbuv(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-01-14 23:37:53 +01:00
|
|
|
vp9_build_intra_predictors_mbuv(xd);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
|
2012-10-28 18:38:23 +01:00
|
|
|
xd->predictor, x->src.uv_stride);
|
|
|
|
|
2012-10-13 18:27:54 +02:00
|
|
|
if (tx_size == TX_4X4) {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_transform_mbuv_4x4(x);
|
|
|
|
vp9_quantize_mbuv_4x4(x);
|
2012-10-13 18:27:54 +02:00
|
|
|
if (x->optimize)
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_optimize_mbuv_4x4(x);
|
|
|
|
vp9_inverse_transform_mbuv_4x4(xd);
|
2012-10-13 18:27:54 +02:00
|
|
|
} else /* 16x16 or 8x8 */ {
|
2012-10-30 20:58:42 +01:00
|
|
|
vp9_transform_mbuv_8x8(x);
|
|
|
|
vp9_quantize_mbuv_8x8(x);
|
2012-10-13 18:27:54 +02:00
|
|
|
if (x->optimize)
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_optimize_mbuv_8x8(x);
|
|
|
|
vp9_inverse_transform_mbuv_8x8(xd);
|
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-01-14 23:37:53 +01:00
|
|
|
vp9_intra8x8_predict(b, b->bmi.as_mode.first, b->predictor);
|
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;
|
|
|
|
|
2012-11-16 00:14:38 +01:00
|
|
|
tx_type = get_tx_type_8x8(xd, &xd->block[ib]);
|
2012-10-16 01:41:41 +02:00
|
|
|
if (tx_type != DCT_DCT) {
|
2012-10-31 17:38:51 +01:00
|
|
|
vp9_fht(be->src_diff, 32, (x->block + idx)->coeff,
|
2012-10-16 01:41:41 +02:00
|
|
|
tx_type, 8);
|
|
|
|
x->quantize_b_8x8(x->block + idx, xd->block + idx);
|
2012-11-29 16:19:38 +01:00
|
|
|
vp9_ihtllm(xd->block[idx].dqcoeff, xd->block[ib].diff, 32,
|
2012-12-13 00:49:39 +01:00
|
|
|
tx_type, 8, xd->block[idx].eob);
|
2012-10-16 01:41:41 +02:00
|
|
|
} else {
|
2012-10-30 20:58:42 +01:00
|
|
|
x->vp9_short_fdct8x8(be->src_diff, (x->block + idx)->coeff, 32);
|
2012-10-16 01:41:41 +02:00
|
|
|
x->quantize_b_8x8(x->block + idx, xd->block + idx);
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_short_idct8x8(xd->block[idx].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++) {
|
|
|
|
b = &xd->block[ib + iblock[i]];
|
2012-10-11 02:18:22 +02:00
|
|
|
be = &x->block[ib + iblock[i]];
|
2012-11-16 00:14:38 +01:00
|
|
|
tx_type = get_tx_type_4x4(xd, b);
|
|
|
|
if (tx_type != DCT_DCT) {
|
|
|
|
vp9_fht_c(be->src_diff, 32, be->coeff, tx_type, 4);
|
|
|
|
vp9_ht_quantize_b_4x4(be, b, tx_type);
|
2012-12-13 00:49:39 +01:00
|
|
|
vp9_ihtllm(b->dqcoeff, b->diff, 32, tx_type, 4, b->eob);
|
2012-11-16 00:14:38 +01:00
|
|
|
} else {
|
|
|
|
x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
|
|
|
|
x->quantize_b_4x4(be, b);
|
|
|
|
vp9_inverse_transform_b_4x4(xd, ib + iblock[i], 32);
|
|
|
|
}
|
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]];
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_recon_b_c(b->predictor, 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) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i, ib;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2012-10-31 01:12:12 +01:00
|
|
|
ib = vp9_i8x8_block[i];
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_encode_intra8x8(x, ib);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|
|
|
|
|
2013-01-14 23:37:53 +01:00
|
|
|
static void encode_intra_uv4x4(MACROBLOCK *x, int ib,
|
|
|
|
int mode) {
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCKD *b = &x->e_mbd.block[ib];
|
|
|
|
BLOCK *be = &x->block[ib];
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2013-01-14 23:37:53 +01:00
|
|
|
vp9_intra_uv4x4_predict(b, mode, b->predictor);
|
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
|
|
|
|
2012-10-30 20:58:42 +01:00
|
|
|
x->vp9_short_fdct4x4(be->src_diff, be->coeff, 16);
|
2012-10-13 06:41:58 +02:00
|
|
|
x->quantize_b_4x4(be, b);
|
2012-11-25 04:33:58 +01:00
|
|
|
vp9_inverse_transform_b_4x4(&x->e_mbd, ib, 16);
|
2011-08-05 01:30:27 +02:00
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
vp9_recon_uv_b_c(b->predictor, b->diff, *(b->base_dst) + b->dst,
|
|
|
|
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-01-14 23:37:53 +01:00
|
|
|
int i, ib, mode;
|
2012-07-14 00:21:29 +02:00
|
|
|
BLOCKD *b;
|
2012-10-13 18:27:54 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
for (i = 0; i < 4; i++) {
|
2012-10-31 01:12:12 +01:00
|
|
|
ib = vp9_i8x8_block[i];
|
2012-07-14 00:21:29 +02:00
|
|
|
b = &x->e_mbd.block[ib];
|
|
|
|
mode = b->bmi.as_mode.first;
|
2013-01-14 23:37:53 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/*u */
|
2013-01-14 23:37:53 +01:00
|
|
|
encode_intra_uv4x4(x, i + 16, mode);
|
2012-07-14 00:21:29 +02:00
|
|
|
/*v */
|
2013-01-14 23:37:53 +01:00
|
|
|
encode_intra_uv4x4(x, i + 20, mode);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-08-05 01:30:27 +02:00
|
|
|
}
|