• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "vpx_config.h"
12 #include "vp8_rtcd.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"
17 #include "encodemb.h"
18 #include "vp8/common/invtrans.h"
19 #include "encodeintra.h"
20 
vp8_encode_intra(MACROBLOCK * x,int use_dc_pred)21 int vp8_encode_intra(MACROBLOCK *x, int use_dc_pred) {
22   int i;
23   int intra_pred_var = 0;
24 
25   if (use_dc_pred) {
26     x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
27     x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
28     x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
29 
30     vp8_encode_intra16x16mby(x);
31 
32     vp8_inverse_transform_mby(&x->e_mbd);
33   } else {
34     for (i = 0; i < 16; ++i) {
35       x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
36       vp8_encode_intra4x4block(x, i);
37     }
38   }
39 
40   intra_pred_var = vpx_get_mb_ss(x->src_diff);
41 
42   return intra_pred_var;
43 }
44 
vp8_encode_intra4x4block(MACROBLOCK * x,int ib)45 void vp8_encode_intra4x4block(MACROBLOCK *x, int ib) {
46   BLOCKD *b = &x->e_mbd.block[ib];
47   BLOCK *be = &x->block[ib];
48   int dst_stride = x->e_mbd.dst.y_stride;
49   unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
50   unsigned char *Above = dst - dst_stride;
51   unsigned char *yleft = dst - 1;
52   unsigned char top_left = Above[-1];
53 
54   vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode, b->predictor,
55                        16, top_left);
56 
57   vp8_subtract_b(be, b, 16);
58 
59   x->short_fdct4x4(be->src_diff, be->coeff, 32);
60 
61   x->quantize_b(be, b);
62 
63   if (*b->eob > 1) {
64     vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride);
65   } else {
66     vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride);
67   }
68 }
69 
vp8_encode_intra4x4mby(MACROBLOCK * mb)70 void vp8_encode_intra4x4mby(MACROBLOCK *mb) {
71   int i;
72 
73   MACROBLOCKD *xd = &mb->e_mbd;
74   intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
75 
76   for (i = 0; i < 16; ++i) vp8_encode_intra4x4block(mb, i);
77   return;
78 }
79 
vp8_encode_intra16x16mby(MACROBLOCK * x)80 void vp8_encode_intra16x16mby(MACROBLOCK *x) {
81   BLOCK *b = &x->block[0];
82   MACROBLOCKD *xd = &x->e_mbd;
83 
84   vp8_build_intra_predictors_mby_s(xd, xd->dst.y_buffer - xd->dst.y_stride,
85                                    xd->dst.y_buffer - 1, xd->dst.y_stride,
86                                    xd->dst.y_buffer, xd->dst.y_stride);
87 
88   vp8_subtract_mby(x->src_diff, *(b->base_src), b->src_stride, xd->dst.y_buffer,
89                    xd->dst.y_stride);
90 
91   vp8_transform_intra_mby(x);
92 
93   vp8_quantize_mby(x);
94 
95   if (x->optimize) vp8_optimize_mby(x);
96 }
97 
vp8_encode_intra16x16mbuv(MACROBLOCK * x)98 void vp8_encode_intra16x16mbuv(MACROBLOCK *x) {
99   MACROBLOCKD *xd = &x->e_mbd;
100 
101   vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride,
102                                     xd->dst.v_buffer - xd->dst.uv_stride,
103                                     xd->dst.u_buffer - 1, xd->dst.v_buffer - 1,
104                                     xd->dst.uv_stride, xd->dst.u_buffer,
105                                     xd->dst.v_buffer, xd->dst.uv_stride);
106 
107   vp8_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
108                     x->src.uv_stride, xd->dst.u_buffer, xd->dst.v_buffer,
109                     xd->dst.uv_stride);
110 
111   vp8_transform_mbuv(x);
112 
113   vp8_quantize_mbuv(x);
114 
115   if (x->optimize) vp8_optimize_mbuv(x);
116 }
117