fb44046b2ebc807f77398b8244ba437a229f7911
[ffmpeg.git] / libavcodec / h264pred.c
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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 / MPEG4 part10 prediction functions.
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27
28 #include "h264pred.h"
29
30 #define BIT_DEPTH 8
31 #include "h264pred_template.c"
32 #undef BIT_DEPTH
33
34 #define BIT_DEPTH 9
35 #include "h264pred_template.c"
36 #undef BIT_DEPTH
37
38 #define BIT_DEPTH 10
39 #include "h264pred_template.c"
40 #undef BIT_DEPTH
41
42 static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
43     const unsigned lt = src[-1-1*stride];
44     LOAD_TOP_EDGE
45     LOAD_TOP_RIGHT_EDGE
46     uint32_t v = PACK_4U8((lt + 2*t0 + t1 + 2) >> 2,
47                           (t0 + 2*t1 + t2 + 2) >> 2,
48                           (t1 + 2*t2 + t3 + 2) >> 2,
49                           (t2 + 2*t3 + t4 + 2) >> 2);
50
51     AV_WN32A(src+0*stride, v);
52     AV_WN32A(src+1*stride, v);
53     AV_WN32A(src+2*stride, v);
54     AV_WN32A(src+3*stride, v);
55 }
56
57 static void pred4x4_horizontal_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
58     const unsigned lt = src[-1-1*stride];
59     LOAD_LEFT_EDGE
60
61     AV_WN32A(src+0*stride, ((lt + 2*l0 + l1 + 2) >> 2)*0x01010101);
62     AV_WN32A(src+1*stride, ((l0 + 2*l1 + l2 + 2) >> 2)*0x01010101);
63     AV_WN32A(src+2*stride, ((l1 + 2*l2 + l3 + 2) >> 2)*0x01010101);
64     AV_WN32A(src+3*stride, ((l2 + 2*l3 + l3 + 2) >> 2)*0x01010101);
65 }
66
67 static void pred4x4_down_left_svq3_c(uint8_t *src, const uint8_t *topright, int stride){
68     LOAD_TOP_EDGE
69     LOAD_LEFT_EDGE
70
71     src[0+0*stride]=(l1 + t1)>>1;
72     src[1+0*stride]=
73     src[0+1*stride]=(l2 + t2)>>1;
74     src[2+0*stride]=
75     src[1+1*stride]=
76     src[0+2*stride]=
77     src[3+0*stride]=
78     src[2+1*stride]=
79     src[1+2*stride]=
80     src[0+3*stride]=
81     src[3+1*stride]=
82     src[2+2*stride]=
83     src[1+3*stride]=
84     src[3+2*stride]=
85     src[2+3*stride]=
86     src[3+3*stride]=(l3 + t3)>>1;
87 }
88
89 static void pred4x4_down_left_rv40_c(uint8_t *src, const uint8_t *topright, int stride){
90     LOAD_TOP_EDGE
91     LOAD_TOP_RIGHT_EDGE
92     LOAD_LEFT_EDGE
93     LOAD_DOWN_LEFT_EDGE
94
95     src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3;
96     src[1+0*stride]=
97     src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3;
98     src[2+0*stride]=
99     src[1+1*stride]=
100     src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + l4 + 2*l3 + 2)>>3;
101     src[3+0*stride]=
102     src[2+1*stride]=
103     src[1+2*stride]=
104     src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3 + l5 + 2*l4 + 2)>>3;
105     src[3+1*stride]=
106     src[2+2*stride]=
107     src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l4 + l6 + 2*l5 + 2)>>3;
108     src[3+2*stride]=
109     src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l5 + l7 + 2*l6 + 2)>>3;
110     src[3+3*stride]=(t6 + t7 + 1 + l6 + l7 + 1)>>2;
111 }
112
113 static void pred4x4_down_left_rv40_nodown_c(uint8_t *src, const uint8_t *topright, int stride){
114     LOAD_TOP_EDGE
115     LOAD_TOP_RIGHT_EDGE
116     LOAD_LEFT_EDGE
117
118     src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3;
119     src[1+0*stride]=
120     src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3;
121     src[2+0*stride]=
122     src[1+1*stride]=
123     src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + 3*l3 + 2)>>3;
124     src[3+0*stride]=
125     src[2+1*stride]=
126     src[1+2*stride]=
127     src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3*4 + 2)>>3;
128     src[3+1*stride]=
129     src[2+2*stride]=
130     src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l3*4 + 2)>>3;
131     src[3+2*stride]=
132     src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l3*4 + 2)>>3;
133     src[3+3*stride]=(t6 + t7 + 1 + 2*l3 + 1)>>2;
134 }
135
136 static void pred4x4_vertical_left_rv40(uint8_t *src, const uint8_t *topright, int stride,
137                                        const int l0, const int l1, const int l2, const int l3, const int l4){
138     LOAD_TOP_EDGE
139     LOAD_TOP_RIGHT_EDGE
140
141     src[0+0*stride]=(2*t0 + 2*t1 + l1 + 2*l2 + l3 + 4)>>3;
142     src[1+0*stride]=
143     src[0+2*stride]=(t1 + t2 + 1)>>1;
144     src[2+0*stride]=
145     src[1+2*stride]=(t2 + t3 + 1)>>1;
146     src[3+0*stride]=
147     src[2+2*stride]=(t3 + t4+ 1)>>1;
148     src[3+2*stride]=(t4 + t5+ 1)>>1;
149     src[0+1*stride]=(t0 + 2*t1 + t2 + l2 + 2*l3 + l4 + 4)>>3;
150     src[1+1*stride]=
151     src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
152     src[2+1*stride]=
153     src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
154     src[3+1*stride]=
155     src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
156     src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
157 }
158
159 static void pred4x4_vertical_left_rv40_c(uint8_t *src, const uint8_t *topright, int stride){
160     LOAD_LEFT_EDGE
161     LOAD_DOWN_LEFT_EDGE
162
163     pred4x4_vertical_left_rv40(src, topright, stride, l0, l1, l2, l3, l4);
164 }
165
166 static void pred4x4_vertical_left_rv40_nodown_c(uint8_t *src, const uint8_t *topright, int stride){
167     LOAD_LEFT_EDGE
168
169     pred4x4_vertical_left_rv40(src, topright, stride, l0, l1, l2, l3, l3);
170 }
171
172 static void pred4x4_vertical_left_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
173     LOAD_TOP_EDGE
174     LOAD_TOP_RIGHT_EDGE
175
176     src[0+0*stride]=(t0 + t1 + 1)>>1;
177     src[1+0*stride]=
178     src[0+2*stride]=(t1 + t2 + 1)>>1;
179     src[2+0*stride]=
180     src[1+2*stride]=(t2 + t3 + 1)>>1;
181     src[3+0*stride]=
182     src[2+2*stride]=(t3 + t4 + 1)>>1;
183     src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
184     src[1+1*stride]=
185     src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
186     src[2+1*stride]=
187     src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
188     src[3+1*stride]=
189     src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
190     src[3+2*stride]=(t4 + 2*t5 + t6 + 2)>>2;
191     src[3+3*stride]=(t5 + 2*t6 + t7 + 2)>>2;
192 }
193
194 static void pred4x4_horizontal_up_rv40_c(uint8_t *src, const uint8_t *topright, int stride){
195     LOAD_LEFT_EDGE
196     LOAD_DOWN_LEFT_EDGE
197     LOAD_TOP_EDGE
198     LOAD_TOP_RIGHT_EDGE
199
200     src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;
201     src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;
202     src[2+0*stride]=
203     src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;
204     src[3+0*stride]=
205     src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;
206     src[2+1*stride]=
207     src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;
208     src[3+1*stride]=
209     src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;
210     src[3+2*stride]=
211     src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;
212     src[0+3*stride]=
213     src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;
214     src[2+3*stride]=(l4 + l5 + 1)>>1;
215     src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;
216 }
217
218 static void pred4x4_horizontal_up_rv40_nodown_c(uint8_t *src, const uint8_t *topright, int stride){
219     LOAD_LEFT_EDGE
220     LOAD_TOP_EDGE
221     LOAD_TOP_RIGHT_EDGE
222
223     src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;
224     src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;
225     src[2+0*stride]=
226     src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;
227     src[3+0*stride]=
228     src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;
229     src[2+1*stride]=
230     src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;
231     src[3+1*stride]=
232     src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;
233     src[3+2*stride]=
234     src[1+3*stride]=l3;
235     src[0+3*stride]=
236     src[2+2*stride]=(t6 + t7 + 2*l3 + 2)>>2;
237     src[2+3*stride]=
238     src[3+3*stride]=l3;
239 }
240
241 static void pred4x4_tm_vp8_c(uint8_t *src, const uint8_t *topright, int stride){
242     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP - src[-1-stride];
243     uint8_t *top = src-stride;
244     int y;
245
246     for (y = 0; y < 4; y++) {
247         uint8_t *cm_in = cm + src[-1];
248         src[0] = cm_in[top[0]];
249         src[1] = cm_in[top[1]];
250         src[2] = cm_in[top[2]];
251         src[3] = cm_in[top[3]];
252         src += stride;
253     }
254 }
255
256 static void pred16x16_plane_svq3_c(uint8_t *src, int stride){
257     pred16x16_plane_compat_8_c(src, stride, 1, 0);
258 }
259
260 static void pred16x16_plane_rv40_c(uint8_t *src, int stride){
261     pred16x16_plane_compat_8_c(src, stride, 0, 1);
262 }
263
264 static void pred16x16_tm_vp8_c(uint8_t *src, int stride){
265     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP - src[-1-stride];
266     uint8_t *top = src-stride;
267     int y;
268
269     for (y = 0; y < 16; y++) {
270         uint8_t *cm_in = cm + src[-1];
271         src[0]  = cm_in[top[0]];
272         src[1]  = cm_in[top[1]];
273         src[2]  = cm_in[top[2]];
274         src[3]  = cm_in[top[3]];
275         src[4]  = cm_in[top[4]];
276         src[5]  = cm_in[top[5]];
277         src[6]  = cm_in[top[6]];
278         src[7]  = cm_in[top[7]];
279         src[8]  = cm_in[top[8]];
280         src[9]  = cm_in[top[9]];
281         src[10] = cm_in[top[10]];
282         src[11] = cm_in[top[11]];
283         src[12] = cm_in[top[12]];
284         src[13] = cm_in[top[13]];
285         src[14] = cm_in[top[14]];
286         src[15] = cm_in[top[15]];
287         src += stride;
288     }
289 }
290
291 static void pred8x8_left_dc_rv40_c(uint8_t *src, int stride){
292     int i;
293     unsigned dc0;
294
295     dc0=0;
296     for(i=0;i<8; i++)
297         dc0+= src[-1+i*stride];
298     dc0= 0x01010101*((dc0 + 4)>>3);
299
300     for(i=0; i<8; i++){
301         ((uint32_t*)(src+i*stride))[0]=
302         ((uint32_t*)(src+i*stride))[1]= dc0;
303     }
304 }
305
306 static void pred8x8_top_dc_rv40_c(uint8_t *src, int stride){
307     int i;
308     unsigned dc0;
309
310     dc0=0;
311     for(i=0;i<8; i++)
312         dc0+= src[i-stride];
313     dc0= 0x01010101*((dc0 + 4)>>3);
314
315     for(i=0; i<8; i++){
316         ((uint32_t*)(src+i*stride))[0]=
317         ((uint32_t*)(src+i*stride))[1]= dc0;
318     }
319 }
320
321 static void pred8x8_dc_rv40_c(uint8_t *src, int stride){
322     int i;
323     unsigned dc0 = 0;
324
325     for(i=0;i<4; i++){
326         dc0+= src[-1+i*stride] + src[i-stride];
327         dc0+= src[4+i-stride];
328         dc0+= src[-1+(i+4)*stride];
329     }
330     dc0= 0x01010101*((dc0 + 8)>>4);
331
332     for(i=0; i<4; i++){
333         ((uint32_t*)(src+i*stride))[0]= dc0;
334         ((uint32_t*)(src+i*stride))[1]= dc0;
335     }
336     for(i=4; i<8; i++){
337         ((uint32_t*)(src+i*stride))[0]= dc0;
338         ((uint32_t*)(src+i*stride))[1]= dc0;
339     }
340 }
341
342 static void pred8x8_tm_vp8_c(uint8_t *src, int stride){
343     uint8_t *cm = ff_cropTbl + MAX_NEG_CROP - src[-1-stride];
344     uint8_t *top = src-stride;
345     int y;
346
347     for (y = 0; y < 8; y++) {
348         uint8_t *cm_in = cm + src[-1];
349         src[0] = cm_in[top[0]];
350         src[1] = cm_in[top[1]];
351         src[2] = cm_in[top[2]];
352         src[3] = cm_in[top[3]];
353         src[4] = cm_in[top[4]];
354         src[5] = cm_in[top[5]];
355         src[6] = cm_in[top[6]];
356         src[7] = cm_in[top[7]];
357         src += stride;
358     }
359 }
360
361 /**
362  * Set the intra prediction function pointers.
363  */
364 void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc){
365 //    MpegEncContext * const s = &h->s;
366
367 #undef FUNC
368 #undef FUNCC
369 #define FUNC(a, depth) a ## _ ## depth
370 #define FUNCC(a, depth) a ## _ ## depth ## _c
371 #define FUNCD(a) a ## _c
372
373 #define H264_PRED(depth) \
374     if(codec_id != AV_CODEC_ID_RV40){\
375         if(codec_id == AV_CODEC_ID_VP8) {\
376             h->pred4x4[VERT_PRED       ]= FUNCD(pred4x4_vertical_vp8);\
377             h->pred4x4[HOR_PRED        ]= FUNCD(pred4x4_horizontal_vp8);\
378         } else {\
379             h->pred4x4[VERT_PRED       ]= FUNCC(pred4x4_vertical          , depth);\
380             h->pred4x4[HOR_PRED        ]= FUNCC(pred4x4_horizontal        , depth);\
381         }\
382         h->pred4x4[DC_PRED             ]= FUNCC(pred4x4_dc                , depth);\
383         if(codec_id == AV_CODEC_ID_SVQ3)\
384             h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_svq3);\
385         else\
386             h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred4x4_down_left     , depth);\
387         h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right        , depth);\
388         h->pred4x4[VERT_RIGHT_PRED     ]= FUNCC(pred4x4_vertical_right    , depth);\
389         h->pred4x4[HOR_DOWN_PRED       ]= FUNCC(pred4x4_horizontal_down   , depth);\
390         if (codec_id == AV_CODEC_ID_VP8) {\
391             h->pred4x4[VERT_LEFT_PRED  ]= FUNCD(pred4x4_vertical_left_vp8);\
392         } else\
393             h->pred4x4[VERT_LEFT_PRED  ]= FUNCC(pred4x4_vertical_left     , depth);\
394         h->pred4x4[HOR_UP_PRED         ]= FUNCC(pred4x4_horizontal_up     , depth);\
395         if(codec_id != AV_CODEC_ID_VP8) {\
396             h->pred4x4[LEFT_DC_PRED    ]= FUNCC(pred4x4_left_dc           , depth);\
397             h->pred4x4[TOP_DC_PRED     ]= FUNCC(pred4x4_top_dc            , depth);\
398             h->pred4x4[DC_128_PRED     ]= FUNCC(pred4x4_128_dc            , depth);\
399         } else {\
400             h->pred4x4[TM_VP8_PRED     ]= FUNCD(pred4x4_tm_vp8);\
401             h->pred4x4[DC_127_PRED     ]= FUNCC(pred4x4_127_dc            , depth);\
402             h->pred4x4[DC_129_PRED     ]= FUNCC(pred4x4_129_dc            , depth);\
403             h->pred4x4[VERT_VP8_PRED   ]= FUNCC(pred4x4_vertical          , depth);\
404             h->pred4x4[HOR_VP8_PRED    ]= FUNCC(pred4x4_horizontal        , depth);\
405         }\
406     }else{\
407         h->pred4x4[VERT_PRED           ]= FUNCC(pred4x4_vertical          , depth);\
408         h->pred4x4[HOR_PRED            ]= FUNCC(pred4x4_horizontal        , depth);\
409         h->pred4x4[DC_PRED             ]= FUNCC(pred4x4_dc                , depth);\
410         h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_rv40);\
411         h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right        , depth);\
412         h->pred4x4[VERT_RIGHT_PRED     ]= FUNCC(pred4x4_vertical_right    , depth);\
413         h->pred4x4[HOR_DOWN_PRED       ]= FUNCC(pred4x4_horizontal_down   , depth);\
414         h->pred4x4[VERT_LEFT_PRED      ]= FUNCD(pred4x4_vertical_left_rv40);\
415         h->pred4x4[HOR_UP_PRED         ]= FUNCD(pred4x4_horizontal_up_rv40);\
416         h->pred4x4[LEFT_DC_PRED        ]= FUNCC(pred4x4_left_dc           , depth);\
417         h->pred4x4[TOP_DC_PRED         ]= FUNCC(pred4x4_top_dc            , depth);\
418         h->pred4x4[DC_128_PRED         ]= FUNCC(pred4x4_128_dc            , depth);\
419         h->pred4x4[DIAG_DOWN_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_down_left_rv40_nodown);\
420         h->pred4x4[HOR_UP_PRED_RV40_NODOWN]= FUNCD(pred4x4_horizontal_up_rv40_nodown);\
421         h->pred4x4[VERT_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_vertical_left_rv40_nodown);\
422     }\
423 \
424     h->pred8x8l[VERT_PRED           ]= FUNCC(pred8x8l_vertical            , depth);\
425     h->pred8x8l[HOR_PRED            ]= FUNCC(pred8x8l_horizontal          , depth);\
426     h->pred8x8l[DC_PRED             ]= FUNCC(pred8x8l_dc                  , depth);\
427     h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred8x8l_down_left           , depth);\
428     h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred8x8l_down_right          , depth);\
429     h->pred8x8l[VERT_RIGHT_PRED     ]= FUNCC(pred8x8l_vertical_right      , depth);\
430     h->pred8x8l[HOR_DOWN_PRED       ]= FUNCC(pred8x8l_horizontal_down     , depth);\
431     h->pred8x8l[VERT_LEFT_PRED      ]= FUNCC(pred8x8l_vertical_left       , depth);\
432     h->pred8x8l[HOR_UP_PRED         ]= FUNCC(pred8x8l_horizontal_up       , depth);\
433     h->pred8x8l[LEFT_DC_PRED        ]= FUNCC(pred8x8l_left_dc             , depth);\
434     h->pred8x8l[TOP_DC_PRED         ]= FUNCC(pred8x8l_top_dc              , depth);\
435     h->pred8x8l[DC_128_PRED         ]= FUNCC(pred8x8l_128_dc              , depth);\
436 \
437     if (chroma_format_idc == 1) {\
438         h->pred8x8[VERT_PRED8x8   ]= FUNCC(pred8x8_vertical               , depth);\
439         h->pred8x8[HOR_PRED8x8    ]= FUNCC(pred8x8_horizontal             , depth);\
440     } else {\
441         h->pred8x8[VERT_PRED8x8   ]= FUNCC(pred8x16_vertical              , depth);\
442         h->pred8x8[HOR_PRED8x8    ]= FUNCC(pred8x16_horizontal            , depth);\
443     }\
444     if (codec_id != AV_CODEC_ID_VP8) {\
445         if (chroma_format_idc == 1) {\
446             h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x8_plane                , depth);\
447         } else {\
448             h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x16_plane               , depth);\
449         }\
450     } else\
451         h->pred8x8[PLANE_PRED8x8]= FUNCD(pred8x8_tm_vp8);\
452     if(codec_id != AV_CODEC_ID_RV40 && codec_id != AV_CODEC_ID_VP8){\
453         if (chroma_format_idc == 1) {\
454             h->pred8x8[DC_PRED8x8     ]= FUNCC(pred8x8_dc                     , depth);\
455             h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x8_left_dc                , depth);\
456             h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x8_top_dc                 , depth);\
457             h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l0t, depth);\
458             h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0lt, depth);\
459             h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l00, depth);\
460             h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0l0, depth);\
461         } else {\
462             h->pred8x8[DC_PRED8x8     ]= FUNCC(pred8x16_dc                    , depth);\
463             h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x16_left_dc               , depth);\
464             h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x16_top_dc                , depth);\
465             h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l0t, depth);\
466             h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0lt, depth);\
467             h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l00, depth);\
468             h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0l0, depth);\
469         }\
470     }else{\
471         h->pred8x8[DC_PRED8x8     ]= FUNCD(pred8x8_dc_rv40);\
472         h->pred8x8[LEFT_DC_PRED8x8]= FUNCD(pred8x8_left_dc_rv40);\
473         h->pred8x8[TOP_DC_PRED8x8 ]= FUNCD(pred8x8_top_dc_rv40);\
474         if (codec_id == AV_CODEC_ID_VP8) {\
475             h->pred8x8[DC_127_PRED8x8]= FUNCC(pred8x8_127_dc              , depth);\
476             h->pred8x8[DC_129_PRED8x8]= FUNCC(pred8x8_129_dc              , depth);\
477         }\
478     }\
479     if (chroma_format_idc == 1) {\
480         h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x8_128_dc                 , depth);\
481     } else {\
482         h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x16_128_dc                , depth);\
483     }\
484 \
485     h->pred16x16[DC_PRED8x8     ]= FUNCC(pred16x16_dc                     , depth);\
486     h->pred16x16[VERT_PRED8x8   ]= FUNCC(pred16x16_vertical               , depth);\
487     h->pred16x16[HOR_PRED8x8    ]= FUNCC(pred16x16_horizontal             , depth);\
488     switch(codec_id){\
489     case AV_CODEC_ID_SVQ3:\
490        h->pred16x16[PLANE_PRED8x8  ]= FUNCD(pred16x16_plane_svq3);\
491        break;\
492     case AV_CODEC_ID_RV40:\
493        h->pred16x16[PLANE_PRED8x8  ]= FUNCD(pred16x16_plane_rv40);\
494        break;\
495     case AV_CODEC_ID_VP8:\
496        h->pred16x16[PLANE_PRED8x8  ]= FUNCD(pred16x16_tm_vp8);\
497        h->pred16x16[DC_127_PRED8x8]= FUNCC(pred16x16_127_dc               , depth);\
498        h->pred16x16[DC_129_PRED8x8]= FUNCC(pred16x16_129_dc               , depth);\
499        break;\
500     default:\
501        h->pred16x16[PLANE_PRED8x8  ]= FUNCC(pred16x16_plane               , depth);\
502        break;\
503     }\
504     h->pred16x16[LEFT_DC_PRED8x8]= FUNCC(pred16x16_left_dc                , depth);\
505     h->pred16x16[TOP_DC_PRED8x8 ]= FUNCC(pred16x16_top_dc                 , depth);\
506     h->pred16x16[DC_128_PRED8x8 ]= FUNCC(pred16x16_128_dc                 , depth);\
507 \
508     /* special lossless h/v prediction for h264 */ \
509     h->pred4x4_add  [VERT_PRED   ]= FUNCC(pred4x4_vertical_add            , depth);\
510     h->pred4x4_add  [ HOR_PRED   ]= FUNCC(pred4x4_horizontal_add          , depth);\
511     h->pred8x8l_add [VERT_PRED   ]= FUNCC(pred8x8l_vertical_add           , depth);\
512     h->pred8x8l_add [ HOR_PRED   ]= FUNCC(pred8x8l_horizontal_add         , depth);\
513     if (chroma_format_idc == 1) {\
514     h->pred8x8_add  [VERT_PRED8x8]= FUNCC(pred8x8_vertical_add            , depth);\
515     h->pred8x8_add  [ HOR_PRED8x8]= FUNCC(pred8x8_horizontal_add          , depth);\
516     } else {\
517         h->pred8x8_add  [VERT_PRED8x8]= FUNCC(pred8x16_vertical_add            , depth);\
518         h->pred8x8_add  [ HOR_PRED8x8]= FUNCC(pred8x16_horizontal_add          , depth);\
519     }\
520     h->pred16x16_add[VERT_PRED8x8]= FUNCC(pred16x16_vertical_add          , depth);\
521     h->pred16x16_add[ HOR_PRED8x8]= FUNCC(pred16x16_horizontal_add        , depth);\
522
523     switch (bit_depth) {
524         case 9:
525             H264_PRED(9)
526             break;
527         case 10:
528             H264_PRED(10)
529             break;
530         default:
531             H264_PRED(8)
532             break;
533     }
534
535     if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id, bit_depth, chroma_format_idc);
536     if (ARCH_X86) ff_h264_pred_init_x86(h, codec_id, bit_depth, chroma_format_idc);
537 }