]> git.sesse.net Git - vlc/blobdiff - modules/codec/cinepak.c
macosx: Fix controller playlist toggling to use the contentRect and not the window...
[vlc] / modules / codec / cinepak.c
index 28ef9351f27a271f6a2eec59ecb12beeedbaa331..b7642ec24911bb3240bfc7db3d6aa194f99b9c93 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * cinepak.c: cinepak video decoder 
+ * cinepak.c: cinepak video decoder
  *****************************************************************************
- * Copyright (C) 1999-2001 VideoLAN
- * $Id: cinepak.c,v 1.1 2003/10/02 21:12:45 gbazin Exp $
+ * Copyright (C) 1999-2001 the VideoLAN team
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -10,7 +10,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_vout.h>
+#include <vlc_codec.h>
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  OpenDecoder ( vlc_object_t * );
+static void CloseDecoder( vlc_object_t * );
 
-#include <vlc/vlc.h>
-#include <vlc/vout.h>
-#include <vlc/decoder.h>
-#include <vlc/input.h>
+vlc_module_begin();
+    set_description( N_("Cinepak video decoder") );
+    set_capability( "decoder", 50 );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_VCODEC );
+    set_callbacks( OpenDecoder, CloseDecoder );
+vlc_module_end();
 
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
 #define CINEPAK_MAXSTRIP 32
 
-typedef struct cinepak_codebook_s
+typedef struct
 {
-    u8 i_y[4];
-    u8 i_u, i_v;
-    
+    uint8_t i_y[4];
+    uint8_t i_u, i_v;
+
 } cinepak_codebook_t;
 
-typedef struct cinepak_context_s
+typedef struct
 {
     int b_grayscale; /* force to grayscale */
-    
-    int i_width;
-    int i_height;
+
+    unsigned int i_width;
+    unsigned int i_height;
 
     int i_stride_x;
     int i_stride_y;
-     
-    u *p_y, *p_u, *p_v;
+
+    uint8_t *p_y, *p_u, *p_v;
 
     int i_stride[3]; /* our 3 planes */
     int i_lines[3];
-    u *p_pix[3];
-    
+    uint8_t *p_pix[3];
+
     cinepak_codebook_t codebook_v1[CINEPAK_MAXSTRIP][256];
     cinepak_codebook_t codebook_v4[CINEPAK_MAXSTRIP][256];
-    
+
 } cinepak_context_t;
 
 /*****************************************************************************
@@ -70,87 +89,41 @@ struct decoder_sys_t
     /*
      * Cinepak properties
      */
-    cinepak_context_t *p_context;
-
-    /*
-     * Output properties
-     */
-    vout_thread_t *p_vout;
+    cinepak_context_t context;
 };
 
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int OpenDecoder( vlc_object_t * );
-static int InitDecoder( decoder_t * );
-static int RunDecoder ( decoder_t *, block_t * );
-static int EndDecoder ( decoder_t * );
+static picture_t *DecodeBlock ( decoder_t *, block_t ** );
 
