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