Reformat pcx.c

This commit is contained in:
Yamagi Burmeister 2012-03-12 09:56:27 +00:00
parent 57b06a8bcf
commit 643cb93e5f

View file

@ -27,7 +27,7 @@
#include "../header/local.h"
void
LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height )
LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height)
{
byte *raw;
pcx_t *pcx;
@ -39,9 +39,9 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height )
char filename[256];
/* Add the extension */
filelen = strlen( origname );
filelen = strlen(origname);
if ( strcmp( origname + filelen - 4, ".pcx" ) )
if (strcmp(origname + filelen - 4, ".pcx"))
{
strncpy(filename, origname, 256);
strncat(filename, ".pcx", 255);
@ -55,68 +55,63 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height )
*palette = NULL;
/* load the file */
len = ri.FS_LoadFile( filename, (void **) &raw );
len = ri.FS_LoadFile(filename, (void **)&raw);
if ( !raw )
if (!raw)
{
ri.Con_Printf( PRINT_DEVELOPER, "Bad pcx file %s\n", filename );
ri.Con_Printf(PRINT_DEVELOPER, "Bad pcx file %s\n", filename);
return;
}
/* parse the PCX file */
pcx = (pcx_t *) raw;
pcx = (pcx_t *)raw;
pcx->xmin = LittleShort( pcx->xmin );
pcx->ymin = LittleShort( pcx->ymin );
pcx->xmax = LittleShort( pcx->xmax );
pcx->ymax = LittleShort( pcx->ymax );
pcx->hres = LittleShort( pcx->hres );
pcx->vres = LittleShort( pcx->vres );
pcx->bytes_per_line = LittleShort( pcx->bytes_per_line );
pcx->palette_type = LittleShort( pcx->palette_type );
pcx->xmin = LittleShort(pcx->xmin);
pcx->ymin = LittleShort(pcx->ymin);
pcx->xmax = LittleShort(pcx->xmax);
pcx->ymax = LittleShort(pcx->ymax);
pcx->hres = LittleShort(pcx->hres);
pcx->vres = LittleShort(pcx->vres);
pcx->bytes_per_line = LittleShort(pcx->bytes_per_line);
pcx->palette_type = LittleShort(pcx->palette_type);
raw = &pcx->data;
if ( ( pcx->manufacturer != 0x0a ) ||
( pcx->version != 5 ) ||
( pcx->encoding != 1 ) ||
( pcx->bits_per_pixel != 8 ) ||
( pcx->xmax >= 640 ) ||
( pcx->ymax >= 480 ) )
if ((pcx->manufacturer != 0x0a) || (pcx->version != 5) || (pcx->encoding != 1) || (pcx->bits_per_pixel != 8) || (pcx->xmax >= 640) || (pcx->ymax >= 480))
{
ri.Con_Printf( PRINT_ALL, "Bad pcx file %s\n", filename );
ri.Con_Printf(PRINT_ALL, "Bad pcx file %s\n", filename);
return;
}
out = malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) );
out = malloc((pcx->ymax + 1) * (pcx->xmax + 1));
*pic = out;
pix = out;
if ( palette )
if (palette)
{
*palette = malloc( 768 );
memcpy( *palette, (byte *) pcx + len - 768, 768 );
*palette = malloc(768);
memcpy(*palette, (byte *)pcx + len - 768, 768);
}
if ( width )
if (width)
{
*width = pcx->xmax + 1;
}
if ( height )
if (height)
{
*height = pcx->ymax + 1;
}
for ( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 )
for (y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1)
{
for ( x = 0; x <= pcx->xmax; )
for (x = 0; x <= pcx->xmax; )
{
dataByte = *raw++;
if ( ( dataByte & 0xC0 ) == 0xC0 )
if ((dataByte & 0xC0) == 0xC0)
{
runLength = dataByte & 0x3F;
dataByte = *raw++;
@ -126,39 +121,42 @@ LoadPCX ( char *origname, byte **pic, byte **palette, int *width, int *height )
runLength = 1;
}
while ( runLength-- > 0 )
while (runLength-- > 0)
{
pix [ x++ ] = dataByte;
pix[x++] = dataByte;
}
}
}
if ( raw - (byte *) pcx > len )
if (raw - (byte *)pcx > len)
{
ri.Con_Printf( PRINT_DEVELOPER, "PCX file %s was malformed", filename );
free( *pic );
ri.Con_Printf(PRINT_DEVELOPER, "PCX file %s was malformed", filename);
free(*pic);
*pic = NULL;
}
ri.FS_FreeFile( pcx );
ri.FS_FreeFile(pcx);
}
qboolean
GetPCXInfo (char *filename, int *width, int *height)
GetPCXInfo(char *filename, int *width, int *height)
{
pcx_t *pcx;
byte *raw;
ri.FS_LoadFile (filename, (void **)&raw);
ri.FS_LoadFile(filename, (void **)&raw);
if (!raw)
{
return false;
}
pcx = (pcx_t *)raw;
*width = pcx->xmax + 1;
*height = pcx->ymax + 1;
ri.FS_FreeFile (raw);
ri.FS_FreeFile(raw);
return true;
}