-static int cinepak_decode_frame( cinepak_context_t *, int, u8 * );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-vlc_module_begin();
-    set_description( _("Cinepak video decoder") );
-    set_capability( "decoder", 70 );
-    set_callbacks( OpenDecoder, NULL );
-vlc_module_end();
+static int cinepak_decode_frame( cinepak_context_t *, size_t, uint8_t * );
 
 /*****************************************************************************
  * OpenDecoder: probe the decoder and return score
  *****************************************************************************
- * Tries to launch a decoder and return score so that the interface is able 
+ * Tries to launch a decoder and return score so that the interface is able
  * to chose.
  *****************************************************************************/
 static int OpenDecoder( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
-    
-    switch( p_dec->p_fifo->i_fourcc )
-    {
-        case VLC_FOURCC('c','v','i','d'):
-        case VLC_FOURCC('C','V','I','D'):
-            break;
-
-        default:
-            return VLC_EGENERIC;
-    }
+    decoder_sys_t *p_sys;
+    vlc_value_t val;
 
-    /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys =
-          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
+    if( p_dec->fmt_in.i_codec != VLC_FOURCC('c','v','i','d') &&
+        p_dec->fmt_in.i_codec != VLC_FOURCC('C','V','I','D') )
     {
-        msg_Err( p_dec, "out of memory" );
         return VLC_EGENERIC;
     }
 
-    p_dec->pf_init = InitDecoder;
-    p_dec->pf_decode = RunDecoder;
-    p_dec->pf_end = EndDecoder;
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * InitDecoder: Initalize the decoder
- *****************************************************************************/
-static int InitDecoder( decoder_t *p_dec )
-{
-    decoder_sys_t *p_sys = p_dec->p_sys;
-    vlc_value_t val;
-
-    p_sys->p_vout = NULL;
-
-    if( !(p_sys->p_context = malloc( sizeof( cinepak_context_t ) ) ) )
-    {
-        msg_Err( p_dec, "out of memory" );
-    }
-    memset( p_sys->p_context, 0, sizeof( cinepak_context_t ) );
+    /* Allocate the memory needed to store the decoder's structure */
+    if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL )
+        return VLC_ENOMEM;
+    memset( &p_sys->context, 0, sizeof( cinepak_context_t ) );
 
     var_Create( p_dec, "grayscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Get( p_dec, "grayscale", &val );
-    p_sys->p_context->b_grayscale = val.b_bool;
+    p_sys->context.b_grayscale = val.b_bool;
+
+    p_dec->pf_decode_video = DecodeBlock;
 
     msg_Dbg( p_dec, "cinepak decoder started" );
 
@@ -158,101 +131,85 @@ static int InitDecoder( decoder_t *p_dec )
 }
 
 /****************************************************************************
- * RunDecoder: the whole thing
+ * DecodeBlock: the whole thing
  ****************************************************************************
  * This function must be fed with whole frames.
  ****************************************************************************/
-static int RunDecoder( decoder_t *p_dec, block_t *p_block )
+static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     int i_status, i_plane;
-    u8 *p_dst, *p_src;
+    uint8_t *p_dst, *p_src;
     picture_t *p_pic;
+    block_t *p_block;
 
-    i_status = cinepak_decode_frame( p_sys->p_context,
-                                     p_block->i_buffer, p_block->p_buffer );
-    if( i_status < 0 )
+    if( !pp_block || !*pp_block )
     {
-        msg_Warn( p_dec, "cannot decode one frame (%d bytes)",
-                  p_block->i_buffer );
-        block_Release( p_block );
-        return VLC_SUCCESS;
+        return NULL;
     }
+    p_block = *pp_block;
+    *pp_block = NULL;
 
-    /* Check our vout */
-    p_sys->p_vout = vout_Request( p_dec, p_sys->p_vout,
-                                  p_sys->p_context->i_width,
-                                  p_sys->p_context->i_height,
-                                  VLC_FOURCC('I','4','2','0'),
-                                  p_sys->p_context->i_width
-                                    * VOUT_ASPECT_FACTOR
-                                    / p_sys->p_context->i_height );
-    if( !p_sys->p_vout )
+    i_status = cinepak_decode_frame( &p_sys->context, p_block->i_buffer,
+                                     p_block->p_buffer );
+    if( i_status < 0 )
     {
-        msg_Err( p_dec, "cannot create vout" );
+        msg_Warn( p_dec, "cannot decode one frame (%zu bytes)",
+                  p_block->i_buffer );
         block_Release( p_block );
-        return VLC_EGENERIC;
+        return NULL;
     }
 
-    /* Send decoded frame to vout */
-    while( !(p_pic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 ) ) )
-    {
-        if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
-        {
-            block_Release( p_block );
-            return VLC_EGENERIC;
-        }
-        msleep( VOUT_OUTMEM_SLEEP );
-    }
+    p_dec->fmt_out.video.i_width = p_sys->context.i_width;
+    p_dec->fmt_out.video.i_height = p_sys->context.i_height;
+    p_dec->fmt_out.video.i_aspect = p_sys->context.i_width
+        * VOUT_ASPECT_FACTOR / p_sys->context.i_height;
+    p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
 
