Merge "vp8_rd_pick_best_mbsegmentation code restructure"
[libvpx.git] / vp8 / common / reconintra4x4.c
blobdb44fa1909ecb519c6c949ab828ea3918651c4e2
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 "recon.h"
14 #include "vpx_mem/vpx_mem.h"
15 #include "reconintra.h"
17 void vp8_predict_intra4x4(BLOCKD *x,
18 int b_mode,
19 unsigned char *predictor)
21 int i, r, c;
23 unsigned char *Above = *(x->base_dst) + x->dst - x->dst_stride;
24 unsigned char Left[4];
25 unsigned char top_left = Above[-1];
27 Left[0] = (*(x->base_dst))[x->dst - 1];
28 Left[1] = (*(x->base_dst))[x->dst - 1 + x->dst_stride];
29 Left[2] = (*(x->base_dst))[x->dst - 1 + 2 * x->dst_stride];
30 Left[3] = (*(x->base_dst))[x->dst - 1 + 3 * x->dst_stride];
32 switch (b_mode)
34 case B_DC_PRED:
36 int expected_dc = 0;
38 for (i = 0; i < 4; i++)
40 expected_dc += Above[i];
41 expected_dc += Left[i];
44 expected_dc = (expected_dc + 4) >> 3;
46 for (r = 0; r < 4; r++)
48 for (c = 0; c < 4; c++)
50 predictor[c] = expected_dc;
53 predictor += 16;
56 break;
57 case B_TM_PRED:
59 /* prediction similar to true_motion prediction */
60 for (r = 0; r < 4; r++)
62 for (c = 0; c < 4; c++)
64 int pred = Above[c] - top_left + Left[r];
66 if (pred < 0)
67 pred = 0;
69 if (pred > 255)
70 pred = 255;
72 predictor[c] = pred;
75 predictor += 16;
78 break;
80 case B_VE_PRED:
83 unsigned int ap[4];
84 ap[0] = (top_left + 2 * Above[0] + Above[1] + 2) >> 2;
85 ap[1] = (Above[0] + 2 * Above[1] + Above[2] + 2) >> 2;
86 ap[2] = (Above[1] + 2 * Above[2] + Above[3] + 2) >> 2;
87 ap[3] = (Above[2] + 2 * Above[3] + Above[4] + 2) >> 2;
89 for (r = 0; r < 4; r++)
91 for (c = 0; c < 4; c++)
94 predictor[c] = ap[c];
97 predictor += 16;
101 break;
104 case B_HE_PRED:
107 unsigned int lp[4];
108 lp[0] = (top_left + 2 * Left[0] + Left[1] + 2) >> 2;
109 lp[1] = (Left[0] + 2 * Left[1] + Left[2] + 2) >> 2;
110 lp[2] = (Left[1] + 2 * Left[2] + Left[3] + 2) >> 2;
111 lp[3] = (Left[2] + 2 * Left[3] + Left[3] + 2) >> 2;
113 for (r = 0; r < 4; r++)
115 for (c = 0; c < 4; c++)
117 predictor[c] = lp[r];
120 predictor += 16;
123 break;
124 case B_LD_PRED:
126 unsigned char *ptr = Above;
127 predictor[0 * 16 + 0] = (ptr[0] + ptr[1] * 2 + ptr[2] + 2) >> 2;
128 predictor[0 * 16 + 1] =
129 predictor[1 * 16 + 0] = (ptr[1] + ptr[2] * 2 + ptr[3] + 2) >> 2;
130 predictor[0 * 16 + 2] =
131 predictor[1 * 16 + 1] =
132 predictor[2 * 16 + 0] = (ptr[2] + ptr[3] * 2 + ptr[4] + 2) >> 2;
133 predictor[0 * 16 + 3] =
134 predictor[1 * 16 + 2] =
135 predictor[2 * 16 + 1] =
136 predictor[3 * 16 + 0] = (ptr[3] + ptr[4] * 2 + ptr[5] + 2) >> 2;
137 predictor[1 * 16 + 3] =
138 predictor[2 * 16 + 2] =
139 predictor[3 * 16 + 1] = (ptr[4] + ptr[5] * 2 + ptr[6] + 2) >> 2;
140 predictor[2 * 16 + 3] =
141 predictor[3 * 16 + 2] = (ptr[5] + ptr[6] * 2 + ptr[7] + 2) >> 2;
142 predictor[3 * 16 + 3] = (ptr[6] + ptr[7] * 2 + ptr[7] + 2) >> 2;
145 break;
146 case B_RD_PRED:
149 unsigned char pp[9];
151 pp[0] = Left[3];
152 pp[1] = Left[2];
153 pp[2] = Left[1];
154 pp[3] = Left[0];
155 pp[4] = top_left;
156 pp[5] = Above[0];
157 pp[6] = Above[1];
158 pp[7] = Above[2];
159 pp[8] = Above[3];
161 predictor[3 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
162 predictor[3 * 16 + 1] =
163 predictor[2 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
164 predictor[3 * 16 + 2] =
165 predictor[2 * 16 + 1] =
166 predictor[1 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
167 predictor[3 * 16 + 3] =
168 predictor[2 * 16 + 2] =
169 predictor[1 * 16 + 1] =
170 predictor[0 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
171 predictor[2 * 16 + 3] =
172 predictor[1 * 16 + 2] =
173 predictor[0 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
174 predictor[1 * 16 + 3] =
175 predictor[0 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
176 predictor[0 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2;
179 break;
180 case B_VR_PRED:
183 unsigned char pp[9];
185 pp[0] = Left[3];
186 pp[1] = Left[2];
187 pp[2] = Left[1];
188 pp[3] = Left[0];
189 pp[4] = top_left;
190 pp[5] = Above[0];
191 pp[6] = Above[1];
192 pp[7] = Above[2];
193 pp[8] = Above[3];
196 predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
197 predictor[2 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
198 predictor[3 * 16 + 1] =
199 predictor[1 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
200 predictor[2 * 16 + 1] =
201 predictor[0 * 16 + 0] = (pp[4] + pp[5] + 1) >> 1;
202 predictor[3 * 16 + 2] =
203 predictor[1 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
204 predictor[2 * 16 + 2] =
205 predictor[0 * 16 + 1] = (pp[5] + pp[6] + 1) >> 1;
206 predictor[3 * 16 + 3] =
207 predictor[1 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
208 predictor[2 * 16 + 3] =
209 predictor[0 * 16 + 2] = (pp[6] + pp[7] + 1) >> 1;
210 predictor[1 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2;
211 predictor[0 * 16 + 3] = (pp[7] + pp[8] + 1) >> 1;
214 break;
215 case B_VL_PRED:
218 unsigned char *pp = Above;
220 predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
221 predictor[1 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
222 predictor[2 * 16 + 0] =
223 predictor[0 * 16 + 1] = (pp[1] + pp[2] + 1) >> 1;
224 predictor[1 * 16 + 1] =
225 predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
226 predictor[2 * 16 + 1] =
227 predictor[0 * 16 + 2] = (pp[2] + pp[3] + 1) >> 1;
228 predictor[3 * 16 + 1] =
229 predictor[1 * 16 + 2] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
230 predictor[0 * 16 + 3] =
231 predictor[2 * 16 + 2] = (pp[3] + pp[4] + 1) >> 1;
232 predictor[1 * 16 + 3] =
233 predictor[3 * 16 + 2] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
234 predictor[2 * 16 + 3] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
235 predictor[3 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
237 break;
239 case B_HD_PRED:
241 unsigned char pp[9];
242 pp[0] = Left[3];
243 pp[1] = Left[2];
244 pp[2] = Left[1];
245 pp[3] = Left[0];
246 pp[4] = top_left;
247 pp[5] = Above[0];
248 pp[6] = Above[1];
249 pp[7] = Above[2];
250 pp[8] = Above[3];
253 predictor[3 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
254 predictor[3 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
255 predictor[2 * 16 + 0] =
256 predictor[3 * 16 + 2] = (pp[1] + pp[2] + 1) >> 1;
257 predictor[2 * 16 + 1] =
258 predictor[3 * 16 + 3] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
259 predictor[2 * 16 + 2] =
260 predictor[1 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1;
261 predictor[2 * 16 + 3] =
262 predictor[1 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
263 predictor[1 * 16 + 2] =
264 predictor[0 * 16 + 0] = (pp[3] + pp[4] + 1) >> 1;
265 predictor[1 * 16 + 3] =
266 predictor[0 * 16 + 1] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
267 predictor[0 * 16 + 2] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
268 predictor[0 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
270 break;
273 case B_HU_PRED:
275 unsigned char *pp = Left;
276 predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
277 predictor[0 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
278 predictor[0 * 16 + 2] =
279 predictor[1 * 16 + 0] = (pp[1] + pp[2] + 1) >> 1;
280 predictor[0 * 16 + 3] =
281 predictor[1 * 16 + 1] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
282 predictor[1 * 16 + 2] =
283 predictor[2 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1;
284 predictor[1 * 16 + 3] =
285 predictor[2 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[3] + 2) >> 2;
286 predictor[2 * 16 + 2] =
287 predictor[2 * 16 + 3] =
288 predictor[3 * 16 + 0] =
289 predictor[3 * 16 + 1] =
290 predictor[3 * 16 + 2] =
291 predictor[3 * 16 + 3] = pp[3];
293 break;
298 /* copy 4 bytes from the above right down so that the 4x4 prediction modes using pixels above and
299 * to the right prediction have filled in pixels to use.
301 void vp8_intra_prediction_down_copy(MACROBLOCKD *x)
303 unsigned char *above_right = *(x->block[0].base_dst) + x->block[0].dst - x->block[0].dst_stride + 16;
305 unsigned int *src_ptr = (unsigned int *)above_right;
306 unsigned int *dst_ptr0 = (unsigned int *)(above_right + 4 * x->block[0].dst_stride);
307 unsigned int *dst_ptr1 = (unsigned int *)(above_right + 8 * x->block[0].dst_stride);
308 unsigned int *dst_ptr2 = (unsigned int *)(above_right + 12 * x->block[0].dst_stride);
310 *dst_ptr0 = *src_ptr;
311 *dst_ptr1 = *src_ptr;
312 *dst_ptr2 = *src_ptr;
316 void vp8_recon_intra4x4mb(const vp8_recon_rtcd_vtable_t *rtcd, MACROBLOCKD *x)
318 int i;
320 vp8_intra_prediction_down_copy(x);
322 #if ARCH_ARM
324 BLOCKD *b = &x->block[0];
326 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
327 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
328 b += 1;
330 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
331 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
332 b += 1;
334 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
335 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
336 b += 1;
338 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
339 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
340 b += 1;
342 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
343 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
344 b += 1;
346 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
347 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
348 b += 1;
350 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
351 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
352 b += 1;
354 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
355 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
356 b += 1;
358 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
359 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
360 b += 1;
362 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
363 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
364 b += 1;
366 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
367 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
368 b += 1;
370 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
371 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
372 b += 1;
374 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
375 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
376 b += 1;
378 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
379 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
380 b += 1;
382 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
383 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
384 b += 1;
386 vp8_predict_intra4x4(b, b->bmi.mode, b->predictor);
387 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
389 #else
390 for (i = 0; i < 16; i++)
392 BLOCKD *b = &x->block[i];
394 vp8_predict_intra4x4(b, x->block[i].bmi.mode, x->block[i].predictor);
395 RECON_INVOKE(rtcd, recon)(b->predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
397 #endif
399 vp8_recon_intra_mbuv(rtcd, x);