michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #include "vpx_config.h" michael@0: #include "vp8_rtcd.h" michael@0: #include "quantize.h" michael@0: #include "vp8/common/reconintra4x4.h" michael@0: #include "encodemb.h" michael@0: #include "vp8/common/invtrans.h" michael@0: #include "encodeintra.h" michael@0: michael@0: michael@0: int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred) michael@0: { michael@0: michael@0: int i; michael@0: int intra_pred_var = 0; michael@0: (void) cpi; michael@0: michael@0: if (use_dc_pred) michael@0: { michael@0: x->e_mbd.mode_info_context->mbmi.mode = DC_PRED; michael@0: x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED; michael@0: x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; michael@0: michael@0: vp8_encode_intra16x16mby(x); michael@0: michael@0: vp8_inverse_transform_mby(&x->e_mbd); michael@0: } michael@0: else michael@0: { michael@0: for (i = 0; i < 16; i++) michael@0: { michael@0: x->e_mbd.block[i].bmi.as_mode = B_DC_PRED; michael@0: vp8_encode_intra4x4block(x, i); michael@0: } michael@0: } michael@0: michael@0: intra_pred_var = vp8_get_mb_ss(x->src_diff); michael@0: michael@0: return intra_pred_var; michael@0: } michael@0: michael@0: void vp8_encode_intra4x4block(MACROBLOCK *x, int ib) michael@0: { michael@0: BLOCKD *b = &x->e_mbd.block[ib]; michael@0: BLOCK *be = &x->block[ib]; michael@0: int dst_stride = x->e_mbd.dst.y_stride; michael@0: unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset; michael@0: unsigned char *Above = dst - dst_stride; michael@0: unsigned char *yleft = dst - 1; michael@0: unsigned char top_left = Above[-1]; michael@0: michael@0: vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode, michael@0: b->predictor, 16, top_left); michael@0: michael@0: vp8_subtract_b(be, b, 16); michael@0: michael@0: x->short_fdct4x4(be->src_diff, be->coeff, 32); michael@0: michael@0: x->quantize_b(be, b); michael@0: michael@0: if (*b->eob > 1) michael@0: { michael@0: vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride); michael@0: } michael@0: else michael@0: { michael@0: vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride); michael@0: } michael@0: } michael@0: michael@0: void vp8_encode_intra4x4mby(MACROBLOCK *mb) michael@0: { michael@0: int i; michael@0: michael@0: MACROBLOCKD *xd = &mb->e_mbd; michael@0: intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16); michael@0: michael@0: for (i = 0; i < 16; i++) michael@0: vp8_encode_intra4x4block(mb, i); michael@0: return; michael@0: } michael@0: michael@0: void vp8_encode_intra16x16mby(MACROBLOCK *x) michael@0: { michael@0: BLOCK *b = &x->block[0]; michael@0: MACROBLOCKD *xd = &x->e_mbd; michael@0: michael@0: vp8_build_intra_predictors_mby_s(xd, michael@0: xd->dst.y_buffer - xd->dst.y_stride, michael@0: xd->dst.y_buffer - 1, michael@0: xd->dst.y_stride, michael@0: xd->dst.y_buffer, michael@0: xd->dst.y_stride); michael@0: michael@0: vp8_subtract_mby(x->src_diff, *(b->base_src), michael@0: b->src_stride, xd->dst.y_buffer, xd->dst.y_stride); michael@0: michael@0: vp8_transform_intra_mby(x); michael@0: michael@0: vp8_quantize_mby(x); michael@0: michael@0: if (x->optimize) michael@0: vp8_optimize_mby(x); michael@0: } michael@0: michael@0: void vp8_encode_intra16x16mbuv(MACROBLOCK *x) michael@0: { michael@0: MACROBLOCKD *xd = &x->e_mbd; michael@0: michael@0: vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride, michael@0: xd->dst.v_buffer - xd->dst.uv_stride, michael@0: xd->dst.u_buffer - 1, michael@0: xd->dst.v_buffer - 1, michael@0: xd->dst.uv_stride, michael@0: xd->dst.u_buffer, xd->dst.v_buffer, michael@0: xd->dst.uv_stride); michael@0: michael@0: vp8_subtract_mbuv(x->src_diff, x->src.u_buffer, michael@0: x->src.v_buffer, x->src.uv_stride, xd->dst.u_buffer, michael@0: xd->dst.v_buffer, xd->dst.uv_stride); michael@0: michael@0: vp8_transform_mbuv(x); michael@0: michael@0: vp8_quantize_mbuv(x); michael@0: michael@0: if (x->optimize) michael@0: vp8_optimize_mbuv(x); michael@0: }