-    for( i_plane = 0; i_plane < 3; i_plane++ )
+    /* Get a new picture */
+    if( ( p_pic = p_dec->pf_vout_buffer_new( p_dec ) ) )
     {
-        int i_line, i_lines;
+        for( i_plane = 0; i_plane < 3; i_plane++ )
+        {
+            int i_line, i_lines;
 
-        p_dst = p_pic->p[i_plane].p_pixels;
-        p_src = p_sys->p_context->p_pix[i_plane];
+            p_dst = p_pic->p[i_plane].p_pixels;
+            p_src = p_sys->context.p_pix[i_plane];
 
-        i_lines = __MIN( p_sys->p_context->i_lines[i_plane],
-                         p_pic->p[i_plane].i_lines );
-        for( i_line = 0; i_line < i_lines; i_line++ )
-        {
-            memcpy( p_dst, p_src,
-                    __MIN( p_pic->p[i_plane].i_pitch,
-                           p_sys->p_context->i_stride[i_plane] ) );
-            p_dst += p_pic->p[i_plane].i_pitch;
-            p_src += p_sys->p_context->i_stride[i_plane];
+            i_lines = __MIN( p_sys->context.i_lines[i_plane],
+                             p_pic->p[i_plane].i_visible_lines );
+            for( i_line = 0; i_line < i_lines; i_line++ )
+            {
+                memcpy( p_dst, p_src,
+                        __MIN( p_pic->p[i_plane].i_pitch,
+                               p_sys->context.i_stride[i_plane] ) );
+                p_dst += p_pic->p[i_plane].i_pitch;
+                p_src += p_sys->context.i_stride[i_plane];
+            }
         }
-    }
 
-    vout_DatePicture( p_sys->p_vout, p_pic, p_block->i_pts);
-    vout_DisplayPicture( p_sys->p_vout, p_pic );
+        p_pic->date = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
+    }
 
     block_Release( p_block );
-    return VLC_SUCCESS;
+    return p_pic;
 }
 
 /*****************************************************************************
- * EndDecoder: theora decoder destruction
+ * CloseDecoder: decoder destruction
  *****************************************************************************/
