IMG_lbm.c
changeset 251 a6565b353095
parent 236 cce1251de477
child 280 ec4ae96c100c
equal deleted inserted replaced
250:692379215a48 251:a6565b353095
    53     Uint8 mask;			/* mask type ( 0 => no mask ) */
    53     Uint8 mask;			/* mask type ( 0 => no mask ) */
    54     Uint8 tcomp;		/* compression type */
    54     Uint8 tcomp;		/* compression type */
    55     Uint8 pad1;			/* dummy value, for padding */
    55     Uint8 pad1;			/* dummy value, for padding */
    56     Uint16 tcolor;		/* transparent color */
    56     Uint16 tcolor;		/* transparent color */
    57     Uint8 xAspect,		/* pixel aspect ratio */
    57     Uint8 xAspect,		/* pixel aspect ratio */
    58          yAspect;
    58           yAspect;
    59     Sint16  Lpage;		/* width of the screen in pixels */
    59     Sint16  Lpage;		/* width of the screen in pixels */
    60     Sint16  Hpage;		/* height of the screen in pixels */
    60     Sint16  Hpage;		/* height of the screen in pixels */
    61 } BMHD;
    61 } BMHD;
    62 
    62 
    63 int IMG_isLBM( SDL_RWops *src )
    63 int IMG_isLBM( SDL_RWops *src )
    87 {
    87 {
    88 	int start;
    88 	int start;
    89 	SDL_Surface *Image;
    89 	SDL_Surface *Image;
    90 	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    90 	Uint8       id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
    91 	Uint32      size, bytesloaded, nbcolors;
    91 	Uint32      size, bytesloaded, nbcolors;
    92 	Uint32      i, j, bytesperline, nbplanes, plane, h;
    92 	Uint32      i, j, bytesperline, nbplanes, stencil, plane, h;
    93 	Uint32      remainingbytes;
    93 	Uint32      remainingbytes;
    94 	Uint32      width;
    94 	Uint32      width;
    95 	BMHD	      bmhd;
    95 	BMHD	      bmhd;
    96 	char        *error;
    96 	char        *error;
    97 	Uint8       flagHAM,flagEHB;
    97 	Uint8       flagHAM,flagEHB;
   236 	{
   236 	{
   237 		bytesperline *= 8;
   237 		bytesperline *= 8;
   238 		nbplanes = 1;
   238 		nbplanes = 1;
   239 	}
   239 	}
   240 
   240 
   241 	if ( bmhd.mask & 1 ) ++nbplanes;   /* There is a mask ( 'stencil' ) */
   241 	stencil = (bmhd.mask & 1);   /* There is a mask ( 'stencil' ) */
   242 
   242 
   243 	/* Allocate memory for a temporary buffer ( used for
   243 	/* Allocate memory for a temporary buffer ( used for
   244            decompression/deinterleaving ) */
   244            decompression/deinterleaving ) */
   245 
   245 
   246 	if ( ( MiniBuf = (void *)malloc( bytesperline * nbplanes ) ) == NULL )
   246 	MiniBuf = (void *)malloc( bytesperline * (nbplanes + stencil) );
       
   247 	if ( MiniBuf == NULL )
   247 	{
   248 	{
   248 		error="no enough memory for temporary buffer";
   249 		error="no enough memory for temporary buffer";
   249 		goto done;
   250 		goto done;
   250 	}
   251 	}
   251 
   252 
   258 	/* Update palette informations */
   259 	/* Update palette informations */
   259 
   260 
   260 	/* There is no palette in 24 bits ILBM file */
   261 	/* There is no palette in 24 bits ILBM file */
   261 	if ( nbcolors>0 && flagHAM==0 )
   262 	if ( nbcolors>0 && flagHAM==0 )
   262 	{
   263 	{
   263 		int nbrcolorsfinal = 1 << nbplanes;
   264 		/* FIXME: Should this include the stencil? See comment below */
       
   265 		int nbrcolorsfinal = 1 << (nbplanes + stencil);
   264 		ptr = &colormap[0];
   266 		ptr = &colormap[0];
   265 
   267 
   266 		for ( i=0; i<nbcolors; i++ )
   268 		for ( i=0; i<nbcolors; i++ )
   267 		{
   269 		{
   268 			Image->format->palette->colors[i].r = *ptr++;
   270 			Image->format->palette->colors[i].r = *ptr++;
   306 
   308 
   307 	for ( h=0; h < bmhd.h; h++ )
   309 	for ( h=0; h < bmhd.h; h++ )
   308 	{
   310 	{
   309 		/* uncompress the datas of each planes */
   311 		/* uncompress the datas of each planes */
   310 
   312 
   311 		for ( plane=0; plane < nbplanes; plane++ )
   313 		for ( plane=0; plane < (nbplanes+stencil); plane++ )
   312 		{
   314 		{
   313 			ptr = MiniBuf + ( plane * bytesperline );
   315 			ptr = MiniBuf + ( plane * bytesperline );
   314 
   316 
   315 			remainingbytes = bytesperline;
   317 			remainingbytes = bytesperline;
   316 
   318 
   329 						count ^= 0xFF;
   331 						count ^= 0xFF;
   330 						count += 2; /* now it */
   332 						count += 2; /* now it */
   331 
   333 
   332 						if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
   334 						if ( ( count > remainingbytes ) || !SDL_RWread( src, &color, 1, 1 ) )
   333 						{
   335 						{
   334 						   error="error reading BODY chunk";
   336 							error="error reading BODY chunk";
   335 							goto done;
   337 							goto done;
   336 						}
   338 						}
   337 						memset( ptr, color, count );
   339 						memset( ptr, color, count );
   338 					}
   340 					}
   339 					else
   341 					else
   382 
   384 
   383 				for ( i=0; i < size; i++ )
   385 				for ( i=0; i < size; i++ )
   384 				{
   386 				{
   385 					memset( ptr, 0, 8 );
   387 					memset( ptr, 0, 8 );
   386 
   388 
   387 					for ( plane=0; plane < nbplanes; plane++ )
   389 					for ( plane=0; plane < (nbplanes + stencil); plane++ )
   388 					{
   390 					{
   389 						color = *( MiniBuf + i + ( plane * bytesperline ) );
   391 						color = *( MiniBuf + i + ( plane * bytesperline ) );
   390 						msk = 0x80;
   392 						msk = 0x80;
   391 
   393 
   392 						for ( j=0; j<8; j++ )
   394 						for ( j=0; j<8; j++ )