Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

cinepak.c

00001 /*****************************************************************************
00002  * cinepak.c: cinepak video decoder
00003  *****************************************************************************
00004  * Copyright (C) 1999-2001 the VideoLAN team
00005  * $Id: cinepak.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Laurent Aimar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <vlc/vlc.h>
00028 #include <vlc/vout.h>
00029 #include <vlc/decoder.h>
00030 
00031 /*****************************************************************************
00032  * Module descriptor
00033  *****************************************************************************/
00034 static int  OpenDecoder ( vlc_object_t * );
00035 static void CloseDecoder( vlc_object_t * );
00036 
00037 vlc_module_begin();
00038     set_description( _("Cinepak video decoder") );
00039     set_capability( "decoder", 100 );
00040     set_category( CAT_INPUT );
00041     set_subcategory( SUBCAT_INPUT_VCODEC );
00042     set_callbacks( OpenDecoder, CloseDecoder );
00043 vlc_module_end();
00044 
00045 
00046 /*****************************************************************************
00047  * Local prototypes
00048  *****************************************************************************/
00049 #define CINEPAK_MAXSTRIP 32
00050 
00051 typedef struct
00052 {
00053     uint8_t i_y[4];
00054     uint8_t i_u, i_v;
00055 
00056 } cinepak_codebook_t;
00057 
00058 typedef struct
00059 {
00060     int b_grayscale; /* force to grayscale */
00061 
00062     int i_width;
00063     int i_height;
00064 
00065     int i_stride_x;
00066     int i_stride_y;
00067 
00068     uint8_t *p_y, *p_u, *p_v;
00069 
00070     int i_stride[3]; /* our 3 planes */
00071     int i_lines[3];
00072     uint8_t *p_pix[3];
00073 
00074     cinepak_codebook_t codebook_v1[CINEPAK_MAXSTRIP][256];
00075     cinepak_codebook_t codebook_v4[CINEPAK_MAXSTRIP][256];
00076 
00077 } cinepak_context_t;
00078 
00079 /*****************************************************************************
00080  * decoder_sys_t : decoder descriptor
00081  *****************************************************************************/
00082 struct decoder_sys_t
00083 {
00084     /*
00085      * Cinepak properties
00086      */
00087     cinepak_context_t context;
00088 };
00089 
00090 static picture_t *DecodeBlock ( decoder_t *, block_t ** );
00091 
00092 static int cinepak_decode_frame( cinepak_context_t *, int, uint8_t * );
00093 
00094 /*****************************************************************************
00095  * OpenDecoder: probe the decoder and return score
00096  *****************************************************************************
00097  * Tries to launch a decoder and return score so that the interface is able
00098  * to chose.
00099  *****************************************************************************/
00100 static int OpenDecoder( vlc_object_t *p_this )
00101 {
00102     decoder_t *p_dec = (decoder_t*)p_this;
00103     decoder_sys_t *p_sys;
00104     vlc_value_t val;
00105 
00106     if( p_dec->fmt_in.i_codec != VLC_FOURCC('c','v','i','d') &&
00107         p_dec->fmt_in.i_codec != VLC_FOURCC('C','V','I','D') )
00108     {
00109         return VLC_EGENERIC;
00110     }
00111 
00112     /* Allocate the memory needed to store the decoder's structure */
00113     if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL )
00114     {
00115         msg_Err( p_dec, "out of memory" );
00116         return VLC_EGENERIC;
00117     }
00118     memset( &p_sys->context, 0, sizeof( cinepak_context_t ) );
00119 
00120     var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
00121     var_Get( p_dec, "grayscale", &val );
00122     p_sys->context.b_grayscale = val.b_bool;
00123 
00124     p_dec->pf_decode_video = DecodeBlock;
00125 
00126     msg_Dbg( p_dec, "cinepak decoder started" );
00127 
00128     return VLC_SUCCESS;
00129 }
00130 
00131 /****************************************************************************
00132  * DecodeBlock: the whole thing
00133  ****************************************************************************
00134  * This function must be fed with whole frames.
00135  ****************************************************************************/
00136 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
00137 {
00138     decoder_sys_t *p_sys = p_dec->p_sys;
00139     int i_status, i_plane;
00140     uint8_t *p_dst, *p_src;
00141     picture_t *p_pic;
00142     block_t *p_block;
00143 
00144     if( !pp_block || !*pp_block )
00145     {
00146         return NULL;
00147     }
00148     p_block = *pp_block;
00149     *pp_block = NULL;
00150 
00151     i_status = cinepak_decode_frame( &p_sys->context, p_block->i_buffer,
00152                                      p_block->p_buffer );
00153     if( i_status < 0 )
00154     {
00155         msg_Warn( p_dec, "cannot decode one frame (%d bytes)",
00156                   p_block->i_buffer );
00157         block_Release( p_block );
00158         return NULL;
00159     }
00160 
00161     p_dec->fmt_out.video.i_width = p_sys->context.i_width;
00162     p_dec->fmt_out.video.i_height = p_sys->context.i_height;
00163     p_dec->fmt_out.video.i_aspect = p_sys->context.i_width
00164         * VOUT_ASPECT_FACTOR / p_sys->context.i_height;
00165     p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
00166 
00167     /* Get a new picture */
00168     if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
00169     {
00170         for( i_plane = 0; i_plane < 3; i_plane++ )
00171         {
00172             int i_line, i_lines;
00173 
00174             p_dst = p_pic->p[i_plane].p_pixels;
00175             p_src = p_sys->context.p_pix[i_plane];
00176 
00177             i_lines = __MIN( p_sys->context.i_lines[i_plane],
00178                              p_pic->p[i_plane].i_visible_lines );
00179             for( i_line = 0; i_line < i_lines; i_line++ )
00180             {
00181                 memcpy( p_dst, p_src,
00182                         __MIN( p_pic->p[i_plane].i_pitch,
00183                                p_sys->context.i_stride[i_plane] ) );
00184                 p_dst += p_pic->p[i_plane].i_pitch;
00185                 p_src += p_sys->context.i_stride[i_plane];
00186             }
00187         }
00188 
00189         p_pic->date = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
00190     }
00191 
00192     block_Release( p_block );
00193     return p_pic;
00194 }
00195 
00196 /*****************************************************************************
00197  * CloseDecoder: decoder destruction
00198  *****************************************************************************/
00199 static void CloseDecoder( vlc_object_t *p_this )
00200 {
00201     decoder_t     *p_dec = (decoder_t *)p_this;
00202     decoder_sys_t *p_sys = p_dec->p_sys;
00203     int i;
00204 
00205     msg_Dbg( p_dec, "cinepak decoder stopped" );
00206 
00207     for( i = 0; i < 3; i++ )
00208     {
00209         if( p_sys->context.p_pix[i] ) free( p_sys->context.p_pix[i] );
00210     }
00211 
00212     free( p_sys );
00213 }
00214 
00215 /*****************************************************************************
00216  * local Functions
00217  *****************************************************************************/
00218 
00219 #define GET2BYTES( p ) \
00220     GetWBE( p ); p+= 2;
00221 /* FIXME */
00222 #define GET3BYTES( p ) \
00223     (GetDWBE( p ) >> 8); p+= 3;
00224 
00225 #define GET4BYTES( p ) \
00226     GetDWBE( p ); p+= 4;
00227 
00228 #define FREE( p ) \
00229     if( p ) free( p )
00230 
00231 static void cinepak_LoadCodebook( cinepak_codebook_t *p_codebook,
00232                                   uint8_t *p_data, int b_grayscale )
00233 {
00234     int i, i_y[4], i_u, i_v, i_Cb, i_Cr;
00235     int i_uv;
00236 #define SCALEBITS 12
00237 #define FIX( x ) ( (int)( (x) * ( 1L << SCALEBITS ) + 0.5 ) )
00238 
00239     for( i = 0; i < 4; i++ )
00240     {
00241         i_y[i] = (uint8_t)( *(p_data++) );
00242     }
00243     if( b_grayscale )
00244     {
00245         i_u  = (int8_t)( *(p_data++) );
00246         i_v  = (int8_t)( *(p_data++) );
00247     }
00248     else
00249     {
00250         i_u  = 0;
00251         i_v  = 0;
00252     }
00253 
00254     /*
00255           | Y  |   | 1 -0.0655  0.0110 | | CY |
00256           | Cb | = | 0  1.1656 -0.0062 | | CU |
00257           | Cr |   | 0  0.0467  1.4187 | | CV |
00258      */
00259     i_uv = ( FIX( -0.0655 ) * i_u + FIX( 0.0110 ) * i_v ) >> SCALEBITS;
00260     for( i = 0; i < 4; i++ )
00261     {
00262         i_y[i] += i_uv;
00263     }
00264     i_Cb  = ( FIX( 1.1656 ) * i_u + FIX( -0.0062 ) * i_v ) >> SCALEBITS;
00265     i_Cr  = ( FIX( 0.0467 ) * i_u + FIX(  1.4187 ) * i_v ) >> SCALEBITS;
00266 
00267     for( i = 0; i < 4; i++ )
00268     {
00269         p_codebook->i_y[i] = __MIN( __MAX( 0, i_y[i] ), 255 );
00270     }
00271     p_codebook->i_u  = __MIN( __MAX( 0, i_Cb + 128 ), 255 );
00272     p_codebook->i_v  = __MIN( __MAX( 0, i_Cr + 128 ), 255 );
00273 
00274 #undef FIX
00275 #undef SCALEBITS
00276 }
00277 
00278 static void cinepak_Getv4( cinepak_context_t *p_context,
00279                            int i_strip, int i_x, int i_y,
00280                            int i_x2, int i_y2, uint8_t *p_data )
00281 {
00282     uint8_t i_index[4];
00283     int i,j;
00284 
00285     uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
00286 #define PIX_SET_Y( x, y, v ) \
00287     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
00288 
00289 #define PIX_SET_UV( i, p, x, y, v ) \
00290     p[(x) + (y)* (p_context->i_stride[i])] = (v);
00291 
00292     for( i = 0; i < 4; i++ )
00293     {
00294         i_index[i] = *(p_data++);
00295     }
00296 
00297     /* y plane */
00298     p_dst_y = p_context->p_pix[0] + p_context->i_stride[0] * i_y + i_x;
00299     p_dst_u = p_context->p_pix[1] + p_context->i_stride[1] * (i_y/2) + (i_x/2);
00300     p_dst_v = p_context->p_pix[2] + p_context->i_stride[2] * (i_y/2) + (i_x/2);
00301 
00302     for( i = 0; i < 2; i++ )
00303     {
00304         for( j = 0; j < 2; j ++ )
00305         {
00306             PIX_SET_Y( 2*j + 0, 2*i + 0,
00307                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[0]);
00308             PIX_SET_Y( 2*j + 1, 2*i + 0,
00309                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[1]);
00310             PIX_SET_Y( 2*j + 0, 2*i + 1,
00311                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[2]);
00312             PIX_SET_Y( 2*j + 1, 2*i + 1,
00313                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[3]);
00314 
00315             PIX_SET_UV( 1, p_dst_u, j, i,
00316                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_u );
00317             PIX_SET_UV( 2, p_dst_v, j, i,
00318                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_v );
00319         }
00320     }
00321 #undef PIX_SET_Y
00322 #undef PIX_SET_UV
00323 }
00324 
00325 static void cinepak_Getv1( cinepak_context_t *p_context,
00326                            int i_strip, int i_x,  int i_y,
00327                            int i_x2, int i_y2, uint8_t *p_data )
00328 {
00329     uint8_t i_index;
00330     int i,j;
00331 
00332     uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
00333 #define PIX_SET_Y( x, y, v ) \
00334     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
00335 
00336 #define PIX_SET_UV( i,p, x, y, v ) \
00337     p[(x) + (y)* (p_context->i_stride[i])] = (v);
00338 
00339     i_index = *(p_data++);
00340 
00341     /* y plane */
00342     p_dst_y = p_context->p_pix[0] + p_context->i_stride[0] * i_y + i_x;
00343     p_dst_u = p_context->p_pix[1] + p_context->i_stride[1] * (i_y/2) + (i_x/2);
00344     p_dst_v = p_context->p_pix[2] + p_context->i_stride[2] * (i_y/2) + (i_x/2);
00345 
00346     for( i = 0; i < 2; i++ )
00347     {
00348         for( j = 0; j < 2; j ++ )
00349         {
00350             PIX_SET_Y( 2*j + 0, 2*i + 0,
00351                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
00352             PIX_SET_Y( 2*j + 1, 2*i + 0,
00353                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
00354             PIX_SET_Y( 2*j + 0, 2*i + 1,
00355                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
00356             PIX_SET_Y( 2*j + 1, 2*i + 1,
00357                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
00358 
00359             PIX_SET_UV( 1,p_dst_u, j, i,
00360                         p_context->codebook_v1[i_strip][i_index].i_u );
00361             PIX_SET_UV( 2,p_dst_v, j, i,
00362                         p_context->codebook_v1[i_strip][i_index].i_v );
00363         }
00364     }
00365 
00366 #undef PIX_SET_Y
00367 #undef PIX_SET_UV
00368 }
00369 
00370 /*****************************************************************************
00371  * The function that decode one frame
00372  *****************************************************************************/
00373 static int cinepak_decode_frame( cinepak_context_t *p_context,
00374                                  int i_length, uint8_t *p_data )
00375 {
00376     int i_strip;
00377 
00378     int i_frame_flags;
00379     int i_frame_size;
00380     int i_width, i_height;
00381     int i_frame_strips;
00382     int i_index;
00383     int i_strip_x1 =0, i_strip_y1=0;
00384     int i_strip_x2 =0, i_strip_y2=0;
00385 
00386     if( i_length <= 10 )
00387     {
00388         /* Broken header or no data */
00389         return( -1 );
00390     }
00391 
00392     /* get header */
00393     i_frame_flags  = *(p_data++);
00394     i_frame_size = GET3BYTES( p_data );
00395     i_width  = GET2BYTES( p_data );
00396     i_height = GET2BYTES( p_data );
00397     i_frame_strips = GET2BYTES( p_data );
00398 
00399     if( !i_frame_size || !i_width || !i_height )
00400     {
00401         /* Broken header */
00402         return( -1 );
00403     }
00404 
00405     /* Check if we have a picture buffer with good size */
00406     if( ( p_context->i_width != i_width ) ||
00407         ( p_context->i_height != i_height ) )
00408     {
00409         int i;
00410         for( i = 0; i < 3; i++ )
00411         {
00412             FREE( p_context->p_pix[i] );
00413         }
00414 
00415         p_context->i_width = i_width;
00416         p_context->i_height = i_height;
00417 
00418         p_context->i_stride[0] = ( i_width + 3 ) & 0xfffc;
00419         p_context->i_stride[1] = p_context->i_stride[2] =
00420                 p_context->i_stride[0] / 2;
00421 
00422         p_context->i_lines[0] = ( i_height + 3 ) & 0xfffc;
00423         p_context->i_lines[1] = p_context->i_lines[2] =
00424                 p_context->i_lines[0] /2;
00425 
00426         for( i = 0; i < 3; i++ )
00427         {
00428             p_context->p_pix[i] = malloc( p_context->i_stride[i] *
00429                                           p_context->i_lines[i] );
00430             /* Set it to all black */
00431             memset( p_context->p_pix[i], ( i == 0 ) ? 0 : 128 ,
00432                     p_context->i_stride[i] * p_context->i_lines[i] );
00433         }
00434     }
00435 
00436     if( i_frame_size != i_length )
00437     {
00438         i_length = __MIN( i_length, i_frame_size );
00439     }
00440     i_length -= 10;
00441 
00442     if( i_frame_strips >= CINEPAK_MAXSTRIP )
00443     {
00444         i_frame_strips = CINEPAK_MAXSTRIP;
00445     }
00446 
00447     /* Now decode each strip */
00448     for( i_strip = 0; i_strip < i_frame_strips; i_strip++ )
00449     {
00450         int i_strip_id;
00451         int i_strip_size;
00452 
00453         if( i_length <= 12 )
00454         {
00455             break;
00456         }
00457 
00458         i_strip_id   = GET2BYTES( p_data );
00459         i_strip_size = GET2BYTES( p_data );
00460         i_strip_size = __MIN( i_strip_size, i_length );
00461         /* FIXME I don't really understand how it's work; */
00462         i_strip_y1  = i_strip_y2 + GET2BYTES( p_data );
00463         i_strip_x1  = GET2BYTES( p_data );
00464         i_strip_y2  = i_strip_y2 + GET2BYTES( p_data );
00465         i_strip_x2  = GET2BYTES( p_data );
00466 
00467         i_length -= i_strip_size;
00468 
00469         i_strip_size -= 12;
00470         /* init codebook , if needed */
00471         if( ( i_strip > 0 )&&( !(i_frame_flags&0x01) ) )
00472         {
00473             memcpy( &p_context->codebook_v1[i_strip],
00474                     &p_context->codebook_v1[i_strip-1],
00475                     sizeof(cinepak_codebook_t[256] ) );
00476 
00477             memcpy( &p_context->codebook_v4[i_strip],
00478                     &p_context->codebook_v4[i_strip-1],
00479                     sizeof(cinepak_codebook_t[256] ) );
00480         }
00481 
00482         /* Now parse all chunk in this strip */
00483         while( i_strip_size > 0 )
00484         {
00485             cinepak_codebook_t (*p_codebook)[CINEPAK_MAXSTRIP][256];
00486             int i_mode;
00487 
00488             int i_chunk_id;
00489             int i_chunk_size;
00490             uint32_t i_vector_flags;
00491             int i_count;
00492             int i;
00493             int i_x, i_y; /* (0,0) begin in fact at (x1,y1) ... */
00494 
00495             i_chunk_id   = GET2BYTES( p_data );
00496             i_chunk_size = GET2BYTES( p_data );
00497             i_chunk_size  = __MIN( i_chunk_size, i_strip_size );
00498             i_strip_size -= i_chunk_size;
00499 
00500             i_chunk_size -= 4;
00501 
00502             i_x = 0;
00503             i_y = 0;
00504             if( i_chunk_size < 0 )
00505             {
00506                 break;
00507             }
00508 
00509             switch( i_chunk_id )
00510             {
00511             case( 0x2000 ): /* 12bits v4 Intra*/
00512             case( 0x2200 ): /* 12bits v1 Intra*/
00513             case( 0x2400 ): /* 8bits v4 Intra*/
00514             case( 0x2600 ): /* 8bits v1 Intra */
00515                 i_mode = ( ( i_chunk_id&0x0400 ) == 0 );
00516                 p_codebook = ( i_chunk_id&0x0200 ) ?
00517                                &p_context->codebook_v1 :
00518                                &p_context->codebook_v4;
00519 
00520                 i_count = __MIN( i_chunk_size / ( i_mode ? 6 : 4 ), 256 );
00521 
00522                 for( i = 0; i < i_count; i++ )
00523                 {
00524                     cinepak_LoadCodebook( &((*p_codebook)[i_strip][i]),
00525                                           p_data,
00526                                           i_mode&~p_context->b_grayscale );
00527                     p_data += i_mode ? 6 : 4;
00528                     i_chunk_size -= i_mode ? 6 : 4;
00529                 }
00530                 break;
00531 
00532             case( 0x2100 ): /* selective 12bits v4 Inter*/
00533             case( 0x2300 ): /* selective 12bits v1 Inter*/
00534             case( 0x2500 ): /* selective 8bits v4 Inter*/
00535             case( 0x2700 ): /* selective 8bits v1 Inter*/
00536                 i_mode = ( ( i_chunk_id&0x0400 ) == 0 );
00537                 p_codebook = ( i_chunk_id&0x0200 ) ?
00538                                &p_context->codebook_v1 :
00539                                &p_context->codebook_v4;
00540 
00541                 i_index = 0;
00542                 while( (i_chunk_size > 4)&&(i_index<256))
00543                 {
00544                     i_vector_flags = GET4BYTES( p_data );
00545                     i_chunk_size -= 4;
00546                     for( i = 0; i < 32; i++ )
00547                     {
00548                         if( ( i_chunk_size < ( i_mode ? 6 : 4 ) )
00549                             || (i_index >= 256 ) )
00550                         {
00551                             break;
00552                         }
00553                         if( i_vector_flags&0x80000000UL )
00554                         {
00555                             cinepak_LoadCodebook(
00556                                 &((*p_codebook)[i_strip][i_index]),
00557                                 p_data, i_mode&~p_context->b_grayscale );
00558 
00559                             p_data += i_mode ? 6 : 4;
00560                             i_chunk_size -= i_mode ? 6 : 4;
00561                         }
00562                         i_index++;
00563                         i_vector_flags <<= 1;
00564                     }
00565                 }
00566                 break;
00567 
00568             case( 0x3000 ): /* load image Intra */
00569                 while( (i_chunk_size >= 4 )&&(i_y<i_strip_y2-i_strip_y1) )
00570                 {
00571                     i_vector_flags = GET4BYTES( p_data );
00572                     i_chunk_size -= 4;
00573                     i_strip_size -= 4;
00574                     i_length     -= 4;
00575 
00576                     for( i = 0; i < 32; i++ )
00577                     {
00578                         if( ( i_y >= i_strip_y2 - i_strip_y1) ||
00579                             ( i_chunk_size<=0 ) )
00580                         {
00581                             break;
00582                         }
00583                         if( i_vector_flags&0x80000000UL )
00584                         {
00585                             cinepak_Getv4( p_context,
00586                                            i_strip,
00587                                            i_strip_x1 + i_x,
00588                                            i_strip_y1 + i_y,
00589                                            i_strip_x2, i_strip_y2,
00590                                            p_data );
00591                             p_data += 4;
00592                             i_chunk_size -= 4;
00593                         }
00594                         else
00595                         {
00596                             cinepak_Getv1( p_context,
00597                                            i_strip,
00598                                            i_strip_x1 + i_x,
00599                                            i_strip_y1 + i_y,
00600                                            i_strip_x2, i_strip_y2,
00601                                            p_data );
00602                             p_data++;
00603                             i_chunk_size--;
00604                         }
00605 
00606                         i_x += 4;
00607                         if( i_x >= i_strip_x2 - i_strip_x1 )
00608                         {
00609                             i_x = 0;
00610                             i_y += 4;
00611                         }
00612                         i_vector_flags <<= 1;
00613                     }
00614                 }
00615                 break;
00616 
00617             case( 0x3100 ): /* load image Inter */
00618                 while( ( i_chunk_size > 4 )&&( i_y < i_strip_y2 - i_strip_y1) )
00619                 {
00620                     uint32_t i_mask;
00621                     i_vector_flags = GET4BYTES( p_data );
00622                     i_chunk_size -= 4;
00623                     i_mask = 0x80000000UL;
00624 
00625                     while( (i_chunk_size > 0 ) && ( i_mask )
00626                            && ( i_y < i_strip_y2 - i_strip_y1 ) )
00627                     {
00628                         if( i_vector_flags&i_mask )
00629                         {
00630                             i_mask >>= 1;
00631                             if( !i_mask )
00632                             {
00633                                 if( i_chunk_size < 4 )
00634                                 {
00635                                     break;
00636                                 }
00637                                 i_vector_flags = GET4BYTES( p_data );
00638                                 i_chunk_size -= 4;
00639                                 i_mask = 0x80000000UL;
00640                             }
00641                             if( i_vector_flags&i_mask )
00642                             {
00643                                 if( i_chunk_size < 4 ) break;
00644                                 cinepak_Getv4( p_context,
00645                                                i_strip,
00646                                                i_strip_x1 + i_x,
00647                                                i_strip_y1 + i_y,
00648                                                i_strip_x2, i_strip_y2,
00649                                                p_data );
00650                                 p_data += 4;
00651                                 i_chunk_size -= 4;
00652                             }
00653                             else
00654                             {
00655                                 if( i_chunk_size < 1 ) break;
00656                                 cinepak_Getv1( p_context,
00657                                                i_strip,
00658                                                i_strip_x1 + i_x,
00659                                                i_strip_y1 + i_y,
00660                                                i_strip_x2, i_strip_y2,
00661                                                p_data );
00662                                 p_data++;
00663                                 i_chunk_size--;
00664                             }
00665                         }
00666                         i_mask >>= 1;
00667 
00668                         i_x += 4;
00669                         if( i_x >= i_strip_x2 - i_strip_x1 )
00670                         {
00671                             i_x = 0;
00672                             i_y += 4;
00673                         }
00674                     }
00675                 }
00676                 break;
00677 
00678             case( 0x3200 ): /* load intra picture but all v1*/
00679                 while( ( i_chunk_size > 0 ) &&
00680                        ( i_y < i_strip_y2 - i_strip_y1 ) )
00681                 {
00682                     cinepak_Getv1( p_context,
00683                                    i_strip,
00684                                    i_strip_x1 + i_x,
00685                                    i_strip_y1 + i_y,
00686                                    i_strip_x2, i_strip_y2,
00687                                    p_data );
00688                     p_data++;
00689                     i_chunk_size--;
00690 
00691                     i_x += 4;
00692                     if( i_x >= i_strip_x2 - i_strip_x1 )
00693                     {
00694                         i_x = 0;
00695                         i_y += 4;
00696                     }
00697                 }
00698                 break;
00699 
00700             default:
00701                 break;
00702 
00703             }
00704             p_data += i_chunk_size ; /* skip remains bytes */
00705         }
00706     }
00707 
00708     return( 0 );
00709 }

Generated on Tue Dec 20 10:14:28 2005 for vlc-0.8.4a by  doxygen 1.4.2