Merge "Relocated idct/add calls for encoder"
[profile/ivi/libvpx.git] / vp8 / encoder / encodeintra.c
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/common/idct.h"
14 #include "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 "vp8/common/recon.h"
20 #include "dct.h"
21 #include "vp8/common/g_common.h"
22 #include "encodeintra.h"
23
24
25 #if CONFIG_RUNTIME_CPU_DETECT
26 #define IF_RTCD(x) (x)
27 #else
28 #define IF_RTCD(x) NULL
29 #endif
30
31 int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred)
32 {
33
34     int i;
35     int intra_pred_var = 0;
36     (void) cpi;
37
38     if (use_dc_pred)
39     {
40         const VP8_ENCODER_RTCD *rtcd = IF_RTCD(&cpi->rtcd);
41
42         x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
43         x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
44         x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
45
46         vp8_encode_intra16x16mby(rtcd, x);
47
48         vp8_inverse_transform_mby(IF_RTCD(&rtcd->common->idct), &x->e_mbd);
49     }
50     else
51     {
52         for (i = 0; i < 16; i++)
53         {
54             x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
55             vp8_encode_intra4x4block(IF_RTCD(&cpi->rtcd), x, i);
56         }
57     }
58
59     intra_pred_var = VARIANCE_INVOKE(&cpi->rtcd.variance, getmbss)(x->src_diff);
60
61     return intra_pred_var;
62 }
63
64 void vp8_encode_intra4x4block(const VP8_ENCODER_RTCD *rtcd,
65                               MACROBLOCK *x, int ib)
66 {
67     BLOCKD *b = &x->e_mbd.block[ib];
68     BLOCK *be = &x->block[ib];
69
70     RECON_INVOKE(&rtcd->common->recon, intra4x4_predict)
71                 (*(b->base_dst) + b->dst, b->dst_stride,
72                  b->bmi.as_mode, b->predictor, 16);
73
74     ENCODEMB_INVOKE(&rtcd->encodemb, subb)(be, b, 16);
75
76     x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
77
78     x->quantize_b(be, b);
79
80     vp8_inverse_transform_b(IF_RTCD(&rtcd->common->idct), b, 16);
81
82 }
83
84 void vp8_encode_intra4x4mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *mb)
85 {
86     int i;
87
88     MACROBLOCKD *x = &mb->e_mbd;
89     vp8_intra_prediction_down_copy(x);
90
91     for (i = 0; i < 16; i++)
92         vp8_encode_intra4x4block(rtcd, mb, i);
93     return;
94 }
95
96 void vp8_encode_intra16x16mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
97 {
98     BLOCK *b = &x->block[0];
99
100     RECON_INVOKE(&rtcd->common->recon, build_intra_predictors_mby)(&x->e_mbd);
101
102     ENCODEMB_INVOKE(&rtcd->encodemb, submby)(x->src_diff, *(b->base_src),
103         x->e_mbd.predictor, b->src_stride);
104
105     vp8_transform_intra_mby(x);
106
107     vp8_quantize_mby(x);
108
109     if (x->optimize)
110         vp8_optimize_mby(x, rtcd);
111
112 }
113
114 void vp8_encode_intra16x16mbuv(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
115 {
116     RECON_INVOKE(&rtcd->common->recon, build_intra_predictors_mbuv)(&x->e_mbd);
117
118     ENCODEMB_INVOKE(&rtcd->encodemb, submbuv)(x->src_diff, x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
119
120     vp8_transform_mbuv(x);
121
122     vp8_quantize_mbuv(x);
123
124     if (x->optimize)
125         vp8_optimize_mbuv(x, rtcd);
126
127 }