2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "vpx_config.h"
13 #include "./vpx_dsp_rtcd.h"
14 #include "vp8/encoder/quantize.h"
15 #include "vp8/common/reconintra.h"
16 #include "vp8/common/reconintra4x4.h"
18 #include "vp8/common/invtrans.h"
19 #include "encodeintra.h"
21 int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred) {
23 int intra_pred_var = 0;
27 x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
28 x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
29 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
31 vp8_encode_intra16x16mby(x);
33 vp8_inverse_transform_mby(&x->e_mbd);
35 for (i = 0; i < 16; ++i) {
36 x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
37 vp8_encode_intra4x4block(x, i);
41 intra_pred_var = vpx_get_mb_ss(x->src_diff);
43 return intra_pred_var;
46 void vp8_encode_intra4x4block(MACROBLOCK *x, int ib) {
47 BLOCKD *b = &x->e_mbd.block[ib];
48 BLOCK *be = &x->block[ib];
49 int dst_stride = x->e_mbd.dst.y_stride;
50 unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
51 unsigned char *Above = dst - dst_stride;
52 unsigned char *yleft = dst - 1;
53 unsigned char top_left = Above[-1];
55 vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode, b->predictor,
58 vp8_subtract_b(be, b, 16);
60 x->short_fdct4x4(be->src_diff, be->coeff, 32);
65 vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride);
67 vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride);
71 void vp8_encode_intra4x4mby(MACROBLOCK *mb) {
74 MACROBLOCKD *xd = &mb->e_mbd;
75 intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
77 for (i = 0; i < 16; ++i) vp8_encode_intra4x4block(mb, i);
81 void vp8_encode_intra16x16mby(MACROBLOCK *x) {
82 BLOCK *b = &x->block[0];
83 MACROBLOCKD *xd = &x->e_mbd;
85 vp8_build_intra_predictors_mby_s(xd, xd->dst.y_buffer - xd->dst.y_stride,
86 xd->dst.y_buffer - 1, xd->dst.y_stride,
87 xd->dst.y_buffer, xd->dst.y_stride);
89 vp8_subtract_mby(x->src_diff, *(b->base_src), b->src_stride, xd->dst.y_buffer,
92 vp8_transform_intra_mby(x);
96 if (x->optimize) vp8_optimize_mby(x);
99 void vp8_encode_intra16x16mbuv(MACROBLOCK *x) {
100 MACROBLOCKD *xd = &x->e_mbd;
102 vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride,
103 xd->dst.v_buffer - xd->dst.uv_stride,
104 xd->dst.u_buffer - 1, xd->dst.v_buffer - 1,
105 xd->dst.uv_stride, xd->dst.u_buffer,
106 xd->dst.v_buffer, xd->dst.uv_stride);
108 vp8_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
109 x->src.uv_stride, xd->dst.u_buffer, xd->dst.v_buffer,
112 vp8_transform_mbuv(x);
114 vp8_quantize_mbuv(x);
116 if (x->optimize) vp8_optimize_mbuv(x);