1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG-4 part10 prediction functions.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #include "config.h"
35
36 #define BIT_DEPTH 8
38 #undef BIT_DEPTH
39
40 #define BIT_DEPTH 9
42 #undef BIT_DEPTH
43
44 #define BIT_DEPTH 10
46 #undef BIT_DEPTH
47
48 #define BIT_DEPTH 12
50 #undef BIT_DEPTH
51
54 #undef BIT_DEPTH
55
58 {
65 (
t2 + 2*
t3 +
t4 + 2) >> 2);
66
71 }
72
75 {
78
83 }
84
87 {
90
107 }
108
111 {
116
133 }
134
136 const uint8_t *topright,
138 {
142
159 }
160
163 const int l0, const int l1, const int l2,
164 const int l3, const int l4)
165 {
168
185 }
186
189 {
192
194 }
195
197 const uint8_t *topright,
199 {
201
203 }
204
207 {
210
227 }
228
231 {
236
253 }
254
256 const uint8_t *topright,
258 {
262
279 }
280
283 {
286 int y;
287
288 for (y = 0; y < 4; y++) {
289 const uint8_t *cm_in =
cm +
src[-1];
290 src[0] = cm_in[top[0]];
291 src[1] = cm_in[top[1]];
292 src[2] = cm_in[top[2]];
293 src[3] = cm_in[top[3]];
295 }
296 }
297
299 {
300 pred16x16_plane_compat_8_c(
src,
stride, 1, 0);
301 }
302
304 {
305 pred16x16_plane_compat_8_c(
src,
stride, 0, 1);
306 }
307
309 {
312 int y;
313
314 for (y = 0; y < 16; y++) {
315 const uint8_t *cm_in =
cm +
src[-1];
316 src[0] = cm_in[top[0]];
317 src[1] = cm_in[top[1]];
318 src[2] = cm_in[top[2]];
319 src[3] = cm_in[top[3]];
320 src[4] = cm_in[top[4]];
321 src[5] = cm_in[top[5]];
322 src[6] = cm_in[top[6]];
323 src[7] = cm_in[top[7]];
324 src[8] = cm_in[top[8]];
325 src[9] = cm_in[top[9]];
326 src[10] = cm_in[top[10]];
327 src[11] = cm_in[top[11]];
328 src[12] = cm_in[top[12]];
329 src[13] = cm_in[top[13]];
330 src[14] = cm_in[top[14]];
331 src[15] = cm_in[top[15]];
333 }
334 }
335
337 {
339 unsigned dc0;
340
341 dc0=0;
344 dc0= 0x01010101*((dc0 + 4)>>3);
345
349 }
350 }
351
353 {
355 unsigned dc0;
356
357 dc0=0;
360 dc0= 0x01010101*((dc0 + 4)>>3);
361
365 }
366 }
367
369 {
371 unsigned dc0 = 0;
372
377 }
378 dc0= 0x01010101*((dc0 + 8)>>4);
379
383 }
387 }
388 }
389
391 {
394 int y;
395
396 for (y = 0; y < 8; y++) {
397 const uint8_t *cm_in =
cm +
src[-1];
398 src[0] = cm_in[top[0]];
399 src[1] = cm_in[top[1]];
400 src[2] = cm_in[top[2]];
401 src[3] = cm_in[top[3]];
402 src[4] = cm_in[top[4]];
403 src[5] = cm_in[top[5]];
404 src[6] = cm_in[top[6]];
405 src[7] = cm_in[top[7]];
407 }
408 }
409
410 /**
411 * Set the intra prediction function pointers.
412 */
415 int chroma_format_idc)
416 {
417 #undef FUNC
418 #undef FUNCC
419 #define FUNC(a, depth) a ## _ ## depth
420 #define FUNCC(a, depth) a ## _ ## depth ## _c
421 #define FUNCD(a) a ## _c
422
423 #define H264_PRED(depth) \
424 if(codec_id != AV_CODEC_ID_RV40){\
425 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8) {\
426 h->pred4x4[VERT_PRED ]= FUNCD(pred4x4_vertical_vp8);\
427 h->pred4x4[HOR_PRED ]= FUNCD(pred4x4_horizontal_vp8);\
428 } else {\
429 h->pred4x4[VERT_PRED ]= FUNCC(pred4x4_vertical , depth);\
430 h->pred4x4[HOR_PRED ]= FUNCC(pred4x4_horizontal , depth);\
431 }\
432 h->pred4x4[DC_PRED ]= FUNCC(pred4x4_dc , depth);\
433 if(codec_id == AV_CODEC_ID_SVQ3)\
434 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_svq3);\
435 else\
436 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred4x4_down_left , depth);\
437 h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right , depth);\
438 h->pred4x4[VERT_RIGHT_PRED ]= FUNCC(pred4x4_vertical_right , depth);\
439 h->pred4x4[HOR_DOWN_PRED ]= FUNCC(pred4x4_horizontal_down , depth);\
440 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8) {\
441 h->pred4x4[VERT_LEFT_PRED ]= FUNCD(pred4x4_vertical_left_vp8);\
442 } else\
443 h->pred4x4[VERT_LEFT_PRED ]= FUNCC(pred4x4_vertical_left , depth);\
444 h->pred4x4[HOR_UP_PRED ]= FUNCC(pred4x4_horizontal_up , depth);\
445 if (codec_id != AV_CODEC_ID_VP7 && codec_id != AV_CODEC_ID_VP8) {\
446 h->pred4x4[LEFT_DC_PRED ]= FUNCC(pred4x4_left_dc , depth);\
447 h->pred4x4[TOP_DC_PRED ]= FUNCC(pred4x4_top_dc , depth);\
448 } else {\
449 h->pred4x4[TM_VP8_PRED ]= FUNCD(pred4x4_tm_vp8);\
450 h->pred4x4[DC_127_PRED ]= FUNCC(pred4x4_127_dc , depth);\
451 h->pred4x4[DC_129_PRED ]= FUNCC(pred4x4_129_dc , depth);\
452 h->pred4x4[VERT_VP8_PRED ]= FUNCC(pred4x4_vertical , depth);\
453 h->pred4x4[HOR_VP8_PRED ]= FUNCC(pred4x4_horizontal , depth);\
454 }\
455 if (codec_id != AV_CODEC_ID_VP8)\
456 h->pred4x4[DC_128_PRED ]= FUNCC(pred4x4_128_dc , depth);\
457 }else{\
458 h->pred4x4[VERT_PRED ]= FUNCC(pred4x4_vertical , depth);\
459 h->pred4x4[HOR_PRED ]= FUNCC(pred4x4_horizontal , depth);\
460 h->pred4x4[DC_PRED ]= FUNCC(pred4x4_dc , depth);\
461 h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_rv40);\
462 h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right , depth);\
463 h->pred4x4[VERT_RIGHT_PRED ]= FUNCC(pred4x4_vertical_right , depth);\
464 h->pred4x4[HOR_DOWN_PRED ]= FUNCC(pred4x4_horizontal_down , depth);\
465 h->pred4x4[VERT_LEFT_PRED ]= FUNCD(pred4x4_vertical_left_rv40);\
466 h->pred4x4[HOR_UP_PRED ]= FUNCD(pred4x4_horizontal_up_rv40);\
467 h->pred4x4[LEFT_DC_PRED ]= FUNCC(pred4x4_left_dc , depth);\
468 h->pred4x4[TOP_DC_PRED ]= FUNCC(pred4x4_top_dc , depth);\
469 h->pred4x4[DC_128_PRED ]= FUNCC(pred4x4_128_dc , depth);\
470 h->pred4x4[DIAG_DOWN_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_down_left_rv40_nodown);\
471 h->pred4x4[HOR_UP_PRED_RV40_NODOWN]= FUNCD(pred4x4_horizontal_up_rv40_nodown);\
472 h->pred4x4[VERT_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_vertical_left_rv40_nodown);\
473 }\
474 \
475 h->pred8x8l[VERT_PRED ]= FUNCC(pred8x8l_vertical , depth);\
476 h->pred8x8l[HOR_PRED ]= FUNCC(pred8x8l_horizontal , depth);\
477 h->pred8x8l[DC_PRED ]= FUNCC(pred8x8l_dc , depth);\
478 h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred8x8l_down_left , depth);\
479 h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred8x8l_down_right , depth);\
480 h->pred8x8l[VERT_RIGHT_PRED ]= FUNCC(pred8x8l_vertical_right , depth);\
481 h->pred8x8l[HOR_DOWN_PRED ]= FUNCC(pred8x8l_horizontal_down , depth);\
482 h->pred8x8l[VERT_LEFT_PRED ]= FUNCC(pred8x8l_vertical_left , depth);\
483 h->pred8x8l[HOR_UP_PRED ]= FUNCC(pred8x8l_horizontal_up , depth);\
484 h->pred8x8l[LEFT_DC_PRED ]= FUNCC(pred8x8l_left_dc , depth);\
485 h->pred8x8l[TOP_DC_PRED ]= FUNCC(pred8x8l_top_dc , depth);\
486 h->pred8x8l[DC_128_PRED ]= FUNCC(pred8x8l_128_dc , depth);\
487 \
488 if (chroma_format_idc <= 1) {\
489 h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x8_vertical , depth);\
490 h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x8_horizontal , depth);\
491 } else {\
492 h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x16_vertical , depth);\
493 h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x16_horizontal , depth);\
494 }\
495 if (codec_id != AV_CODEC_ID_VP7 && codec_id != AV_CODEC_ID_VP8) {\
496 if (chroma_format_idc <= 1) {\
497 h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x8_plane , depth);\
498 } else {\
499 h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x16_plane , depth);\
500 }\
501 } else\
502 h->pred8x8[PLANE_PRED8x8]= FUNCD(pred8x8_tm_vp8);\
503 if (codec_id != AV_CODEC_ID_RV40 && codec_id != AV_CODEC_ID_VP7 && \
504 codec_id != AV_CODEC_ID_VP8) {\
505 if (chroma_format_idc <= 1) {\
506 h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x8_dc , depth);\
507 h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x8_left_dc , depth);\
508 h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x8_top_dc , depth);\
509 h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l0t, depth);\
510 h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0lt, depth);\
511 h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l00, depth);\
512 h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0l0, depth);\
513 } else {\
514 h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x16_dc , depth);\
515 h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x16_left_dc , depth);\
516 h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x16_top_dc , depth);\
517 h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l0t, depth);\
518 h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0lt, depth);\
519 h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l00, depth);\
520 h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0l0, depth);\
521 }\
522 }else{\
523 h->pred8x8[DC_PRED8x8 ]= FUNCD(pred8x8_dc_rv40);\
524 h->pred8x8[LEFT_DC_PRED8x8]= FUNCD(pred8x8_left_dc_rv40);\
525 h->pred8x8[TOP_DC_PRED8x8 ]= FUNCD(pred8x8_top_dc_rv40);\
526 if (codec_id == AV_CODEC_ID_VP7 || codec_id == AV_CODEC_ID_VP8) {\
527 h->pred8x8[DC_127_PRED8x8]= FUNCC(pred8x8_127_dc , depth);\
528 h->pred8x8[DC_129_PRED8x8]= FUNCC(pred8x8_129_dc , depth);\
529 }\
530 }\
531 if (chroma_format_idc <= 1) {\
532 h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x8_128_dc , depth);\
533 } else {\
534 h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x16_128_dc , depth);\
535 }\
536 \
537 h->pred16x16[DC_PRED8x8 ]= FUNCC(pred16x16_dc , depth);\
538 h->pred16x16[VERT_PRED8x8 ]= FUNCC(pred16x16_vertical , depth);\
539 h->pred16x16[HOR_PRED8x8 ]= FUNCC(pred16x16_horizontal , depth);\
540 switch(codec_id){\
541 case AV_CODEC_ID_SVQ3:\
542 h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_plane_svq3);\
543 break;\
544 case AV_CODEC_ID_RV40:\
545 h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_plane_rv40);\
546 break;\
547 case AV_CODEC_ID_VP7:\
548 case AV_CODEC_ID_VP8:\
549 h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_tm_vp8);\
550 h->pred16x16[DC_127_PRED8x8]= FUNCC(pred16x16_127_dc , depth);\
551 h->pred16x16[DC_129_PRED8x8]= FUNCC(pred16x16_129_dc , depth);\
552 break;\
553 default:\
554 h->pred16x16[PLANE_PRED8x8 ]= FUNCC(pred16x16_plane , depth);\
555 break;\
556 }\
557 h->pred16x16[LEFT_DC_PRED8x8]= FUNCC(pred16x16_left_dc , depth);\
558 h->pred16x16[TOP_DC_PRED8x8 ]= FUNCC(pred16x16_top_dc , depth);\
559 h->pred16x16[DC_128_PRED8x8 ]= FUNCC(pred16x16_128_dc , depth);\
560 \
561 /* special lossless h/v prediction for H.264 */ \
562 h->pred4x4_add [VERT_PRED ]= FUNCC(pred4x4_vertical_add , depth);\
563 h->pred4x4_add [ HOR_PRED ]= FUNCC(pred4x4_horizontal_add , depth);\
564 h->pred8x8l_add [VERT_PRED ]= FUNCC(pred8x8l_vertical_add , depth);\
565 h->pred8x8l_add [ HOR_PRED ]= FUNCC(pred8x8l_horizontal_add , depth);\
566 h->pred8x8l_filter_add [VERT_PRED ]= FUNCC(pred8x8l_vertical_filter_add , depth);\
567 h->pred8x8l_filter_add [ HOR_PRED ]= FUNCC(pred8x8l_horizontal_filter_add , depth);\
568 if (chroma_format_idc <= 1) {\
569 h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x8_vertical_add , depth);\
570 h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x8_horizontal_add , depth);\
571 } else {\
572 h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x16_vertical_add , depth);\
573 h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x16_horizontal_add , depth);\
574 }\
575 h->pred16x16_add[VERT_PRED8x8]= FUNCC(pred16x16_vertical_add , depth);\
576 h->pred16x16_add[ HOR_PRED8x8]= FUNCC(pred16x16_horizontal_add , depth);\
577
579 case 9:
581 break;
582 case 10:
584 break;
585 case 12:
587 break;
588 case 14:
590 break;
591 default:
594 break;
595 }
596
597 if (ARCH_AARCH64)
599 if (ARCH_ARM)
601 if (ARCH_X86)
603 if (ARCH_MIPS)
605 if (ARCH_LOONGARCH)
607 }