]> git.sesse.net Git - vlc/blob - modules/codec/cinepak.c
* all: only include header that are needed (and no more stdlib.h, string.h
[vlc] / modules / codec / cinepak.c
1 /*****************************************************************************
2  * cinepak.c: cinepak video decoder
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: cinepak.c,v 1.4 2003/11/22 23:39:14 fenrir Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/vout.h>
29 #include <vlc/decoder.h>
30
31 #define CINEPAK_MAXSTRIP 32
32
33 typedef struct cinepak_codebook_s
34 {
35     uint8_t i_y[4];
36     uint8_t i_u, i_v;
37
38 } cinepak_codebook_t;
39
40 typedef struct cinepak_context_s
41 {
42     int b_grayscale; /* force to grayscale */
43
44     int i_width;
45     int i_height;
46
47     int i_stride_x;
48     int i_stride_y;
49
50     uint8_t *p_y, *p_u, *p_v;
51
52     int i_stride[3]; /* our 3 planes */
53     int i_lines[3];
54     uint8_t *p_pix[3];
55
56     cinepak_codebook_t codebook_v1[CINEPAK_MAXSTRIP][256];
57     cinepak_codebook_t codebook_v4[CINEPAK_MAXSTRIP][256];
58
59 } cinepak_context_t;
60
61 /*****************************************************************************
62  * decoder_sys_t : decoder descriptor
63  *****************************************************************************/
64 struct decoder_sys_t
65 {
66     /*
67      * Cinepak properties
68      */
69     cinepak_context_t *p_context;
70 };
71
72 /*****************************************************************************
73  * Local prototypes
74  *****************************************************************************/
75 static int  OpenDecoder( vlc_object_t * );
76 static void CloseDecoder( vlc_object_t * );
77 static picture_t *DecodeBlock ( decoder_t *, block_t ** );
78
79 static int cinepak_decode_frame( cinepak_context_t *, int, uint8_t * );
80
81 /*****************************************************************************
82  * Module descriptor
83  *****************************************************************************/
84 vlc_module_begin();
85     set_description( _("Cinepak video decoder") );
86     set_capability( "decoder", 70 );
87     set_callbacks( OpenDecoder, CloseDecoder );
88 vlc_module_end();
89
90 /*****************************************************************************
91  * OpenDecoder: probe the decoder and return score
92  *****************************************************************************
93  * Tries to launch a decoder and return score so that the interface is able
94  * to chose.
95  *****************************************************************************/
96 static int OpenDecoder( vlc_object_t *p_this )
97 {
98     decoder_t *p_dec = (decoder_t*)p_this;
99     decoder_sys_t *p_sys;
100     vlc_value_t val;
101
102     switch( p_dec->fmt_in.i_codec )
103     {
104         case VLC_FOURCC('c','v','i','d'):
105         case VLC_FOURCC('C','V','I','D'):
106             break;
107
108         default:
109             return VLC_EGENERIC;
110     }
111
112     /* Allocate the memory needed to store the decoder's structure */
113     if( ( p_dec->p_sys = p_sys =
114           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
115     {
116         msg_Err( p_dec, "out of memory" );
117         return VLC_EGENERIC;
118     }
119
120     if( !(p_sys->p_context = malloc( sizeof( cinepak_context_t ) ) ) )
121     {
122         msg_Err( p_dec, "out of memory" );
123     }
124     memset( p_sys->p_context, 0, sizeof( cinepak_context_t ) );
125
126     var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
127     var_Get( p_dec, "grayscale", &val );
128     p_sys->p_context->b_grayscale = val.b_bool;
129
130     p_dec->pf_decode_video = DecodeBlock;
131
132     msg_Dbg( p_dec, "cinepak decoder started" );
133
134     return VLC_SUCCESS;
135 }
136
137 /****************************************************************************
138  * DecodeBlock: the whole thing
139  ****************************************************************************
140  * This function must be fed with whole frames.
141  ****************************************************************************/
142 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
143 {
144     decoder_sys_t *p_sys = p_dec->p_sys;
145     int i_status, i_plane;
146     uint8_t *p_dst, *p_src;
147     picture_t *p_pic;
148     block_t *p_block;
149
150     if( !pp_block || !*pp_block ) return NULL;
151
152     p_block = *pp_block;
153
154     i_status = cinepak_decode_frame( p_sys->p_context, p_block->i_buffer,
155                                      p_block->p_buffer );
156     if( i_status < 0 )
157     {
158         msg_Warn( p_dec, "cannot decode one frame (%d bytes)",
159                   p_block->i_buffer );
160         block_Release( p_block );
161         return NULL;
162     }
163
164     p_dec->fmt_out.video.i_width = p_sys->p_context->i_width;
165     p_dec->fmt_out.video.i_height = p_sys->p_context->i_height;
166     p_dec->fmt_out.video.i_aspect = p_sys->p_context->i_width
167         * VOUT_ASPECT_FACTOR / p_sys->p_context->i_height;
168     p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
169
170     /* Get a new picture */
171     p_pic = p_dec->pf_vout_buffer_new( p_dec );
172
173     if( p_pic == NULL )
174     {
175         block_Release( p_block );
176         return NULL;
177     }
178
179     for( i_plane = 0; i_plane < 3; i_plane++ )
180     {
181         int i_line, i_lines;
182
183         p_dst = p_pic->p[i_plane].p_pixels;
184         p_src = p_sys->p_context->p_pix[i_plane];
185
186         i_lines = __MIN( p_sys->p_context->i_lines[i_plane],
187                          p_pic->p[i_plane].i_lines );
188         for( i_line = 0; i_line < i_lines; i_line++ )
189         {
190             memcpy( p_dst, p_src,
191                     __MIN( p_pic->p[i_plane].i_pitch,
192                            p_sys->p_context->i_stride[i_plane] ) );
193             p_dst += p_pic->p[i_plane].i_pitch;
194             p_src += p_sys->p_context->i_stride[i_plane];
195         }
196     }
197
198     p_pic->date = p_block->i_pts;
199     block_Release( p_block );
200
201     return p_pic;
202 }
203
204 /*****************************************************************************
205  * CloseDecoder: decoder destruction
206  *****************************************************************************/
207 static void CloseDecoder( vlc_object_t *p_this )
208 {
209     decoder_t *p_dec = (decoder_t *)p_this;
210     decoder_sys_t *p_sys = p_dec->p_sys;
211     int i;
212
213     msg_Dbg( p_dec, "cinepak decoder stopped" );
214
215     for( i = 0; i < 3; i++ )
216     {
217         if( p_sys->p_context->p_pix[i] ) free( p_sys->p_context->p_pix[i] );
218     }
219
220     free( p_sys->p_context );
221
222     free( p_sys );
223 }
224
225 /*****************************************************************************
226  * local Functions
227  *****************************************************************************/
228
229 #define GET2BYTES( p ) \
230     GetWBE( p ); p+= 2;
231 /* FIXME */
232 #define GET3BYTES( p ) \
233     (GetDWBE( p ) >> 8); p+= 3;
234
235 #define GET4BYTES( p ) \
236     GetDWBE( p ); p+= 4;
237
238 #define FREE( p ) \
239     if( p ) free( p )
240
241 static void cinepak_LoadCodebook( cinepak_codebook_t *p_codebook,
242                                   uint8_t *p_data, int b_grayscale )
243 {
244     int i, i_y[4], i_u, i_v, i_Cb, i_Cr;
245     int i_uv;
246 #define SCALEBITS 12
247 #define FIX( x ) ( (int)( (x) * ( 1L << SCALEBITS ) + 0.5 ) )
248
249     for( i = 0; i < 4; i++ )
250     {
251         i_y[i] = (uint8_t)( *(p_data++) );
252     }
253     if( b_grayscale )
254     {
255         i_u  = (int8_t)( *(p_data++) );
256         i_v  = (int8_t)( *(p_data++) );
257     }
258     else
259     {
260         i_u  = 0;
261         i_v  = 0;
262     }
263
264     /*
265           | Y  |   | 1 -0.0655  0.0110 | | CY |
266           | Cb | = | 0  1.1656 -0.0062 | | CU |
267           | Cr |   | 0  0.0467  1.4187 | | CV |
268      */
269     i_uv = ( FIX( -0.0655 ) * i_u + FIX( 0.0110 ) * i_v ) >> SCALEBITS;
270     for( i = 0; i < 4; i++ )
271     {
272         i_y[i] += i_uv;
273     }
274     i_Cb  = ( FIX( 1.1656 ) * i_u + FIX( -0.0062 ) * i_v ) >> SCALEBITS;
275     i_Cr  = ( FIX( 0.0467 ) * i_u + FIX(  1.4187 ) * i_v ) >> SCALEBITS;
276
277     for( i = 0; i < 4; i++ )
278     {
279         p_codebook->i_y[i] = __MIN( __MAX( 0, i_y[i] ), 255 );
280     }
281     p_codebook->i_u  = __MIN( __MAX( 0, i_Cb + 128 ), 255 );
282     p_codebook->i_v  = __MIN( __MAX( 0, i_Cr + 128 ), 255 );
283
284 #undef FIX
285 #undef SCALEBITS
286 }
287
288 static void cinepak_Getv4( cinepak_context_t *p_context,
289                            int i_strip, int i_x, int i_y,
290                            int i_x2, int i_y2, uint8_t *p_data )
291 {
292     uint8_t i_index[4];
293     int i,j;
294
295     uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
296 #define PIX_SET_Y( x, y, v ) \
297     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
298
299 #define PIX_SET_UV( i, p, x, y, v ) \
300     p[(x) + (y)* (p_context->i_stride[i])] = (v);
301
302     for( i = 0; i < 4; i++ )
303     {
304         i_index[i] = *(p_data++);
305     }
306
307     /* y plane */
308     p_dst_y = p_context->p_pix[0] + p_context->i_stride[0] * i_y + i_x;
309     p_dst_u = p_context->p_pix[1] + p_context->i_stride[1] * (i_y/2) + (i_x/2);
310     p_dst_v = p_context->p_pix[2] + p_context->i_stride[2] * (i_y/2) + (i_x/2);
311
312     for( i = 0; i < 2; i++ )
313     {
314         for( j = 0; j < 2; j ++ )
315         {
316             PIX_SET_Y( 2*j + 0, 2*i + 0,
317                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[0]);
318             PIX_SET_Y( 2*j + 1, 2*i + 0,
319                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[1]);
320             PIX_SET_Y( 2*j + 0, 2*i + 1,
321                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[2]);
322             PIX_SET_Y( 2*j + 1, 2*i + 1,
323                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[3]);
324
325             PIX_SET_UV( 1, p_dst_u, j, i,
326                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_u );
327             PIX_SET_UV( 2, p_dst_v, j, i,
328                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_v );
329         }
330     }
331 #undef PIX_SET_Y
332 #undef PIX_SET_UV
333 }
334
335 static void cinepak_Getv1( cinepak_context_t *p_context,
336                            int i_strip, int i_x,  int i_y,
337                            int i_x2, int i_y2, uint8_t *p_data )
338 {
339     uint8_t i_index;
340     int i,j;
341
342     uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
343 #define PIX_SET_Y( x, y, v ) \
344     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
345
346 #define PIX_SET_UV( i,p, x, y, v ) \
347     p[(x) + (y)* (p_context->i_stride[i])] = (v);
348
349     i_index = *(p_data++);
350
351     /* y plane */
352     p_dst_y = p_context->p_pix[0] + p_context->i_stride[0] * i_y + i_x;
353     p_dst_u = p_context->p_pix[1] + p_context->i_stride[1] * (i_y/2) + (i_x/2);
354     p_dst_v = p_context->p_pix[2] + p_context->i_stride[2] * (i_y/2) + (i_x/2);
355
356     for( i = 0; i < 2; i++ )
357     {
358         for( j = 0; j < 2; j ++ )
359         {
360             PIX_SET_Y( 2*j + 0, 2*i + 0,
361                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
362             PIX_SET_Y( 2*j + 1, 2*i + 0,
363                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
364             PIX_SET_Y( 2*j + 0, 2*i + 1,
365                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
366             PIX_SET_Y( 2*j + 1, 2*i + 1,
367                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
368
369             PIX_SET_UV( 1,p_dst_u, j, i,
370                         p_context->codebook_v1[i_strip][i_index].i_u );
371             PIX_SET_UV( 2,p_dst_v, j, i,
372                         p_context->codebook_v1[i_strip][i_index].i_v );
373         }
374     }
375
376 #undef PIX_SET_Y
377 #undef PIX_SET_UV
378 }
379
380 /*****************************************************************************
381  * The function that decode one frame
382  *****************************************************************************/
383 static int cinepak_decode_frame( cinepak_context_t *p_context,
384                                  int i_length, uint8_t *p_data )
385 {
386     int i_strip;
387
388     int i_frame_flags;
389     int i_frame_size;
390     int i_width, i_height;
391     int i_frame_strips;
392     int i_index;
393     int i_strip_x1 =0, i_strip_y1=0;
394     int i_strip_x2 =0, i_strip_y2=0;
395
396     if( i_length <= 10 )
397     {
398         /* Broken header or no data */
399         return( -1 );
400     }
401
402     /* get header */
403     i_frame_flags  = *(p_data++);
404     i_frame_size = GET3BYTES( p_data );
405     i_width  = GET2BYTES( p_data );
406     i_height = GET2BYTES( p_data );
407     i_frame_strips = GET2BYTES( p_data );
408
409     if( !i_frame_size || !i_width || !i_height )
410     {
411         /* Broken header */
412         return( -1 );
413     }
414
415     /* Check if we have a picture buffer with good size */
416     if( ( p_context->i_width != i_width ) ||
417         ( p_context->i_height != i_height ) )
418     {
419         int i;
420         for( i = 0; i < 3; i++ )
421         {
422             FREE( p_context->p_pix[i] );
423         }
424
425         p_context->i_width = i_width;
426         p_context->i_height = i_height;
427
428         p_context->i_stride[0] = ( i_width + 3 ) & 0xfffc;
429         p_context->i_stride[1] = p_context->i_stride[2] =
430                 p_context->i_stride[0] / 2;
431
432         p_context->i_lines[0] = ( i_height + 3 ) & 0xfffc;
433         p_context->i_lines[1] = p_context->i_lines[2] =
434                 p_context->i_lines[0] /2;
435
436         for( i = 0; i < 3; i++ )
437         {
438             p_context->p_pix[i] = malloc( p_context->i_stride[i] *
439                                           p_context->i_lines[i] );
440             /* Set it to all black */
441             memset( p_context->p_pix[i], ( i == 0 ) ? 0 : 128 ,
442                     p_context->i_stride[i] * p_context->i_lines[i] );
443         }
444     }
445
446     if( i_frame_size != i_length )
447     {
448         i_length = __MIN( i_length, i_frame_size );
449     }
450     i_length -= 10;
451
452     if( i_frame_strips >= CINEPAK_MAXSTRIP )
453     {
454         i_frame_strips = CINEPAK_MAXSTRIP;
455     }
456
457     /* Now decode each strip */
458     for( i_strip = 0; i_strip < i_frame_strips; i_strip++ )
459     {
460         int i_strip_id;
461         int i_strip_size;
462
463         if( i_length <= 12 )
464         {
465             break;
466         }
467
468         i_strip_id   = GET2BYTES( p_data );
469         i_strip_size = GET2BYTES( p_data );
470         i_strip_size = __MIN( i_strip_size, i_length );
471         /* FIXME I don't really understand how it's work; */
472         i_strip_y1  = i_strip_y2 + GET2BYTES( p_data );
473         i_strip_x1  = GET2BYTES( p_data );
474         i_strip_y2  = i_strip_y2 + GET2BYTES( p_data );
475         i_strip_x2  = GET2BYTES( p_data );
476
477         i_length -= i_strip_size;
478
479         i_strip_size -= 12;
480         /* init codebook , if needed */
481         if( ( i_strip > 0 )&&( !(i_frame_flags&0x01) ) )
482         {
483             memcpy( &p_context->codebook_v1[i_strip],
484                     &p_context->codebook_v1[i_strip-1],
485                     sizeof(cinepak_codebook_t[256] ) );
486
487             memcpy( &p_context->codebook_v4[i_strip],
488                     &p_context->codebook_v4[i_strip-1],
489                     sizeof(cinepak_codebook_t[256] ) );
490         }
491
492         /* Now parse all chunk in this strip */
493         while( i_strip_size > 0 )
494         {
495             cinepak_codebook_t (*p_codebook)[CINEPAK_MAXSTRIP][256];
496             int i_mode;
497
498             int i_chunk_id;
499             int i_chunk_size;
500             uint32_t i_vector_flags;
501             int i_count;
502             int i;
503             int i_x, i_y; /* (0,0) begin in fact at (x1,y1) ... */
504
505             i_chunk_id   = GET2BYTES( p_data );
506             i_chunk_size = GET2BYTES( p_data );
507             i_chunk_size  = __MIN( i_chunk_size, i_strip_size );
508             i_strip_size -= i_chunk_size;
509
510             i_chunk_size -= 4;
511
512             i_x = 0;
513             i_y = 0;
514             if( i_chunk_size < 0 )
515             {
516                 break;
517             }
518
519             switch( i_chunk_id )
520             {
521             case( 0x2000 ): /* 12bits v4 Intra*/
522             case( 0x2200 ): /* 12bits v1 Intra*/
523             case( 0x2400 ): /* 8bits v4 Intra*/
524             case( 0x2600 ): /* 8bits v1 Intra */
525                 i_mode = ( ( i_chunk_id&0x0400 ) == 0 );
526                 p_codebook = ( i_chunk_id&0x0200 ) ?
527                                &p_context->codebook_v1 :
528                                &p_context->codebook_v4;
529
530                 i_count = __MIN( i_chunk_size / ( i_mode ? 6 : 4 ), 256 );
531
532                 for( i = 0; i < i_count; i++ )
533                 {
534                     cinepak_LoadCodebook( &((*p_codebook)[i_strip][i]),
535                                           p_data,
536                                           i_mode&~p_context->b_grayscale );
537                     p_data += i_mode ? 6 : 4;
538                     i_chunk_size -= i_mode ? 6 : 4;
539                 }
540                 break;
541
542             case( 0x2100 ): /* selective 12bits v4 Inter*/
543             case( 0x2300 ): /* selective 12bits v1 Inter*/
544             case( 0x2500 ): /* selective 8bits v4 Inter*/
545             case( 0x2700 ): /* selective 8bits v1 Inter*/
546                 i_mode = ( ( i_chunk_id&0x0400 ) == 0 );
547                 p_codebook = ( i_chunk_id&0x0200 ) ?
548                                &p_context->codebook_v1 :
549                                &p_context->codebook_v4;
550
551                 i_index = 0;
552                 while( (i_chunk_size > 4)&&(i_index<256))
553                 {
554                     i_vector_flags = GET4BYTES( p_data );
555                     i_chunk_size -= 4;
556                     for( i = 0; i < 32; i++ )
557                     {
558                         if( ( i_chunk_size < ( i_mode ? 6 : 4 ) )
559                             || (i_index >= 256 ) )
560                         {
561                             break;
562                         }
563                         if( i_vector_flags&0x80000000UL )
564                         {
565                             cinepak_LoadCodebook(
566                                 &((*p_codebook)[i_strip][i_index]),
567                                 p_data, i_mode&~p_context->b_grayscale );
568
569                             p_data += i_mode ? 6 : 4;
570                             i_chunk_size -= i_mode ? 6 : 4;
571                         }
572                         i_index++;
573                         i_vector_flags <<= 1;
574                     }
575                 }
576                 break;
577
578             case( 0x3000 ): /* load image Intra */
579                 while( (i_chunk_size >= 4 )&&(i_y<i_strip_y2-i_strip_y1) )
580                 {
581                     i_vector_flags = GET4BYTES( p_data );
582                     i_chunk_size -= 4;
583                     i_strip_size -= 4;
584                     i_length     -= 4;
585
586                     for( i = 0; i < 32; i++ )
587                     {
588                         if( ( i_y >= i_strip_y2 - i_strip_y1) ||
589                             ( i_chunk_size<=0 ) )
590                         {
591                             break;
592                         }
593                         if( i_vector_flags&0x80000000UL )
594                         {
595                             cinepak_Getv4( p_context,
596                                            i_strip,
597                                            i_strip_x1 + i_x,
598                                            i_strip_y1 + i_y,
599                                            i_strip_x2, i_strip_y2,
600                                            p_data );
601                             p_data += 4;
602                             i_chunk_size -= 4;
603                         }
604                         else
605                         {
606                             cinepak_Getv1( p_context,
607                                            i_strip,
608                                            i_strip_x1 + i_x,
609                                            i_strip_y1 + i_y,
610                                            i_strip_x2, i_strip_y2,
611                                            p_data );
612                             p_data++;
613                             i_chunk_size--;
614                         }
615
616                         i_x += 4;
617                         if( i_x >= i_strip_x2 - i_strip_x1 )
618                         {
619                             i_x = 0;
620                             i_y += 4;
621                         }
622                         i_vector_flags <<= 1;
623                     }
624                 }
625                 break;
626
627             case( 0x3100 ): /* load image Inter */
628                 while( ( i_chunk_size > 4 )&&( i_y < i_strip_y2 - i_strip_y1) )
629                 {
630                     uint32_t i_mask;
631                     i_vector_flags = GET4BYTES( p_data );
632                     i_chunk_size -= 4;
633                     i_mask = 0x80000000UL;
634
635                     while( (i_chunk_size > 0 ) && ( i_mask )
636                            && ( i_y < i_strip_y2 - i_strip_y1 ) )
637                     {
638                         if( i_vector_flags&i_mask )
639                         {
640                             i_mask >>= 1;
641                             if( !i_mask )
642                             {
643                                 if( i_chunk_size < 4 )
644                                 {
645                                     break;
646                                 }
647                                 i_vector_flags = GET4BYTES( p_data );
648                                 i_chunk_size -= 4;
649                                 i_mask = 0x80000000UL;
650                             }
651                             if( i_vector_flags&i_mask )
652                             {
653                                 if( i_chunk_size < 4 ) break;
654                                 cinepak_Getv4( p_context,
655                                                i_strip,
656                                                i_strip_x1 + i_x,
657                                                i_strip_y1 + i_y,
658                                                i_strip_x2, i_strip_y2,
659                                                p_data );
660                                 p_data += 4;
661                                 i_chunk_size -= 4;
662                             }
663                             else
664                             {
665                                 if( i_chunk_size < 1 ) break;
666                                 cinepak_Getv1( p_context,
667                                                i_strip,
668                                                i_strip_x1 + i_x,
669                                                i_strip_y1 + i_y,
670                                                i_strip_x2, i_strip_y2,
671                                                p_data );
672                                 p_data++;
673                                 i_chunk_size--;
674                             }
675                         }
676                         i_mask >>= 1;
677
678                         i_x += 4;
679                         if( i_x >= i_strip_x2 - i_strip_x1 )
680                         {
681                             i_x = 0;
682                             i_y += 4;
683                         }
684                     }
685                 }
686                 break;
687
688             case( 0x3200 ): /* load intra picture but all v1*/
689                 while( ( i_chunk_size > 0 ) &&
690                        ( i_y < i_strip_y2 - i_strip_y1 ) )
691                 {
692                     cinepak_Getv1( p_context,
693                                    i_strip,
694                                    i_strip_x1 + i_x,
695                                    i_strip_y1 + i_y,
696                                    i_strip_x2, i_strip_y2,
697                                    p_data );
698                     p_data++;
699                     i_chunk_size--;
700
701                     i_x += 4;
702                     if( i_x >= i_strip_x2 - i_strip_x1 )
703                     {
704                         i_x = 0;
705                         i_y += 4;
706                     }
707                 }
708                 break;
709
710             default:
711                 break;
712
713             }
714             p_data += i_chunk_size ; /* skip remains bytes */
715         }
716     }
717
718     return( 0 );
719 }