1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
3 * Copyright (c) 2003-2011 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
29
31
33
36 {
40
45 }
46
49 {
56 }
57
60 {
66
71 }
72
75 {
80
85 }
86
89 {
94
99 }
100
103 {
107
112 }
113
114
115 #define LOAD_TOP_RIGHT_EDGE\
116 const unsigned av_unused t4 = topright[0];\
117 const unsigned av_unused t5 = topright[1];\
118 const unsigned av_unused t6 = topright[2];\
119 const unsigned av_unused t7 = topright[3];\
120
121 #define LOAD_DOWN_LEFT_EDGE\
122 const unsigned av_unused l4 = src[-1+4*stride];\
123 const unsigned av_unused l5 = src[-1+5*stride];\
124 const unsigned av_unused l6 = src[-1+6*stride];\
125 const unsigned av_unused l7 = src[-1+7*stride];\
126
127 #define LOAD_LEFT_EDGE\
128 const unsigned av_unused l0 = src[-1+0*stride];\
129 const unsigned av_unused l1 = src[-1+1*stride];\
130 const unsigned av_unused l2 = src[-1+2*stride];\
131 const unsigned av_unused l3 = src[-1+3*stride];\
132
133 #define LOAD_TOP_EDGE\
134 const unsigned av_unused t0 = src[ 0-1*stride];\
135 const unsigned av_unused t1 = src[ 1-1*stride];\
136 const unsigned av_unused t2 = src[ 2-1*stride];\
137 const unsigned av_unused t3 = src[ 3-1*stride];\
138
141 {
147
164 }
165
168 {
170 const pixel *topright = (
const pixel*)_topright;
174 // LOAD_LEFT_EDGE
175
192 }
193
195 const uint8_t *topright,
197 {
203
220 }
221
223 const uint8_t *_topright,
225 {
227 const pixel *topright = (
const pixel*)_topright;
231
248 }
249
252 {
256
273 }
274
276 const uint8_t *topright,
278 {
284
301 }
302
304 {
312
318 }
319 }
320
322 {
326
329
334 }
335 }
336
337 #define PREDICT_16x16_DC(v)\
338 for(i=0; i<16; i++){\
339 AV_WN4PA(src+ 0, v);\
340 AV_WN4PA(src+ 4, v);\
341 AV_WN4PA(src+ 8, v);\
342 AV_WN4PA(src+12, v);\
343 src += stride;\
344 }
345
347 {
352
355 }
356
359 }
360
363 }
364
366 {
371
374 }
375
378 }
379
381 {
386
389 }
390
393 }
394
395 #define PRED16x16_X(n, v) \
396 static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
397 {\
398 int i;\
399 pixel *src = (pixel*)_src;\
400 stride >>= sizeof(pixel)-1;\
401 PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\
402 }
403
405 #if BIT_DEPTH == 8
408 #endif
409
410 static inline void FUNCC(pred16x16_plane_compat)(uint8_t *_src,
425 for(k=2; k<=8; ++k) {
429 }
431 H = ( 5*(
H/4) ) / 16;
432 V = ( 5*(
V/4) ) / 16;
433
434 /* required for 100% accuracy */
437 H = (
H + (
H>>2) ) >> 4;
438 V = (
V + (
V>>2) ) >> 4;
442 }
443
445 for(j=16; j>0; --j) {
448 for(
i=-16;
i<0;
i+=4) {
454 }
456 }
457 }
458
460 {
462 }
463
465 {
471
475 }
476 }
477
479 {
485
489 }
490 }
491
493 {
497
502 }
503 }
504
506 {
514 }
515 }
516
517 #define PRED8x8_X(n, v)\
518 static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, ptrdiff_t stride)\
519 {\
520 int i;\
521 const pixel4 a = PIXEL_SPLAT_X4(v);\
522 pixel *src = (pixel*)_src;\
523 stride >>= sizeof(pixel)-1;\
524 for(i=0; i<8; i++){\
525 AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\
526 AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\
527 }\
528 }
529
531 #if BIT_DEPTH == 8
534 #endif
535
536 static void FUNCC(pred8x16_128_dc)(uint8_t *_src, ptrdiff_t
stride)
540 }
541
543 {
545 int dc0, dc2;
546 pixel4 dc0splat, dc2splat;
549
550 dc0=dc2=0;
554 }
557
561 }
565 }
566 }
567
569 {
572 }
573
575 {
577 int dc0, dc1;
578 pixel4 dc0splat, dc1splat;
581
582 dc0=dc1=0;
586 }
589
593 }
597 }
598 }
599
601 {
603 int dc0, dc1;
604 pixel4 dc0splat, dc1splat;
607
608 dc0=dc1=0;
612 }
615
619 }
620 }
621
623 {
625 int dc0, dc1, dc2;
626 pixel4 dc0splat, dc1splat, dc2splat, dc3splat;
629
630 dc0=dc1=dc2=0;
635 }
640
644 }
648 }
649 }
650
652 {
654 int dc0, dc1, dc2, dc3, dc4;
655 pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat;
658
659 dc0=dc1=dc2=dc3=dc4=0;
666 }
675
679 }
683 }
687 }
688 for(
i=12;
i<16;
i++){
691 }
692 }
693
694 //the following 4 function should not be optimized!
696 {
699 }
700
702 {
705 }
706
708 {
711 }
712
714 {
717 }
718
720 {
724 }
725
727 {
731 }
732
734 {
738 }
739
741 {
745 }
746
748 {
749 int j, k;
759 for(k=2; k<=4; ++k) {
763 }
764 H = ( 17*
H+16 ) >> 5;
765 V = ( 17*
V+16 ) >> 5;
766
768 for(j=8; j>0; --j) {
780 }
781 }
782
784 {
785 int j, k;
795
796 for (k = 2; k <= 4; ++k) {
800 }
801 for (; k <= 8; ++k) {
804 }
805
808
810 for(j=16; j>0; --j) {
822 }
823 }
824
825 #define SRC(x,y) src[(x)+(y)*stride]
827 const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2;
828 #define PREDICT_8x8_LOAD_LEFT \
829 const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \
830 + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \
831 PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \
832 const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2
833
835 const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
836 #define PREDICT_8x8_LOAD_TOP \
837 const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \
838 + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \
839 PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \
840 const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \
841 + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2
842
844 t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2;
845 #define PREDICT_8x8_LOAD_TOPRIGHT \
846 int t8, t9, t10, t11, t12, t13, t14, t15; \
847 if(has_topright) { \
848 PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \
849 t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \
850 } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1);
851
852 #define PREDICT_8x8_LOAD_TOPLEFT \
853 const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2
854
855 #define PREDICT_8x8_DC(v) \
856 int y; \
857 for( y = 0; y < 8; y++ ) { \
858 AV_WN4PA(((pixel4*)src)+0, v); \
859 AV_WN4PA(((pixel4*)src)+1, v); \
860 src += stride; \
861 }
862
864 int has_topright, ptrdiff_t
_stride)
865 {
868
870 }
872 int has_topright, ptrdiff_t
_stride)
873 {
876
880 }
882 int has_topright, ptrdiff_t
_stride)
883 {
886
890 }
892 int has_topright, ptrdiff_t
_stride)
893 {
896
902 }
904 int has_topright, ptrdiff_t
_stride)
905 {
909
911 #define ROW(y) a = PIXEL_SPLAT_X4(l##y); \
912 AV_WN4PA(src+y*stride, a); \
913 AV_WN4PA(src+y*stride+4, a);
915 #undef ROW
916 }
918 int has_topright, ptrdiff_t
_stride)
919 {
920 int y;
924
936 for( y = 1; y < 8; y++ ) {
939 }
940 }
942 int has_topright, ptrdiff_t
_stride)
943 {
960 SRC(5,7)=
SRC(6,6)=
SRC(7,5)= (
t12 + 2*t13 + t14 + 2) >> 2;
961 SRC(6,7)=
SRC(7,6)= (t13 + 2*t14 +
t15 + 2) >> 2;
962 SRC(7,7)= (t14 + 3*
t15 + 2) >> 2;
963 }
965 int has_topright, ptrdiff_t
_stride)
966 {
972 SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2;
973 SRC(0,6)=
SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2;
974 SRC(0,5)=
SRC(1,6)=
SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2;
975 SRC(0,4)=
SRC(1,5)=
SRC(2,6)=
SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2;
976 SRC(0,3)=
SRC(1,4)=
SRC(2,5)=
SRC(3,6)=
SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2;
987 }
989 int has_topright, ptrdiff_t
_stride)
990 {
996 SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2;
997 SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2;
998 SRC(0,4)=
SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2;
999 SRC(0,5)=
SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2;
1000 SRC(0,2)=
SRC(1,4)=
SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2;
1001 SRC(0,3)=
SRC(1,5)=
SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2;
1018 }
1020 int has_topright, ptrdiff_t
_stride)
1021 {
1027 SRC(0,7)= (l6 + l7 + 1) >> 1;
1028 SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2;
1029 SRC(0,6)=
SRC(2,7)= (l5 + l6 + 1) >> 1;
1030 SRC(1,6)=
SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2;
1031 SRC(0,5)=
SRC(2,6)=
SRC(4,7)= (l4 + l5 + 1) >> 1;
1032 SRC(1,5)=
SRC(3,6)=
SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2;
1033 SRC(0,4)=
SRC(2,5)=
SRC(4,6)=
SRC(6,7)= (l3 + l4 + 1) >> 1;
1034 SRC(1,4)=
SRC(3,5)=
SRC(5,6)=
SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2;
1035 SRC(0,3)=
SRC(2,4)=
SRC(4,5)=
SRC(6,6)= (l2 + l3 + 1) >> 1;
1036 SRC(1,3)=
SRC(3,4)=
SRC(5,5)=
SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2;
1037 SRC(0,2)=
SRC(2,3)=
SRC(4,4)=
SRC(6,5)= (l1 + l2 + 1) >> 1;
1038 SRC(1,2)=
SRC(3,3)=
SRC(5,4)=
SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2;
1039 SRC(0,1)=
SRC(2,2)=
SRC(4,3)=
SRC(6,4)= (l0 + l1 + 1) >> 1;
1040 SRC(1,1)=
SRC(3,2)=
SRC(5,3)=
SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2;
1041 SRC(0,0)=
SRC(2,1)=
SRC(4,2)=
SRC(6,3)= (lt + l0 + 1) >> 1;
1049 }
1051 int has_topright, ptrdiff_t
_stride)
1052 {
1079 }
1081 int has_topright, ptrdiff_t
_stride)
1082 {
1086 SRC(0,0)= (l0 + l1 + 1) >> 1;
1087 SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2;
1088 SRC(0,1)=
SRC(2,0)= (l1 + l2 + 1) >> 1;
1089 SRC(1,1)=
SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2;
1090 SRC(0,2)=
SRC(2,1)=
SRC(4,0)= (l2 + l3 + 1) >> 1;
1091 SRC(1,2)=
SRC(3,1)=
SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2;
1092 SRC(0,3)=
SRC(2,2)=
SRC(4,1)=
SRC(6,0)= (l3 + l4 + 1) >> 1;
1093 SRC(1,3)=
SRC(3,2)=
SRC(5,1)=
SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2;
1094 SRC(0,4)=
SRC(2,3)=
SRC(4,2)=
SRC(6,1)= (l4 + l5 + 1) >> 1;
1095 SRC(1,4)=
SRC(3,3)=
SRC(5,2)=
SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2;
1096 SRC(0,5)=
SRC(2,4)=
SRC(4,3)=
SRC(6,2)= (l5 + l6 + 1) >> 1;
1097 SRC(1,5)=
SRC(3,4)=
SRC(5,3)=
SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2;
1098 SRC(0,6)=
SRC(2,5)=
SRC(4,4)=
SRC(6,3)= (l6 + l7 + 1) >> 1;
1099 SRC(1,6)=
SRC(3,5)=
SRC(5,4)=
SRC(7,3)= (l6 + 3*l7 + 2) >> 2;
1104 }
1105
1107 int has_topright, ptrdiff_t
_stride)
1108 {
1115
1124
1137 }
1138
1139 memset(_block, 0,
sizeof(
dctcoef) * 64);
1140 }
1141
1143 int has_topright, ptrdiff_t
_stride)
1144 {
1151
1152 pix[0] = l0;
1153 pix[1] = l1;
1154 pix[2] = l2;
1155 pix[3] = l3;
1156 pix[4] = l4;
1157 pix[5] = l5;
1158 pix[6] = l6;
1159 pix[7] = l7;
1160
1173 }
1174
1175 memset(_block, 0,
sizeof(
dctcoef) * 64);
1176 }
1177
1178 #undef PREDICT_8x8_LOAD_LEFT
1179 #undef PREDICT_8x8_LOAD_TOP
1180 #undef PREDICT_8x8_LOAD_TOPLEFT
1181 #undef PREDICT_8x8_LOAD_TOPRIGHT
1182 #undef PREDICT_8x8_DC
1183 #undef PTR
1184 #undef PT
1185 #undef PL
1186 #undef SRC
1187
1190 {
1202 pix++;
1204 }
1205
1206 memset(_block, 0,
sizeof(
dctcoef) * 16);
1207 }
1208
1211 {
1218 pix[0]= v +=
block[0];
1219 pix[1]= v +=
block[1];
1220 pix[2]= v +=
block[2];
1221 pix[3]= v +
block[3];
1224 }
1225
1226 memset(_block, 0,
sizeof(
dctcoef) * 16);
1227 }
1228
1231 {
1247 pix++;
1249 }
1250
1251 memset(_block, 0,
sizeof(
dctcoef) * 64);
1252 }
1253
1256 {
1263 pix[0]= v +=
block[0];
1264 pix[1]= v +=
block[1];
1265 pix[2]= v +=
block[2];
1266 pix[3]= v +=
block[3];
1267 pix[4]= v +=
block[4];
1268 pix[5]= v +=
block[5];
1269 pix[6]= v +=
block[6];
1270 pix[7]= v +
block[7];
1273 }
1274
1275 memset(_block, 0,
sizeof(
dctcoef) * 64);
1276 }
1277
1281 {
1285 }
1286
1288 const int *block_offset,
1291 {
1295 }
1296
1299 {
1303 }
1304
1307 {
1313 }
1314
1318 {
1322 }
1323
1325 const int *block_offset,
1327 {
1333 }