1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
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.
9 */
10
11
12 #include "vpx_config.h"
13 #include "vp8_rtcd.h"
14 #include "./vpx_dsp_rtcd.h"
15 #include "vp8/encoder/quantize.h"
16 #include "vp8/common/reconintra.h"
17 #include "vp8/common/reconintra4x4.h"
18 #include "encodemb.h"
19 #include "vp8/common/invtrans.h"
20 #include "encodeintra.h"
21
22
vp8_encode_intra(VP8_COMP * cpi,MACROBLOCK * x,int use_dc_pred)23 int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred)
24 {
25
26 int i;
27 int intra_pred_var = 0;
28 (void) cpi;
29
30 if (use_dc_pred)
31 {
32 x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
33 x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
34 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
35
36 vp8_encode_intra16x16mby(x);
37
38 vp8_inverse_transform_mby(&x->e_mbd);
39 }
40 else
41 {
42 for (i = 0; i < 16; i++)
43 {
44 x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
45 vp8_encode_intra4x4block(x, i);
46 }
47 }
48
49 intra_pred_var = vpx_get_mb_ss(x->src_diff);
50
51 return intra_pred_var;
52 }
53
vp8_encode_intra4x4block(MACROBLOCK * x,int ib)54 void vp8_encode_intra4x4block(MACROBLOCK *x, int ib)
55 {
56 BLOCKD *b = &x->e_mbd.block[ib];
57 BLOCK *be = &x->block[ib];
58 int dst_stride = x->e_mbd.dst.y_stride;
59 unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
60 unsigned char *Above = dst - dst_stride;
61 unsigned char *yleft = dst - 1;
62 unsigned char top_left = Above[-1];
63
64 vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode,
65 b->predictor, 16, top_left);
66
67 vp8_subtract_b(be, b, 16);
68
69 x->short_fdct4x4(be->src_diff, be->coeff, 32);
70
71 x->quantize_b(be, b);
72
73 if (*b->eob > 1)
74 {
75 vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride);
76 }
77 else
78 {
79 vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride);
80 }
81 }
82
vp8_encode_intra4x4mby(MACROBLOCK * mb)83 void vp8_encode_intra4x4mby(MACROBLOCK *mb)
84 {
85 int i;
86
87 MACROBLOCKD *xd = &mb->e_mbd;
88 intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
89
90 for (i = 0; i < 16; i++)
91 vp8_encode_intra4x4block(mb, i);
92 return;
93 }
94
vp8_encode_intra16x16mby(MACROBLOCK * x)95 void vp8_encode_intra16x16mby(MACROBLOCK *x)
96 {
97 BLOCK *b = &x->block[0];
98 MACROBLOCKD *xd = &x->e_mbd;
99
100 vp8_build_intra_predictors_mby_s(xd,
101 xd->dst.y_buffer - xd->dst.y_stride,
102 xd->dst.y_buffer - 1,
103 xd->dst.y_stride,
104 xd->dst.y_buffer,
105 xd->dst.y_stride);
106
107 vp8_subtract_mby(x->src_diff, *(b->base_src),
108 b->src_stride, xd->dst.y_buffer, xd->dst.y_stride);
109
110 vp8_transform_intra_mby(x);
111
112 vp8_quantize_mby(x);
113
114 if (x->optimize)
115 vp8_optimize_mby(x);
116 }
117
vp8_encode_intra16x16mbuv(MACROBLOCK * x)118 void vp8_encode_intra16x16mbuv(MACROBLOCK *x)
119 {
120 MACROBLOCKD *xd = &x->e_mbd;
121
122 vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride,
123 xd->dst.v_buffer - xd->dst.uv_stride,
124 xd->dst.u_buffer - 1,
125 xd->dst.v_buffer - 1,
126 xd->dst.uv_stride,
127 xd->dst.u_buffer, xd->dst.v_buffer,
128 xd->dst.uv_stride);
129
130 vp8_subtract_mbuv(x->src_diff, x->src.u_buffer,
131 x->src.v_buffer, x->src.uv_stride, xd->dst.u_buffer,
132 xd->dst.v_buffer, xd->dst.uv_stride);
133
134 vp8_transform_mbuv(x);
135
136 vp8_quantize_mbuv(x);
137
138 if (x->optimize)
139 vp8_optimize_mbuv(x);
140 }
141