]> git.sesse.net Git - vlc/blob - modules/codec/libmpeg2.c
* include/vlc_block.h, modules/codec/libmpeg2.c: re-added the discontinuity flag...
[vlc] / modules / codec / libmpeg2.c
1 /*****************************************************************************
2  * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: libmpeg2.c,v 1.28 2003/09/30 20:23:03 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/vout.h>
30 #include <vlc/input.h>
31 #include <vlc/decoder.h>
32
33 #include <stdlib.h>                                      /* malloc(), free() */
34 #include <string.h>                                    /* memcpy(), memset() */
35
36 #include <mpeg2dec/mpeg2.h>
37
38 #include "vout_synchro.h"
39
40 /* Aspect ratio (ISO/IEC 13818-2 section 6.3.3, table 6-3) */
41 #define AR_SQUARE_PICTURE       1                           /* square pixels */
42 #define AR_3_4_PICTURE          2                        /* 3:4 picture (TV) */
43 #define AR_16_9_PICTURE         3              /* 16:9 picture (wide screen) */
44 #define AR_221_1_PICTURE        4                  /* 2.21:1 picture (movie) */
45
46 /*****************************************************************************
47  * decoder_sys_t : libmpeg2 decoder descriptor
48  *****************************************************************************/
49 struct decoder_sys_t
50 {
51     /*
52      * libmpeg2 properties
53      */
54     mpeg2dec_t          *p_mpeg2dec;
55     const mpeg2_info_t  *p_info;
56     vlc_bool_t          b_skip;
57
58     /*
59      * Input properties
60      */
61     pes_packet_t     *p_pes;                  /* current PES we are decoding */
62     mtime_t          i_pts;
63     mtime_t          i_previous_pts;
64     mtime_t          i_current_pts;
65     mtime_t          i_period_remainder;
66     int              i_current_rate;
67     picture_t *      p_picture_to_destroy;
68     vlc_bool_t       b_garbage_pic;
69     vlc_bool_t       b_after_sequence_header; /* is it the next frame after
70                                                * the sequence header ?    */
71     vlc_bool_t       b_slice_i;             /* intra-slice refresh stream */
72
73     /*
74      * Output properties
75      */
76     vout_thread_t *p_vout;
77     vout_synchro_t *p_synchro;
78
79 };
80
81 /*****************************************************************************
82  * Local prototypes
83  *****************************************************************************/
84 static int  OpenDecoder  ( vlc_object_t * );
85 static int  InitDecoder  ( decoder_t * );
86 static int  RunDecoder   ( decoder_t *, block_t * );
87 static int  EndDecoder   ( decoder_t * );
88
89 static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
90
91 /*****************************************************************************
92  * Module descriptor
93  *****************************************************************************/
94 vlc_module_begin();
95     set_description( _("MPEG I/II video decoder (using libmpeg2)") );
96     set_capability( "decoder", 150 );
97     set_callbacks( OpenDecoder, NULL );
98     add_shortcut( "libmpeg2" );
99 vlc_module_end();
100
101 /*****************************************************************************
102  * OpenDecoder: probe the decoder and return score
103  *****************************************************************************/
104 static int OpenDecoder( vlc_object_t *p_this )
105 {
106     decoder_t *p_dec = (decoder_t*)p_this;
107
108     if( p_dec->p_fifo->i_fourcc != VLC_FOURCC('m','p','g','v') &&
109         p_dec->p_fifo->i_fourcc != VLC_FOURCC('m','p','g','1') &&
110         p_dec->p_fifo->i_fourcc != VLC_FOURCC('m','p','g','2') )
111     {
112         return VLC_EGENERIC;
113     }
114
115     p_dec->pf_init = InitDecoder;
116     p_dec->pf_decode = RunDecoder;
117     p_dec->pf_end = EndDecoder;
118
119     return VLC_SUCCESS;
120 }
121
122 /*****************************************************************************
123  * InitDecoder: Initalize the decoder
124  *****************************************************************************/
125 static int InitDecoder( decoder_t *p_dec )
126 {
127     /* Allocate the memory needed to store the decoder's structure */
128     if( ( p_dec->p_sys =
129           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
130     {
131         msg_Err( p_dec, "out of memory" );
132         return VLC_EGENERIC;
133     }
134
135     /* Initialize the thread properties */
136     memset( p_dec->p_sys, 0, sizeof(decoder_sys_t) );
137     p_dec->p_sys->p_pes      = NULL;
138     p_dec->p_sys->p_vout     = NULL;
139     p_dec->p_sys->p_mpeg2dec = NULL;
140     p_dec->p_sys->p_synchro  = NULL;
141     p_dec->p_sys->p_info     = NULL;
142     p_dec->p_sys->i_pts      = mdate() + DEFAULT_PTS_DELAY;
143     p_dec->p_sys->i_current_pts  = 0;
144     p_dec->p_sys->i_previous_pts = 0;
145     p_dec->p_sys->i_period_remainder = 0;
146     p_dec->p_sys->p_picture_to_destroy = NULL;
147     p_dec->p_sys->b_garbage_pic = 0;
148     p_dec->p_sys->b_slice_i  = 0;
149     p_dec->p_sys->b_skip     = 0;
150
151     /* Initialize decoder */
152     p_dec->p_sys->p_mpeg2dec = mpeg2_init();
153     if( p_dec->p_sys->p_mpeg2dec == NULL)
154     {
155         msg_Err( p_dec, "mpeg2_init() failed" );
156         free( p_dec->p_sys );
157         return VLC_EGENERIC;
158     }
159
160     p_dec->p_sys->p_info = mpeg2_info( p_dec->p_sys->p_mpeg2dec );
161
162     return VLC_SUCCESS;
163 }
164
165 /*****************************************************************************
166  * RunDecoder: the libmpeg2 decoder
167  *****************************************************************************/
168 static int RunDecoder( decoder_t *p_dec, block_t *p_block )
169 {
170     decoder_sys_t   *p_sys = p_dec->p_sys;
171     mpeg2_state_t   state;
172     picture_t       *p_pic;
173     int             i_aspect;
174
175     vlc_bool_t      b_need_more_data = VLC_FALSE;
176
177     while( 1 )
178     {
179         if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
180         {
181             block_Release( p_block );
182             return VLC_EGENERIC;
183         }
184
185         state = mpeg2_parse( p_sys->p_mpeg2dec );
186
187         switch( state )
188         {
189         case STATE_BUFFER:
190             if( !p_block->i_buffer || b_need_more_data )
191             {
192                 block_Release( p_block );
193                 return VLC_SUCCESS;
194             }
195
196             if( p_block->b_discontinuity && p_sys->p_synchro 
197                 && p_sys->p_info->sequence->width != (unsigned)-1 )
198             {
199                 vout_SynchroReset( p_sys->p_synchro );
200                 if( p_sys->p_info->current_fbuf != NULL
201                     && p_sys->p_info->current_fbuf->id != NULL )
202                 {
203                     p_sys->b_garbage_pic = 1;
204                     p_pic = p_sys->p_info->current_fbuf->id;
205                 }
206                 else
207                 {
208                     uint8_t *buf[3];
209                     buf[0] = buf[1] = buf[2] = NULL;
210                     if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
211                         break;
212                     mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
213                 }
214                 p_sys->p_picture_to_destroy = p_pic;
215
216                 memset( p_pic->p[0].p_pixels, 0,
217                         p_sys->p_info->sequence->width
218                          * p_sys->p_info->sequence->height );
219                 memset( p_pic->p[1].p_pixels, 0x80,
220                         p_sys->p_info->sequence->width
221                          * p_sys->p_info->sequence->height / 4 );
222                 memset( p_pic->p[2].p_pixels, 0x80,
223                         p_sys->p_info->sequence->width
224                          * p_sys->p_info->sequence->height / 4 );
225
226                 if ( p_sys->b_slice_i )
227                 {
228                     vout_SynchroNewPicture( p_sys->p_synchro,
229                         I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
230                     vout_SynchroDecode( p_sys->p_synchro );
231                     vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
232                 }
233             }
234
235             if( p_block->i_pts )
236             {
237                 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
238                 p_sys->i_previous_pts = p_sys->i_current_pts;
239                 p_sys->i_current_pts = p_block->i_pts;
240             }
241
242             p_sys->i_current_rate = DEFAULT_RATE;//p_pes->i_rate;
243
244             mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
245                           p_block->p_buffer + p_block->i_buffer );
246
247             b_need_more_data = VLC_TRUE;
248             break;
249
250         case STATE_SEQUENCE:
251         {
252             /* Initialize video output */
253             uint8_t *buf[3];
254             buf[0] = buf[1] = buf[2] = NULL;
255
256             /* Check whether the input gives a particular aspect ratio */
257             if( p_dec->p_fifo->p_demux_data
258                 && ( *(int*)(p_dec->p_fifo->p_demux_data) & 0x7 ) )
259             {
260                 i_aspect = *(int*)(p_dec->p_fifo->p_demux_data);
261                 switch( i_aspect )
262                 {
263                 case AR_3_4_PICTURE:
264                     i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
265                     break;
266                 case AR_16_9_PICTURE:
267                     i_aspect = VOUT_ASPECT_FACTOR * 16 / 9;
268                     break;
269                 case AR_221_1_PICTURE:
270                     i_aspect = VOUT_ASPECT_FACTOR * 221 / 100;
271                     break;
272                 case AR_SQUARE_PICTURE:
273                 default:
274                     i_aspect = VOUT_ASPECT_FACTOR *
275                                    p_sys->p_info->sequence->width /
276                                    p_sys->p_info->sequence->height;
277                     break;
278                 }
279             }
280             else
281             {
282                 /* Use the value provided in the MPEG sequence header */
283                 i_aspect = ((uint64_t)p_sys->p_info->sequence->display_width) *
284                     p_sys->p_info->sequence->pixel_width * VOUT_ASPECT_FACTOR /
285                     p_sys->p_info->sequence->display_height /
286                     p_sys->p_info->sequence->pixel_height;
287             }
288
289             if ( p_dec->p_sys->p_vout != NULL )
290             {
291               int i_pic;
292                 /* Temporary hack to free the pictures in use by libmpeg2 */
293                 for ( i_pic = 0; i_pic < p_dec->p_sys->p_vout->render.i_pictures; i_pic++ )
294                 {
295                     if( p_dec->p_sys->p_vout->render.pp_picture[i_pic]->i_status ==
296                           RESERVED_PICTURE )
297                         vout_DestroyPicture( p_dec->p_sys->p_vout,
298                                          p_dec->p_sys->p_vout->render.pp_picture[i_pic] );
299                     if( p_dec->p_sys->p_vout->render.pp_picture[i_pic]->i_refcount > 0 )
300                         vout_UnlinkPicture( p_dec->p_sys->p_vout,
301                                          p_dec->p_sys->p_vout->render.pp_picture[i_pic] );
302                 }
303             }
304
305             p_sys->p_vout = vout_Request( p_dec, p_sys->p_vout,
306                                           p_sys->p_info->sequence->width,
307                                           p_sys->p_info->sequence->height,
308                                           VLC_FOURCC('Y','V','1','2'),
309                                           i_aspect );
310
311             if(p_sys->p_vout == NULL )
312             {
313                 msg_Err( p_dec, "cannot create vout" );
314                 block_Release( p_block );
315                 return -1;
316             } 
317
318             msg_Dbg( p_dec, "%dx%d, aspect %d, %u.%03u fps",
319                      p_sys->p_info->sequence->width,
320                      p_sys->p_info->sequence->height, i_aspect,
321                      (uint32_t)((u64)1001000000 * 27 /
322                      p_sys->p_info->sequence->frame_period / 1001),
323                      (uint32_t)((u64)1001000000 * 27 /
324                      p_sys->p_info->sequence->frame_period % 1001) );
325
326             mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
327
328             /* Set the first 2 reference frames */
329             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
330
331             if( (p_pic = GetNewPicture( p_dec, buf )) == NULL ) break;
332             memset( p_pic->p[0].p_pixels, 0,
333                     p_sys->p_info->sequence->width
334                      * p_sys->p_info->sequence->height );
335             memset( p_pic->p[1].p_pixels, 0x80,
336                     p_sys->p_info->sequence->width
337                      * p_sys->p_info->sequence->height / 4 );
338             memset( p_pic->p[2].p_pixels, 0x80,
339                     p_sys->p_info->sequence->width
340                      * p_sys->p_info->sequence->height / 4 );
341             mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
342             /* This picture will never go through display_picture. */
343             vout_DatePicture( p_sys->p_vout, p_pic, 0 );
344             vout_DisplayPicture( p_sys->p_vout, p_pic );
345             /* For some reason, libmpeg2 will put this pic twice in
346              * discard_picture. This can be considered a bug in libmpeg2. */
347             vout_LinkPicture( p_sys->p_vout, p_pic );
348
349             if ( p_sys->p_synchro )
350             {
351                 vout_SynchroRelease( p_sys->p_synchro );
352             }
353             p_sys->p_synchro = vout_SynchroInit( p_dec, p_sys->p_vout,
354                 (uint32_t)((uint64_t)1001000000 * 27 /
355                 p_sys->p_info->sequence->frame_period) );
356             p_sys->b_after_sequence_header = 1;
357         }
358         break;
359
360         case STATE_PICTURE_2ND:
361             vout_SynchroNewPicture( p_sys->p_synchro,
362                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
363                 p_sys->p_info->current_picture->nb_fields,
364                 0, 0,
365                 p_sys->i_current_rate );
366
367             if ( p_sys->b_skip )
368             {
369                 vout_SynchroTrash( p_sys->p_synchro );
370             }
371             else
372             {
373                 vout_SynchroDecode( p_sys->p_synchro );
374             }
375             break;
376
377         case STATE_PICTURE:
378         {
379             uint8_t *buf[3];
380             buf[0] = buf[1] = buf[2] = NULL;
381
382             if ( p_sys->b_after_sequence_header
383                   && ((p_sys->p_info->current_picture->flags
384                         & PIC_MASK_CODING_TYPE)
385                        == PIC_FLAG_CODING_TYPE_P) )
386             {
387                 /* Intra-slice refresh. Simulate a blank I picture. */
388                 msg_Dbg( p_dec, "intra-slice refresh stream" );
389                 vout_SynchroNewPicture( p_sys->p_synchro,
390                     I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
391                 vout_SynchroDecode( p_sys->p_synchro );
392                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
393                 p_sys->b_slice_i = 1;
394             }
395             p_sys->b_after_sequence_header = 0;
396
397             vout_SynchroNewPicture( p_sys->p_synchro,
398                 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
399                 p_sys->p_info->current_picture->nb_fields,
400                 (p_sys->p_info->current_picture->flags & PIC_FLAG_PTS) ?
401                     ( ( p_sys->p_info->current_picture->pts ==
402                         (uint32_t)p_sys->i_current_pts ) ?
403                       p_sys->i_current_pts : p_sys->i_previous_pts ) : 0,
404                 0, p_sys->i_current_rate );
405
406             if ( !(p_sys->b_slice_i
407                    && ((p_sys->p_info->current_picture->flags
408                          & PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
409                    && !vout_SynchroChoose( p_sys->p_synchro,
410                               p_sys->p_info->current_picture->flags
411                                 & PIC_MASK_CODING_TYPE ) )
412             {
413                 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
414                 p_sys->b_skip = 1;
415                 vout_SynchroTrash( p_sys->p_synchro );
416                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
417             }
418             else
419             {
420                 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
421                 p_sys->b_skip = 0;
422                 vout_SynchroDecode( p_sys->p_synchro );
423                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL ) break;
424                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
425             }
426         }
427         break;
428
429         case STATE_END:
430         case STATE_SLICE:
431             if( p_sys->p_info->display_fbuf
432                 && p_sys->p_info->display_fbuf->id )
433             {
434                 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
435
436                 vout_SynchroEnd( p_sys->p_synchro,
437                             p_sys->p_info->display_picture->flags
438                              & PIC_MASK_CODING_TYPE,
439                             p_sys->b_garbage_pic );
440                 p_sys->b_garbage_pic = 0;
441                 vout_DisplayPicture( p_sys->p_vout, p_pic );
442
443                 if ( p_sys->p_picture_to_destroy != p_pic )
444                 {
445                     vout_DatePicture( p_sys->p_vout, p_pic,
446                         vout_SynchroDate( p_sys->p_synchro ) );
447                 }
448                 else
449                 {
450                     p_sys->p_picture_to_destroy = NULL;
451                     vout_DatePicture( p_sys->p_vout, p_pic, 0 );
452                 }
453             }
454
455             if( p_sys->p_info->discard_fbuf &&
456                 p_sys->p_info->discard_fbuf->id )
457             {
458                 p_pic = (picture_t *)p_sys->p_info->discard_fbuf->id;
459                 vout_UnlinkPicture( p_sys->p_vout, p_pic );
460             }
461             break;
462
463         case STATE_INVALID:
464         {
465             uint8_t *buf[3];
466             buf[0] = buf[1] = buf[2] = NULL;
467
468             msg_Warn( p_dec, "invalid picture encountered" );
469             if ( ( p_sys->p_info->current_picture == NULL ) || 
470                ( ( p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE)
471                   != B_CODING_TYPE ) )
472             {
473                 vout_SynchroReset( p_sys->p_synchro );
474             }
475             mpeg2_skip( p_sys->p_mpeg2dec, 1 );
476             p_sys->b_skip = 1;
477
478             if( p_sys->p_info->current_fbuf &&
479                 p_sys->p_info->current_fbuf->id )
480             {
481                 p_sys->b_garbage_pic = 1;
482                 p_pic = p_sys->p_info->current_fbuf->id;
483             }
484             else
485             {
486                 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
487                     break;
488                 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
489             }
490             p_sys->p_picture_to_destroy = p_pic;
491
492             memset( p_pic->p[0].p_pixels, 0,
493                     p_sys->p_info->sequence->width
494                      * p_sys->p_info->sequence->height );
495             memset( p_pic->p[1].p_pixels, 0x80,
496                     p_sys->p_info->sequence->width
497                      * p_sys->p_info->sequence->height / 4 );
498             memset( p_pic->p[2].p_pixels, 0x80,
499                     p_sys->p_info->sequence->width
500                      * p_sys->p_info->sequence->height / 4 );
501
502             if ( p_sys->b_slice_i )
503             {
504                 vout_SynchroNewPicture( p_sys->p_synchro,
505                             I_CODING_TYPE, 2, 0, 0, p_sys->i_current_rate );
506                 vout_SynchroDecode( p_sys->p_synchro );
507                 vout_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
508             }
509             break;
510         }
511
512         default:
513             break;
514         }
515     }
516
517     block_Release( p_block );
518     return VLC_EGENERIC;
519 }
520
521 /*****************************************************************************
522  * EndDecoder: libmpeg2 decoder destruction
523  *****************************************************************************/
524 static int EndDecoder( decoder_t * p_dec )
525 {
526     decoder_sys_t *p_sys = p_dec->p_sys;
527
528     if( p_sys )
529     {
530         int i_pic;
531
532         if( p_sys->p_synchro )
533             vout_SynchroRelease( p_sys->p_synchro );
534
535         if( p_sys->p_vout )
536         {
537             /* Temporary hack to free the pictures in use by libmpeg2 */
538             for( i_pic = 0; i_pic < p_sys->p_vout->render.i_pictures; i_pic++ )
539             {
540                 if( p_sys->p_vout->render.pp_picture[i_pic]->i_status ==
541                       RESERVED_PICTURE )
542                     vout_DestroyPicture( p_sys->p_vout,
543                                      p_sys->p_vout->render.pp_picture[i_pic] );
544                 if( p_sys->p_vout->render.pp_picture[i_pic]->i_refcount > 0 )
545                     vout_UnlinkPicture( p_sys->p_vout,
546                                      p_sys->p_vout->render.pp_picture[i_pic] );
547             }
548
549             vout_Request( p_dec, p_sys->p_vout, 0, 0, 0, 0 );
550         }
551
552         if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
553
554         free( p_sys );
555     }
556
557     return VLC_SUCCESS;
558 }
559
560 /*****************************************************************************
561  * GetNewPicture: Get a new picture from the vout and set the buf struct
562  *****************************************************************************/
563 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
564 {
565     decoder_sys_t *p_sys = p_dec->p_sys;
566
567     picture_t *p_pic;
568     vlc_bool_t b_progressive = p_sys->p_info->current_picture != NULL ?
569         p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME :
570         1;
571     vlc_bool_t b_top_field_first = p_sys->p_info->current_picture != NULL ?
572         p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST :
573         1;
574     unsigned int i_nb_fields = p_sys->p_info->current_picture != NULL ?
575         p_sys->p_info->current_picture->nb_fields : 2;
576
577     /* Get a new picture */
578     while( !(p_pic = vout_CreatePicture( p_sys->p_vout,
579         b_progressive, b_top_field_first, i_nb_fields )) )
580     {
581         if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
582             break;
583
584         msleep( VOUT_OUTMEM_SLEEP );
585     }
586     if( p_pic == NULL )
587         return NULL;
588     vout_LinkPicture( p_sys->p_vout, p_pic );
589
590     pp_buf[0] = p_pic->p[0].p_pixels;
591     pp_buf[1] = p_pic->p[1].p_pixels;
592     pp_buf[2] = p_pic->p[2].p_pixels;
593
594     return p_pic;
595 }