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