]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/libsdl-image/contrib/IMG_lbm.c
update
[l4.git] / l4 / pkg / libsdl-image / contrib / IMG_lbm.c
index 5ef4b02d1db7e38f0370f46e18bee29875aa0821..f3d66ab76524795c3ac47f316dad4cd9be4fe84a 100644 (file)
@@ -55,7 +55,7 @@ typedef struct
     Uint8 pad1;                        /* dummy value, for padding */
     Uint16 tcolor;             /* transparent color */
     Uint8 xAspect,             /* pixel aspect ratio */
-         yAspect;
+          yAspect;
     Sint16  Lpage;             /* width of the screen in pixels */
     Sint16  Hpage;             /* height of the screen in pixels */
 } BMHD;
@@ -79,7 +79,7 @@ int IMG_isLBM( SDL_RWops *src )
                        is_LBM = 1;
                }
        }
-       SDL_RWseek(src, start, SEEK_SET);
+       SDL_RWseek(src, start, RW_SEEK_SET);
        return( is_LBM );
 }
 
@@ -89,7 +89,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
        SDL_Surface *Image;
        Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
        Uint32      size, bytesloaded, nbcolors;
-       Uint32      i, j, bytesperline, nbplanes, plane, h;
+       Uint32      i, j, bytesperline, nbplanes, stencil, plane, h;
        Uint32      remainingbytes;
        Uint32      width;
        BMHD          bmhd;
@@ -220,7 +220,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
                        if ( size & 1 ) ++size;         /* padding ! */
                        size -= bytesloaded;
                        /* skip the remaining bytes of this chunk */
-                       if ( size )     SDL_RWseek( src, size, SEEK_CUR );
+                       if ( size )     SDL_RWseek( src, size, RW_SEEK_CUR );
                }
        }
 
@@ -238,12 +238,13 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
                nbplanes = 1;
        }
 
-       if ( bmhd.mask & 1 ) ++nbplanes;   /* There is a mask ( 'stencil' ) */
+       stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */
 
        /* Allocate memory for a temporary buffer ( used for
            decompression/deinterleaving ) */
 
-       if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
+       MiniBuf = (void *)malloc( bytesperline * (nbplanes + stencil) );
+       if ( MiniBuf == NULL )
        {
                error="no enough memory for temporary buffer";
                goto done;
@@ -260,7 +261,8 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
        /* There is no palette in 24 bits ILBM file */
        if ( nbcolors>0 && flagHAM==0 )
        {
-               int nbrcolorsfinal = 1 << nbplanes;
+               /* FIXME: Should this include the stencil? See comment below */
+               int nbrcolorsfinal = 1 << (nbplanes + stencil);
                ptr = &colormap[0];
 
                for ( i=0; i<nbcolors; i++ )
@@ -308,7 +310,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
        {
                /* uncompress the datas of each planes */
 
-               for ( plane=0; plane < nbplanes; plane++ )
+               for ( plane=0; plane < (nbplanes+stencil); plane++ )
                {
                        ptr = MiniBuf + ( plane * bytesperline );
 
@@ -331,7 +333,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
 
                                                if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
                                                {
-                                                  error="error reading BODY chunk";
+                                                       error="error reading BODY chunk";
                                                        goto done;
                                                }
                                                memset( ptr, color, count );
@@ -384,7 +386,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
                                {
                                        memset( ptr, 0, 8 );
 
-                                       for ( plane=0; plane < nbplanes; plane++ )
+                                       for ( plane=0; plane < (nbplanes + stencil); plane++ )
                                        {
                                                color = *( MiniBuf + i + ( plane * bytesperline ) );
                                                msk = 0x80;
@@ -474,7 +476,7 @@ done:
 
        if ( error )
        {
-               SDL_RWseek(src, start, SEEK_SET);
+               SDL_RWseek(src, start, RW_SEEK_SET);
                if ( Image ) {
                        SDL_FreeSurface( Image );
                        Image = NULL;