Improved rd_pick_intra4x4block
[aom.git] / vp8 / encoder / encodeintra.c
blob73a0db0f51abda3f51e08d86464b2ff05c419ef4
1 /*
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.
9 */
12 #include "vpx_ports/config.h"
13 #include "idct.h"
14 #include "quantize.h"
15 #include "reconintra.h"
16 #include "reconintra4x4.h"
17 #include "encodemb.h"
18 #include "invtrans.h"
19 #include "recon.h"
20 #include "dct.h"
21 #include "g_common.h"
22 #include "encodeintra.h"
24 #define intra4x4ibias_rate 128
25 #define intra4x4pbias_rate 256
28 void vp8_update_mode_context(int *abmode, int *lbmode, int i, int best_mode)
30 if (i < 12)
32 abmode[i+4] = best_mode;
35 if ((i & 3) != 3)
37 lbmode[i+1] = best_mode;
41 #if CONFIG_RUNTIME_CPU_DETECT
42 #define IF_RTCD(x) (x)
43 #else
44 #define IF_RTCD(x) NULL
45 #endif
46 void vp8_encode_intra4x4block(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x, BLOCK *be, BLOCKD *b, int best_mode)
48 vp8_predict_intra4x4(b, best_mode, b->predictor);
50 ENCODEMB_INVOKE(&rtcd->encodemb, subb)(be, b, 16);
52 x->vp8_short_fdct4x4(be->src_diff, be->coeff, 32);
54 x->quantize_b(be, b);
56 vp8_inverse_transform_b(IF_RTCD(&rtcd->common->idct), b, 32);
58 RECON_INVOKE(&rtcd->common->recon, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
61 void vp8_encode_intra4x4mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *mb)
63 int i;
65 MACROBLOCKD *x = &mb->e_mbd;
66 vp8_intra_prediction_down_copy(x);
68 for (i = 0; i < 16; i++)
70 BLOCK *be = &mb->block[i];
71 BLOCKD *b = &x->block[i];
73 vp8_encode_intra4x4block(rtcd, mb, be, b, b->bmi.mode);
76 return;
79 void vp8_encode_intra16x16mby(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
81 int b;
83 vp8_build_intra_predictors_mby_ptr(&x->e_mbd);
85 ENCODEMB_INVOKE(&rtcd->encodemb, submby)(x->src_diff, x->src.y_buffer, x->e_mbd.predictor, x->src.y_stride);
87 vp8_transform_intra_mby(x);
89 vp8_quantize_mby(x);
91 #if !(CONFIG_REALTIME_ONLY)
92 #if 1
93 if (x->optimize)
94 vp8_optimize_mby(x, rtcd);
96 #endif
97 #endif
99 vp8_inverse_transform_mby(IF_RTCD(&rtcd->common->idct), &x->e_mbd);
101 RECON_INVOKE(&rtcd->common->recon, recon_mby)
102 (IF_RTCD(&rtcd->common->recon), &x->e_mbd);
104 // make sure block modes are set the way we want them for context updates
105 for (b = 0; b < 16; b++)
107 BLOCKD *d = &x->e_mbd.block[b];
109 switch (x->e_mbd.mode_info_context->mbmi.mode)
112 case DC_PRED:
113 d->bmi.mode = B_DC_PRED;
114 break;
115 case V_PRED:
116 d->bmi.mode = B_VE_PRED;
117 break;
118 case H_PRED:
119 d->bmi.mode = B_HE_PRED;
120 break;
121 case TM_PRED:
122 d->bmi.mode = B_TM_PRED;
123 break;
124 default:
125 d->bmi.mode = B_DC_PRED;
126 break;
132 void vp8_encode_intra16x16mbuv(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
134 vp8_build_intra_predictors_mbuv(&x->e_mbd);
136 ENCODEMB_INVOKE(&rtcd->encodemb, submbuv)(x->src_diff, x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
138 vp8_transform_mbuv(x);
140 vp8_quantize_mbuv(x);
142 #if !(CONFIG_REALTIME_ONLY)
143 #if 1
145 if (x->optimize==2 ||(x->optimize && x->rddiv > 1))
146 vp8_optimize_mbuv(x, rtcd);
148 #endif
149 #endif
151 vp8_inverse_transform_mbuv(IF_RTCD(&rtcd->common->idct), &x->e_mbd);
153 vp8_recon_intra_mbuv(IF_RTCD(&rtcd->common->recon), &x->e_mbd);
156 void vp8_encode_intra16x16mbuvrd(const VP8_ENCODER_RTCD *rtcd, MACROBLOCK *x)
158 vp8_build_intra_predictors_mbuv(&x->e_mbd);
160 ENCODEMB_INVOKE(&rtcd->encodemb, submbuv)(x->src_diff, x->src.u_buffer, x->src.v_buffer, x->e_mbd.predictor, x->src.uv_stride);
162 vp8_transform_mbuv(x);
164 vp8_quantize_mbuv(x);
166 vp8_inverse_transform_mbuv(IF_RTCD(&rtcd->common->idct), &x->e_mbd);
168 vp8_recon_intra_mbuv(IF_RTCD(&rtcd->common->recon), &x->e_mbd);