version update
[goodguy/cinelerra.git] / cinelerra-5.1 / mpeg2enc / predict.c
1 /* predict.c, motion compensated prediction                                 */
2
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
5 /*
6  * Disclaimer of Warranty
7  *
8  * These software programs are available to the user without any license fee or
9  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10  * any and all warranties, whether express, implied, or statuary, including any
11  * implied warranties or merchantability or of fitness for a particular
12  * purpose.  In no event shall the copyright-holder be liable for any
13  * incidental, punitive, or consequential damages of any kind whatsoever
14  * arising from the use of these programs.
15  *
16  * This disclaimer of warranty extends to the user of these programs and user's
17  * customers, employees, agents, transferees, successors, and assigns.
18  *
19  * The MPEG Software Simulation Group does not represent or warrant that the
20  * programs furnished hereunder are free of infringement of any third-party
21  * patents.
22  *
23  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24  * are subject to royalty fees to patent holders.  Many of these patents are
25  * general enough such that they are unavoidable regardless of implementation
26  * design.
27  *
28  */
29
30 #include "config.h"
31 #include <stdio.h>
32 #include "global.h"
33 #include "cpu_accel.h"
34 #include "simd.h"
35
36
37 /* private prototypes */
38 static void predict_mb (
39         pict_data_s *picture,
40         uint8_t *oldref[], uint8_t *newref[], uint8_t *cur[],
41         int lx, int bx, int by, mbinfo_s *mbi, int secondfield);
42
43 static void pred (
44         pict_data_s *picture,
45         uint8_t *src[], int sfield,
46         uint8_t *dst[], int dfield,
47         int lx, int w, int h, int x, int y, int dx, int dy, int addflag);
48
49 static void pred_comp (
50         pict_data_s *picture,
51         uint8_t *src, uint8_t *dst,
52         int lx, int w, int h, int x, int y, int dx, int dy, int addflag);
53 #ifdef X86_CPU
54 static void pred_comp_mmxe(
55         pict_data_s *picture,
56         uint8_t *src, uint8_t *dst,
57         int lx, int w, int h, int x, int y, int dx, int dy, int addflag);
58 static void pred_comp_mmx(
59         pict_data_s *picture,
60         uint8_t *src, uint8_t *dst,
61         int lx, int w, int h, int x, int y, int dx, int dy, int addflag);
62 #endif
63 static void calc_DMV 
64         (       pict_data_s *picture,int DMV[][2], 
65                 int *dmvector, int mvx, int mvy);
66
67 static void clearblock (pict_data_s *picture,
68                                                 uint8_t *cur[], int i0, int j0);
69
70 /*
71   Initialise prediction - currently purely selection of which
72   versions of the various low level computation routines to use
73   
74   */
75
76 static void (*ppred_comp)(
77         pict_data_s *picture,
78         uint8_t *src, uint8_t *dst,
79         int lx, int w, int h, int x, int y, int dx, int dy, int addflag);
80
81 void init_predict_hv()
82 {
83         int cpucap = cpu_accel();
84
85         if( cpucap  == 0 )      /* No MMX/SSE etc support available */
86         {
87                 ppred_comp = pred_comp;
88         }
89
90 #ifdef X86_CPU
91         else if(cpucap & ACCEL_X86_MMXEXT ) /* AMD MMX or SSE... */
92         {
93                 if(verbose) fprintf( stderr, "SETTING EXTENDED MMX for PREDICTION!\n");
94                 ppred_comp = pred_comp_mmxe;
95         }
96     else if(cpucap & ACCEL_X86_MMX ) /* Original MMX... */
97         {
98                 if(verbose) fprintf( stderr, "SETTING MMX for PREDICTION!\n");
99                 ppred_comp = pred_comp_mmx;
100         }
101 #endif
102     else
103         {
104                 ppred_comp = pred_comp;
105         }
106 }
107
108 /* form prediction for a complete picture (frontend for predict_mb)
109  *
110  * reff: reference frame for forward prediction
111  * refb: reference frame for backward prediction
112  * cur:  destination (current) frame
113  * secondfield: predict second field of a frame
114  * mbi:  macroblock info
115  *
116  * Notes:
117  * - cf. predict_mb
118  */
119
120 void predict(pict_data_s *picture, 
121                          uint8_t *reff[],
122                          uint8_t *refb[],
123                          uint8_t *cur[3],
124                          int secondfield)
125 {
126         int i, j, k;
127         mbinfo_s *mbi = picture->mbinfo;
128         k = 0;
129
130         /* loop through all macroblocks of the picture */
131         for (j=0; j<height2; j+=16)
132                 for (i=0; i<width; i+=16)
133                 {
134                         predict_mb(picture,reff,refb,cur,width,i,j,
135                                            &mbi[k], secondfield );
136                         k++;
137                 }
138 }
139
140 /* form prediction for one macroblock
141  *
142  * oldref: reference frame for forward prediction
143  * newref: reference frame for backward prediction
144  * cur:    destination (current) frame
145  * lx:     frame width (identical to global var `width')
146  * bx,by:  picture (field or frame) coordinates of macroblock to be predicted
147  * pict_type: I, P or B
148  * pict_struct: FRAME_PICTURE, TOP_FIELD, BOTTOM_FIELD
149  * mb_type:     MB_FORWARD, MB_BACKWARD, MB_INTRA
150  * motion_type: MC_FRAME, MC_FIELD, MC_16X8, MC_DMV
151  * secondfield: predict second field of a frame
152  * PMV[2][2][2]: motion vectors (in half pel picture coordinates)
153  * mv_field_sel[2][2]: motion vertical field selects (for field predictions)
154  * dmvector: differential motion vectors (for dual prime)
155  *
156  * Notes:
157  * - when predicting a P type picture which is the second field of
158  *   a frame, the same parity reference field is in oldref, while the
159  *   opposite parity reference field is assumed to be in newref!
160  * - intra macroblocks are modelled to have a constant prediction of 128
161  *   for all pels; this results in a DC DCT coefficient symmetric to 0
162  * - vectors for field prediction in frame pictures are in half pel frame
163  *   coordinates (vertical component is twice the field value and always
164  *   even)
165  *
166  * already covers dual prime (not yet used)
167  */
168
169 static void predict_mb (
170         pict_data_s *picture,
171         uint8_t *oldref[], uint8_t *newref[], uint8_t *cur[],
172         int lx, int bx, int by, mbinfo_s *mbi,  int secondfield
173         )
174 {
175         int addflag, currentfield;
176         uint8_t **predframe;
177         int DMV[2][2];
178
179         if (mbi->mb_type&MB_INTRA)
180         {
181                 clearblock(picture,cur,bx,by);
182                 return;
183         }
184
185         addflag = 0; /* first prediction is stored, second is added and averaged */
186
187         if ((mbi->mb_type & MB_FORWARD) || (picture->pict_type==P_TYPE))
188         {
189                 /* forward prediction, including zero MV in P pictures */
190
191                 if (picture->pict_struct==FRAME_PICTURE)
192                 {
193                         /* frame picture */
194
195                         if ((mbi->motion_type==MC_FRAME) || !(mbi->mb_type & MB_FORWARD))
196                         {
197                                 /* frame-based prediction in frame picture */
198                                 pred(picture,
199                                          oldref,0,cur,0,
200                                          lx,16,16,bx,by,mbi->MV[0][0][0],mbi->MV[0][0][1],0);
201                         }
202                         else if (mbi->motion_type==MC_FIELD)
203                         {
204                                 /* field-based prediction in frame picture
205                                  *
206                                  * note scaling of the vertical coordinates (by, mbi->MV[][0][1])
207                                  * from frame to field!
208                                  */
209
210                                 /* top field prediction */
211                                 pred(picture,oldref,mbi->mv_field_sel[0][0],cur,0,
212                                          lx<<1,16,8,bx,by>>1,mbi->MV[0][0][0],mbi->MV[0][0][1]>>1,0);
213
214                                 /* bottom field prediction */
215                                 pred(picture,oldref,mbi->mv_field_sel[1][0],cur,1,
216                                          lx<<1,16,8,bx,by>>1,mbi->MV[1][0][0],mbi->MV[1][0][1]>>1,0);
217                         }
218                         else if (mbi->motion_type==MC_DMV)
219                         {
220                                 /* dual prime prediction */
221
222                                 /* calculate derived motion vectors */
223                                 calc_DMV(picture,DMV,mbi->dmvector,mbi->MV[0][0][0],mbi->MV[0][0][1]>>1);
224
225                                 /* predict top field from top field */
226                                 pred(picture,oldref,0,cur,0,
227                                          lx<<1,16,8,bx,by>>1,mbi->MV[0][0][0],mbi->MV[0][0][1]>>1,0);
228
229                                 /* predict bottom field from bottom field */
230                                 pred(picture,oldref,1,cur,1,
231                                          lx<<1,16,8,bx,by>>1,mbi->MV[0][0][0],mbi->MV[0][0][1]>>1,0);
232
233                                 /* predict and add to top field from bottom field */
234                                 pred(picture,oldref,1,cur,0,
235                                          lx<<1,16,8,bx,by>>1,DMV[0][0],DMV[0][1],1);
236
237                                 /* predict and add to bottom field from top field */
238                                 pred(picture,oldref,0,cur,1,
239                                          lx<<1,16,8,bx,by>>1,DMV[1][0],DMV[1][1],1);
240                         }
241                         else
242                         {
243                                 /* invalid mbi->motion_type in frame picture */
244                                 fprintf(stderr,"invalid motion_type\n");
245                         }
246                 }
247                 else /* TOP_FIELD or BOTTOM_FIELD */
248                 {
249                         /* field picture */
250
251                         currentfield = (picture->pict_struct==BOTTOM_FIELD);
252
253                         /* determine which frame to use for prediction */
254                         if ((picture->pict_type==P_TYPE) && secondfield
255                                 && (currentfield!=mbi->mv_field_sel[0][0]))
256                                 predframe = newref; /* same frame */
257                         else
258                                 predframe = oldref; /* previous frame */
259
260                         if ((mbi->motion_type==MC_FIELD) || !(mbi->mb_type & MB_FORWARD))
261                         {
262                                 /* field-based prediction in field picture */
263                                 pred(picture,predframe,mbi->mv_field_sel[0][0],cur,currentfield,
264                                          lx<<1,16,16,bx,by,mbi->MV[0][0][0],mbi->MV[0][0][1],0);
265                         }
266                         else if (mbi->motion_type==MC_16X8)
267                         {
268                                 /* 16 x 8 motion compensation in field picture */
269
270                                 /* upper half */
271                                 pred(picture,predframe,mbi->mv_field_sel[0][0],cur,currentfield,
272                                          lx<<1,16,8,bx,by,mbi->MV[0][0][0],mbi->MV[0][0][1],0);
273
274                                 /* determine which frame to use for lower half prediction */
275                                 if ((picture->pict_type==P_TYPE) && secondfield
276                                         && (currentfield!=mbi->mv_field_sel[1][0]))
277                                         predframe = newref; /* same frame */
278                                 else
279                                         predframe = oldref; /* previous frame */
280
281                                 /* lower half */
282                                 pred(picture,predframe,mbi->mv_field_sel[1][0],cur,currentfield,
283                                          lx<<1,16,8,bx,by+8,mbi->MV[1][0][0],mbi->MV[1][0][1],0);
284                         }
285                         else if (mbi->motion_type==MC_DMV)
286                         {
287                                 /* dual prime prediction */
288
289                                 /* determine which frame to use for prediction */
290                                 if (secondfield)
291                                         predframe = newref; /* same frame */
292                                 else
293                                         predframe = oldref; /* previous frame */
294
295                                 /* calculate derived motion vectors */
296                                 calc_DMV(picture,DMV,mbi->dmvector,mbi->MV[0][0][0],mbi->MV[0][0][1]);
297
298                                 /* predict from field of same parity */
299                                 pred(picture,oldref,currentfield,cur,currentfield,
300                                          lx<<1,16,16,bx,by,mbi->MV[0][0][0],mbi->MV[0][0][1],0);
301
302                                 /* predict from field of opposite parity */
303                                 pred(picture,predframe,!currentfield,cur,currentfield,
304                                          lx<<1,16,16,bx,by,DMV[0][0],DMV[0][1],1);
305                         }
306                         else
307                         {
308                                 /* invalid motion_type in field picture */
309                                 fprintf(stderr,"invalid motion_type\n");
310                         }
311                 }
312                 addflag = 1; /* next prediction (if any) will be averaged with this one */
313         }
314
315         if (mbi->mb_type & MB_BACKWARD)
316         {
317                 /* backward prediction */
318
319                 if (picture->pict_struct==FRAME_PICTURE)
320                 {
321                         /* frame picture */
322
323                         if (mbi->motion_type==MC_FRAME)
324                         {
325                                 /* frame-based prediction in frame picture */
326                                 pred(picture,newref,0,cur,0,
327                                          lx,16,16,bx,by,mbi->MV[0][1][0],mbi->MV[0][1][1],addflag);
328                         }
329                         else
330                         {
331                                 /* field-based prediction in frame picture
332                                  *
333                                  * note scaling of the vertical coordinates (by, mbi->MV[][1][1])
334                                  * from frame to field!
335                                  */
336
337                                 /* top field prediction */
338                                 pred(picture,newref,mbi->mv_field_sel[0][1],cur,0,
339                                          lx<<1,16,8,bx,by>>1,mbi->MV[0][1][0],mbi->MV[0][1][1]>>1,addflag);
340
341                                 /* bottom field prediction */
342                                 pred(picture,newref,mbi->mv_field_sel[1][1],cur,1,
343                                          lx<<1,16,8,bx,by>>1,mbi->MV[1][1][0],mbi->MV[1][1][1]>>1,addflag);
344                         }
345                 }
346                 else /* TOP_FIELD or BOTTOM_FIELD */
347                 {
348                         /* field picture */
349
350                         currentfield = (picture->pict_struct==BOTTOM_FIELD);
351
352                         if (mbi->motion_type==MC_FIELD)
353                         {
354                                 /* field-based prediction in field picture */
355                                 pred(picture,newref,mbi->mv_field_sel[0][1],cur,currentfield,
356                                          lx<<1,16,16,bx,by,mbi->MV[0][1][0],mbi->MV[0][1][1],addflag);
357                         }
358                         else if (mbi->motion_type==MC_16X8)
359                         {
360                                 /* 16 x 8 motion compensation in field picture */
361
362                                 /* upper half */
363                                 pred(picture,newref,mbi->mv_field_sel[0][1],cur,currentfield,
364                                          lx<<1,16,8,bx,by,mbi->MV[0][1][0],mbi->MV[0][1][1],addflag);
365
366                                 /* lower half */
367                                 pred(picture,newref,mbi->mv_field_sel[1][1],cur,currentfield,
368                                          lx<<1,16,8,bx,by+8,mbi->MV[1][1][0],mbi->MV[1][1][1],addflag);
369                         }
370                         else
371                         {
372                                 /* invalid motion_type in field picture */
373                                 fprintf(stderr,"invalid motion_type\n");
374                         }
375                 }
376         }
377 }
378
379 /* predict a rectangular block (all three components)
380  *
381  * src:     source frame (Y,U,V)
382  * sfield:  source field select (0: frame or top field, 1: bottom field)
383  * dst:     destination frame (Y,U,V)
384  * dfield:  destination field select (0: frame or top field, 1: bottom field)
385  *
386  * the following values are in luminance picture (frame or field) dimensions
387  * lx:      distance of vertically adjacent pels (selects frame or field pred.)
388  * w,h:     width and height of block (only 16x16 or 16x8 are used)
389  * x,y:     coordinates of destination block
390  * dx,dy:   half pel motion vector
391  * addflag: store or add (= average) prediction
392  */
393
394 static void pred (
395         pict_data_s *picture,
396         uint8_t *src[], int sfield,
397         uint8_t *dst[], int dfield,
398         int lx, int w, int h, int x, int y, int dx, int dy, int addflag
399         )
400 {
401         int cc;
402
403         for (cc=0; cc<3; cc++)
404         {
405                 if (cc==1)
406                 {
407                         /* scale for color components */
408                         if (chroma_format==CHROMA420)
409                         {
410                                 /* vertical */
411                                 h >>= 1; y >>= 1; dy /= 2;
412                         }
413                         if (chroma_format!=CHROMA444)
414                         {
415                                 /* horizontal */
416                                 w >>= 1; x >>= 1; dx /= 2;
417                                 lx >>= 1;
418                         }
419                 }
420                 (*ppred_comp)(  picture,
421                                                 src[cc]+(sfield?lx>>1:0),dst[cc]+(dfield?lx>>1:0),
422                                                 lx,w,h,x,y,dx,dy,addflag);
423         }
424 }
425
426 /* low level prediction routine
427  *
428  * src:     prediction source
429  * dst:     prediction destination
430  * lx:      line width (for both src and dst)
431  * x,y:     destination coordinates
432  * dx,dy:   half pel motion vector
433  * w,h:     size of prediction block
434  * addflag: store or add prediction
435  *
436  * There are also SIMD versions of this routine...
437  */
438
439 static void pred_comp(
440         pict_data_s *picture,
441         uint8_t *src,
442         uint8_t *dst,
443         int lx,
444         int w, int h,
445         int x, int y,
446         int dx, int dy,
447         int addflag)
448 {
449         int xint, xh, yint, yh;
450         int i, j;
451         uint8_t *s, *d;
452
453         /* half pel scaling */
454         xint = dx>>1; /* integer part */
455         xh = dx & 1;  /* half pel flag */
456         yint = dy>>1;
457         yh = dy & 1;
458
459         /* origins */
460         s = src + lx*(y+yint) + (x+xint); /* motion vector */
461         d = dst + lx*y + x;
462
463         if (!xh && !yh)
464                 if (addflag)
465                         for (j=0; j<h; j++)
466                         {
467                                 for (i=0; i<w; i++)
468                                         d[i] = (unsigned int)(d[i]+s[i]+1)>>1;
469                                 s+= lx;
470                                 d+= lx;
471                         }
472                 else
473                         for (j=0; j<h; j++)
474                         {
475                                 for (i=0; i<w; i++)
476                                         d[i] = s[i];
477                                 s+= lx;
478                                 d+= lx;
479                         }
480         else if (!xh && yh)
481                 if (addflag)
482                         for (j=0; j<h; j++)
483                         {
484                                 for (i=0; i<w; i++)
485                                         d[i] = (d[i] + ((unsigned int)(s[i]+s[i+lx]+1)>>1)+1)>>1;
486                                 s+= lx;
487                                 d+= lx;
488                         }
489                 else
490                         for (j=0; j<h; j++)
491                         {
492                                 for (i=0; i<w; i++)
493                                         d[i] = (unsigned int)(s[i]+s[i+lx]+1)>>1;
494                                 s+= lx;
495                                 d+= lx;
496                         }
497         else if (xh && !yh)
498                 if (addflag)
499                         for (j=0; j<h; j++)
500                         {
501                                 for (i=0; i<w; i++)
502                                         d[i] = (d[i] + ((unsigned int)(s[i]+s[i+1]+1)>>1)+1)>>1;
503                                 s+= lx;
504                                 d+= lx;
505                         }
506                 else
507                         for (j=0; j<h; j++)
508                         {
509                                 for (i=0; i<w; i++)
510                                         d[i] = (unsigned int)(s[i]+s[i+1]+1)>>1;
511                                 s+= lx;
512                                 d+= lx;
513                         }
514         else /* if (xh && yh) */
515                 if (addflag)
516                         for (j=0; j<h; j++)
517                         {
518                                 for (i=0; i<w; i++)
519                                         d[i] = (d[i] + ((unsigned int)(s[i]+s[i+1]+s[i+lx]+s[i+lx+1]+2)>>2)+1)>>1;
520                                 s+= lx;
521                                 d+= lx;
522                         }
523                 else
524                         for (j=0; j<h; j++)
525                         {
526                                 for (i=0; i<w; i++)
527                                         d[i] = (unsigned int)(s[i]+s[i+1]+s[i+lx]+s[i+lx+1]+2)>>2;
528                                 s+= lx;
529                                 d+= lx;
530                         }
531 }
532
533 #ifdef X86_CPU
534 static void pred_comp_mmxe(
535         pict_data_s *picture,
536         uint8_t *src,
537         uint8_t *dst,
538         int lx,
539         int w, int h,
540         int x, int y,
541         int dx, int dy,
542         int addflag)
543 {
544         int xint, xh, yint, yh;
545         uint8_t *s, *d;
546         
547         /* half pel scaling */
548         xint = dx>>1; /* integer part */
549         xh = dx & 1;  /* half pel flag */
550         yint = dy>>1;
551         yh = dy & 1;
552
553         /* origins */
554         s = src + lx*(y+yint) + (x+xint); /* motion vector */
555         d = dst + lx*y + x;
556
557         if( xh )
558         {
559                 if( yh ) 
560                         predcomp_11_mmxe(s,d,lx,w,h,addflag);
561                 else /* !yh */
562                         predcomp_10_mmxe(s,d,lx,w,h,addflag);
563         }
564         else /* !xh */
565         {
566                 if( yh ) 
567                         predcomp_01_mmxe(s,d,lx,w,h,addflag);
568                 else /* !yh */
569                         predcomp_00_mmxe(s,d,lx,w,h,addflag);
570         }
571                 
572 }
573
574 static void pred_comp_mmx(
575         pict_data_s *picture,
576         uint8_t *src,
577         uint8_t *dst,
578         int lx,
579         int w, int h,
580         int x, int y,
581         int dx, int dy,
582         int addflag)
583 {
584         int xint, xh, yint, yh;
585         uint8_t *s, *d;
586         
587         /* half pel scaling */
588         xint = dx>>1; /* integer part */
589         xh = dx & 1;  /* half pel flag */
590         yint = dy>>1;
591         yh = dy & 1;
592
593         /* origins */
594         s = src + lx*(y+yint) + (x+xint); /* motion vector */
595         d = dst + lx*y + x;
596
597         if( xh )
598         {
599                 if( yh ) 
600                         predcomp_11_mmx(s,d,lx,w,h,addflag);
601                 else /* !yh */
602                         predcomp_10_mmx(s,d,lx,w,h,addflag);
603         }
604         else /* !xh */
605         {
606                 if( yh ) 
607                         predcomp_01_mmx(s,d,lx,w,h,addflag);
608                 else /* !yh */
609                         predcomp_00_mmx(s,d,lx,w,h,addflag);
610         }
611                 
612 }
613 #endif
614
615 /* calculate derived motion vectors (DMV) for dual prime prediction
616  * dmvector[2]: differential motion vectors (-1,0,+1)
617  * mvx,mvy: motion vector (for same parity)
618  *
619  * DMV[2][2]: derived motion vectors (for opposite parity)
620  *
621  * uses global variables pict_struct and topfirst
622  *
623  * Notes:
624  *  - all vectors are in field coordinates (even for frame pictures)
625  */
626
627 static void calc_DMV(
628         pict_data_s *picture,int DMV[][2], 
629         int *dmvector, int mvx, int mvy
630 )
631 {
632   if (picture->pict_struct==FRAME_PICTURE)
633   {
634     if (picture->topfirst)
635     {
636       /* vector for prediction of top field from bottom field */
637       DMV[0][0] = ((mvx  +(mvx>0))>>1) + dmvector[0];
638       DMV[0][1] = ((mvy  +(mvy>0))>>1) + dmvector[1] - 1;
639
640       /* vector for prediction of bottom field from top field */
641       DMV[1][0] = ((3*mvx+(mvx>0))>>1) + dmvector[0];
642       DMV[1][1] = ((3*mvy+(mvy>0))>>1) + dmvector[1] + 1;
643     }
644     else
645     {
646       /* vector for prediction of top field from bottom field */
647       DMV[0][0] = ((3*mvx+(mvx>0))>>1) + dmvector[0];
648       DMV[0][1] = ((3*mvy+(mvy>0))>>1) + dmvector[1] - 1;
649
650       /* vector for prediction of bottom field from top field */
651       DMV[1][0] = ((mvx  +(mvx>0))>>1) + dmvector[0];
652       DMV[1][1] = ((mvy  +(mvy>0))>>1) + dmvector[1] + 1;
653     }
654   }
655   else
656   {
657     /* vector for prediction from field of opposite 'parity' */
658     DMV[0][0] = ((mvx+(mvx>0))>>1) + dmvector[0];
659     DMV[0][1] = ((mvy+(mvy>0))>>1) + dmvector[1];
660
661     /* correct for vertical field shift */
662     if (picture->pict_struct==TOP_FIELD)
663       DMV[0][1]--;
664     else
665       DMV[0][1]++;
666   }
667 }
668
669 static void clearblock(
670         pict_data_s *picture,
671         uint8_t *cur[], int i0, int j0
672         )
673 {
674   int i, j, w, h;
675   uint8_t *p;
676
677   p = cur[0] + ((picture->pict_struct==BOTTOM_FIELD) ? width : 0) + i0 + width2*j0;
678
679   for (j=0; j<16; j++)
680   {
681     for (i=0; i<16; i++)
682       p[i] = 128;
683     p+= width2;
684   }
685
686   w = h = 16;
687
688   if (chroma_format!=CHROMA444)
689   {
690     i0>>=1; w>>=1;
691   }
692
693   if (chroma_format==CHROMA420)
694   {
695     j0>>=1; h>>=1;
696   }
697
698   p = cur[1] + ((picture->pict_struct==BOTTOM_FIELD) ? chrom_width : 0) + i0
699              + chrom_width2*j0;
700
701   for (j=0; j<h; j++)
702   {
703     for (i=0; i<w; i++)
704       p[i] = 128;
705     p+= chrom_width2;
706   }
707
708   p = cur[2] + ((picture->pict_struct==BOTTOM_FIELD) ? chrom_width : 0) + i0
709              + chrom_width2*j0;
710
711   for (j=0; j<h; j++)
712   {
713     for (i=0; i<w; i++)
714       p[i] = 128;
715     p+= chrom_width2;
716   }
717 }