-static int EndDecoder( decoder_t *p_dec )
+static void CloseDecoder( vlc_object_t *p_this )
 {
+    decoder_t     *p_dec = (decoder_t *)p_this;
     decoder_sys_t *p_sys = p_dec->p_sys;
     int i;
 
     msg_Dbg( p_dec, "cinepak decoder stopped" );
 
-    vout_Request( p_dec, p_sys->p_vout, 0, 0, 0, 0 );
-
     for( i = 0; i < 3; i++ )
-    {
-        if( p_sys->p_context->p_pix[i] ) free( p_sys->p_context->p_pix[i] );
-    }
-
-    free( p_sys->p_context );
+        free( p_sys->context.p_pix[i] );
 
     free( p_sys );
-
-    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -268,25 +225,22 @@ static int EndDecoder( decoder_t *p_dec )
 #define GET4BYTES( p ) \
     GetDWBE( p ); p+= 4;
 
-#define FREE( p ) \
-    if( p ) free( p )
-
 static void cinepak_LoadCodebook( cinepak_codebook_t *p_codebook,
-                                  u8 *p_data, int b_grayscale )
+                                  uint8_t *p_data, int b_grayscale )
 {
     int i, i_y[4], i_u, i_v, i_Cb, i_Cr;
     int i_uv;
 #define SCALEBITS 12
 #define FIX( x ) ( (int)( (x) * ( 1L << SCALEBITS ) + 0.5 ) )
-    
+
     for( i = 0; i < 4; i++ )
     {
-        i_y[i] = (u8)( *(p_data++) );
+        i_y[i] = (uint8_t)( *(p_data++) );
     }
     if( b_grayscale )
     {
-        i_u  = (s8)( *(p_data++) );
-        i_v  = (s8)( *(p_data++) );
+        i_u  = (int8_t)( *(p_data++) );
+        i_v  = (int8_t)( *(p_data++) );
     }
     else
     {
@@ -320,12 +274,22 @@ static void cinepak_LoadCodebook( cinepak_codebook_t *p_codebook,
 
 static void cinepak_Getv4( cinepak_context_t *p_context,
                            int i_strip, int i_x, int i_y,
-                           int i_x2, int i_y2, u8 *p_data )
+                           uint8_t *p_data )
 {
-    u8 i_index[4];
+    uint8_t i_index[4];
     int i,j;
 
-    u8 *p_dst_y, *p_dst_u, *p_dst_v;
+    size_t y_max = p_context->i_stride[0] * ( i_y + 5 ) + i_x + 5;
+    size_t u_max = p_context->i_stride[1] * ( ( i_y/2 ) + 2 ) + 2 + ( i_x / 2 );
+    size_t v_max = p_context->i_stride[2] * ( ( i_y/2 ) + 2 ) + 2 + ( i_x / 2 );
+    size_t y_siz = p_context->i_stride[0] * p_context->i_lines[0];
+    size_t u_siz = p_context->i_stride[1] * p_context->i_lines[1];
+    size_t v_siz = p_context->i_stride[2] * p_context->i_lines[2];
+    /* boundary check */
+    if( y_max >= y_siz || u_max >= u_siz || v_max >= v_siz )
+        return;
+
+    uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
 #define PIX_SET_Y( x, y, v ) \
     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
 
@@ -346,18 +310,18 @@ static void cinepak_Getv4( cinepak_context_t *p_context,
     {
         for( j = 0; j < 2; j ++ )
         {
-            PIX_SET_Y( 2*j + 0, 2*i + 0, 
+            PIX_SET_Y( 2*j + 0, 2*i + 0,
                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[0]);
-            PIX_SET_Y( 2*j + 1, 2*i + 0, 
+            PIX_SET_Y( 2*j + 1, 2*i + 0,
                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[1]);
-            PIX_SET_Y( 2*j + 0, 2*i + 1, 
+            PIX_SET_Y( 2*j + 0, 2*i + 1,
                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[2]);
-            PIX_SET_Y( 2*j + 1, 2*i + 1, 
+            PIX_SET_Y( 2*j + 1, 2*i + 1,
                        p_context->codebook_v4[i_strip][i_index[j+2*i]].i_y[3]);
 
-            PIX_SET_UV( 1, p_dst_u, j, i, 
+            PIX_SET_UV( 1, p_dst_u, j, i,
                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_u );
-            PIX_SET_UV( 2, p_dst_v, j, i, 
+            PIX_SET_UV( 2, p_dst_v, j, i,
                         p_context->codebook_v4[i_strip][i_index[j+2*i]].i_v );
         }
     }
@@ -367,12 +331,22 @@ static void cinepak_Getv4( cinepak_context_t *p_context,
 
 static void cinepak_Getv1( cinepak_context_t *p_context,
                            int i_strip, int i_x,  int i_y,
-                           int i_x2, int i_y2, u8 *p_data )
+                           uint8_t *p_data )
 {
-    u8 i_index;
+    uint8_t i_index;
     int i,j;
 
-    u8 *p_dst_y, *p_dst_u, *p_dst_v;
+    size_t y_max = p_context->i_stride[0] * ( i_y + 5 ) + i_x + 5;
+    size_t u_max = p_context->i_stride[1] * ( ( i_y/2 ) + 2 ) + 2 + ( i_x / 2 );
+    size_t v_max = p_context->i_stride[2] * ( ( i_y/2 ) + 2 ) + 2 + ( i_x / 2 );
+    size_t y_siz = p_context->i_stride[0] * p_context->i_lines[0];
+    size_t u_siz = p_context->i_stride[1] * p_context->i_lines[1];
+    size_t v_siz = p_context->i_stride[2] * p_context->i_lines[2];
+    /* boundary check */
+    if( y_max >= y_siz || u_max >= u_siz || v_max >= v_siz )
+        return;
+
+    uint8_t *p_dst_y, *p_dst_u, *p_dst_v;
 #define PIX_SET_Y( x, y, v ) \
     p_dst_y[(x) + (y)* p_context->i_stride[0]] = (v);
 
@@ -390,18 +364,18 @@ static void cinepak_Getv1( cinepak_context_t *p_context,
     {
         for( j = 0; j < 2; j ++ )
         {
-            PIX_SET_Y( 2*j + 0, 2*i + 0, 
+            PIX_SET_Y( 2*j + 0, 2*i + 0,
                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
-            PIX_SET_Y( 2*j + 1, 2*i + 0, 
+            PIX_SET_Y( 2*j + 1, 2*i + 0,
                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
-            PIX_SET_Y( 2*j + 0, 2*i + 1, 
+            PIX_SET_Y( 2*j + 0, 2*i + 1,
                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
-            PIX_SET_Y( 2*j + 1, 2*i + 1, 
+            PIX_SET_Y( 2*j + 1, 2*i + 1,
                        p_context->codebook_v1[i_strip][i_index].i_y[2*i+j] );
 
-            PIX_SET_UV( 1,p_dst_u, j, i, 
+            PIX_SET_UV( 1,p_dst_u, j, i,
                         p_context->codebook_v1[i_strip][i_index].i_u );
-            PIX_SET_UV( 2,p_dst_v, j, i, 
+            PIX_SET_UV( 2,p_dst_v, j, i,
                         p_context->codebook_v1[i_strip][i_index].i_v );
         }
     }
@@ -413,15 +387,15 @@ static void cinepak_Getv1( cinepak_context_t *p_context,
 /*****************************************************************************
  * The function that decode one frame
  *****************************************************************************/
-static int cinepak_decode_frame( cinepak_context_t *p_context, 
-                                 int i_length, u8 *p_data )
+static int cinepak_decode_frame( cinepak_context_t *p_context,
+                                 size_t i_length, uint8_t *p_data )
 {
     int i_strip;
 
-    int i_frame_flags;
-    int i_frame_size;
-    int i_width, i_height;
-    int i_frame_strips;
+    int8_t i_frame_flags;
+    uint32_t i_frame_size;
+    uint16_t i_width, i_height;
+    uint16_t i_frame_strips;
     int i_index;
     int i_strip_x1 =0, i_strip_y1=0;
     int i_strip_x2 =0, i_strip_y2=0;
@@ -439,7 +413,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
     i_height = GET2BYTES( p_data );
     i_frame_strips = GET2BYTES( p_data );
 
-    if( !i_frame_size || !i_width || !i_height )
+    if( !i_frame_size || !i_width || !i_height ||
+        i_width > 0xffff-3 || i_height > 0xffff-3)
     {
         /* Broken header */
         return( -1 );
@@ -452,14 +427,14 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
         int i;
         for( i = 0; i < 3; i++ )
         {
-            FREE( p_context->p_pix[i] );
+            free( p_context->p_pix[i] );
         }
 
         p_context->i_width = i_width;
         p_context->i_height = i_height;
 
         p_context->i_stride[0] = ( i_width + 3 ) & 0xfffc;
-        p_context->i_stride[1] = p_context->i_stride[2] = 
+        p_context->i_stride[1] = p_context->i_stride[2] =
                 p_context->i_stride[0] / 2;
 
         p_context->i_lines[0] = ( i_height + 3 ) & 0xfffc;
@@ -468,8 +443,10 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
 
         for( i = 0; i < 3; i++ )
         {
-            p_context->p_pix[i] = malloc( p_context->i_stride[i] * 
+            p_context->p_pix[i] = malloc( p_context->i_stride[i] *
                                           p_context->i_lines[i] );
+            if( p_context->p_pix[i] == NULL )
+                return -1;
             /* Set it to all black */
             memset( p_context->p_pix[i], ( i == 0 ) ? 0 : 128 ,
                     p_context->i_stride[i] * p_context->i_lines[i] );
@@ -490,18 +467,18 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
     /* Now decode each strip */
     for( i_strip = 0; i_strip < i_frame_strips; i_strip++ )
     {
-        int i_strip_id;
-        int i_strip_size;
+        uint16_t i_strip_size;
 
         if( i_length <= 12 )
         {
             break;
         }
 
-        i_strip_id   = GET2BYTES( p_data );
+        p_data += 2; /* int16_t i_strip_id   = GET2BYTES( p_data ); */
+
         i_strip_size = GET2BYTES( p_data );
         i_strip_size = __MIN( i_strip_size, i_length );
-        /* FIXME I don't really understand how it's work; */
+        /* FIXME I don't really understand how it works; */
         i_strip_y1  = i_strip_y2 + GET2BYTES( p_data );
         i_strip_x1  = GET2BYTES( p_data );
         i_strip_y2  = i_strip_y2 + GET2BYTES( p_data );
@@ -513,11 +490,11 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
         /* init codebook , if needed */
         if( ( i_strip > 0 )&&( !(i_frame_flags&0x01) ) )
         {
-            memcpy( &p_context->codebook_v1[i_strip], 
+            memcpy( &p_context->codebook_v1[i_strip],
                     &p_context->codebook_v1[i_strip-1],
                     sizeof(cinepak_codebook_t[256] ) );
 
-            memcpy( &p_context->codebook_v4[i_strip], 
+            memcpy( &p_context->codebook_v4[i_strip],
                     &p_context->codebook_v4[i_strip-1],
                     sizeof(cinepak_codebook_t[256] ) );
         }
@@ -530,19 +507,19 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
 
             int i_chunk_id;
             int i_chunk_size;
-            u32 i_vector_flags;
+            uint32_t i_vector_flags;
             int i_count;
             int i;
             int i_x, i_y; /* (0,0) begin in fact at (x1,y1) ... */
 
             i_chunk_id   = GET2BYTES( p_data );
             i_chunk_size = GET2BYTES( p_data );
-            i_chunk_size  = __MIN( i_chunk_size, i_strip_size ); 
+            i_chunk_size  = __MIN( i_chunk_size, i_strip_size );
             i_strip_size -= i_chunk_size;
 
             i_chunk_size -= 4;
 
-            i_x = 0; 
+            i_x = 0;
             i_y = 0;
             if( i_chunk_size < 0 )
             {
@@ -564,8 +541,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
 
                 for( i = 0; i < i_count; i++ )
                 {
-                    cinepak_LoadCodebook( &((*p_codebook)[i_strip][i]), 
-                                          p_data, 
+                    cinepak_LoadCodebook( &((*p_codebook)[i_strip][i]),
+                                          p_data,
                                           i_mode&~p_context->b_grayscale );
                     p_data += i_mode ? 6 : 4;
                     i_chunk_size -= i_mode ? 6 : 4;
@@ -627,9 +604,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                         {
                             cinepak_Getv4( p_context,
                                            i_strip,
-                                           i_strip_x1 + i_x, 
+                                           i_strip_x1 + i_x,
                                            i_strip_y1 + i_y,
-                                           i_strip_x2, i_strip_y2,
                                            p_data );
                             p_data += 4;
                             i_chunk_size -= 4;
@@ -638,9 +614,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                         {
                             cinepak_Getv1( p_context,
                                            i_strip,
-                                           i_strip_x1 + i_x, 
+                                           i_strip_x1 + i_x,
                                            i_strip_y1 + i_y,
-                                           i_strip_x2, i_strip_y2,
                                            p_data );
                             p_data++;
                             i_chunk_size--;
@@ -654,13 +629,13 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                         }
                         i_vector_flags <<= 1;
                     }
-                } 
+                }
                 break;
 
             case( 0x3100 ): /* load image Inter */
                 while( ( i_chunk_size > 4 )&&( i_y < i_strip_y2 - i_strip_y1) )
                 {
-                    u32 i_mask;
+                    uint32_t i_mask;
                     i_vector_flags = GET4BYTES( p_data );
                     i_chunk_size -= 4;
                     i_mask = 0x80000000UL;
@@ -676,7 +651,7 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                                 if( i_chunk_size < 4 )
                                 {
                                     break;
-                                } 
+                                }
                                 i_vector_flags = GET4BYTES( p_data );
                                 i_chunk_size -= 4;
                                 i_mask = 0x80000000UL;
@@ -686,9 +661,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                                 if( i_chunk_size < 4 ) break;
                                 cinepak_Getv4( p_context,
                                                i_strip,
-                                               i_strip_x1 + i_x, 
+                                               i_strip_x1 + i_x,
                                                i_strip_y1 + i_y,
-                                               i_strip_x2, i_strip_y2,
                                                p_data );
                                 p_data += 4;
                                 i_chunk_size -= 4;
@@ -698,9 +672,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                                 if( i_chunk_size < 1 ) break;
                                 cinepak_Getv1( p_context,
                                                i_strip,
-                                               i_strip_x1 + i_x, 
+                                               i_strip_x1 + i_x,
                                                i_strip_y1 + i_y,
-                                               i_strip_x2, i_strip_y2,
                                                p_data );
                                 p_data++;
                                 i_chunk_size--;
@@ -715,7 +688,7 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                             i_y += 4;
                         }
                     }
-                } 
+                }
                 break;
 
             case( 0x3200 ): /* load intra picture but all v1*/
@@ -724,9 +697,8 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                 {
                     cinepak_Getv1( p_context,
                                    i_strip,
-                                   i_strip_x1 + i_x, 
+                                   i_strip_x1 + i_x,
                                    i_strip_y1 + i_y,
-                                   i_strip_x2, i_strip_y2,
                                    p_data );
                     p_data++;
                     i_chunk_size--;
@@ -737,7 +709,7 @@ static int cinepak_decode_frame( cinepak_context_t *p_context,
                         i_x = 0;
                         i_y += 4;
                     }
-                } 
+                }
                 break;
 
             default: