PCX in ne eigene Datei

This commit is contained in:
Yamagi Burmeister 2010-10-21 07:35:45 +00:00
parent 56f27f1e3a
commit 7d54bf6e41
3 changed files with 135 additions and 103 deletions

View file

@ -150,6 +150,7 @@ ref_gl:
build/ref_gl \
build/ref_gl_game \
build/ref_gl_unix \
build/ref_gl/files \
release
$(MAKE) release/ref_gl.so
@ -330,7 +331,8 @@ OPENGL_OBJS = \
build/ref_gl/gl_rmisc.o \
build/ref_gl/gl_rsurf.o \
build/ref_gl/gl_scrap.o \
build/ref_gl/gl_warp.o
build/ref_gl/gl_warp.o \
build/ref_gl/files/pcx.o
# ----------
@ -797,6 +799,9 @@ build/ref_gl/gl_scrap.o: src/refresh/gl_scrap.c
build/ref_gl/gl_warp.o: src/refresh/gl_warp.c
$(CC) $(CFLAGS_OPENGL) -o $@ -c $<
build/ref_gl/files/pcx.o: src/refresh/files/pcx.c
$(CC) $(CFLAGS_OPENGL) -o $@ -c $<
# ----------
build/ref_gl_game/q_shared.o: src/game/baseq2/q_shared.c

129
src/refresh/files/pcx.c Normal file
View file

@ -0,0 +1,129 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* 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 GNU General Public License for more details.
*
* 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-1307, USA.
*
* =======================================================================
*
* The PCX file format
*
* =======================================================================
*/
#include "../header/local.h"
void
LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *height )
{
byte *raw;
pcx_t *pcx;
int x, y;
int len;
int dataByte, runLength;
byte *out, *pix;
*pic = NULL;
*palette = NULL;
/* load the file */
len = ri.FS_LoadFile( filename, (void **) &raw );
if ( !raw )
{
ri.Con_Printf( PRINT_DEVELOPER, "Bad pcx file %s\n", filename );
return;
}
/* parse the PCX file */
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 );
raw = &pcx->data;
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 );
return;
}
out = malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) );
*pic = out;
pix = out;
if ( palette )
{
*palette = malloc( 768 );
memcpy( *palette, (byte *) pcx + len - 768, 768 );
}
if ( width )
{
*width = pcx->xmax + 1;
}
if ( height )
{
*height = pcx->ymax + 1;
}
for ( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 )
{
for ( x = 0; x <= pcx->xmax; )
{
dataByte = *raw++;
if ( ( dataByte & 0xC0 ) == 0xC0 )
{
runLength = dataByte & 0x3F;
dataByte = *raw++;
}
else
{
runLength = 1;
}
while ( runLength-- > 0 )
{
pix [ x++ ] = dataByte;
}
}
}
if ( raw - (byte *) pcx > len )
{
ri.Con_Printf( PRINT_DEVELOPER, "PCX file %s was malformed", filename );
free( *pic );
*pic = NULL;
}
ri.FS_FreeFile( pcx );
}

View file

@ -20,7 +20,6 @@
/*
Spalten in:
- gl_scrap.c
- gl_pcx.c
- gl_tga.c
- gl_wal.c
@ -278,107 +277,6 @@ GL_ImageList_f ( void )
ri.Con_Printf( PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels );
}
void
LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *height )
{
byte *raw;
pcx_t *pcx;
int x, y;
int len;
int dataByte, runLength;
byte *out, *pix;
*pic = NULL;
*palette = NULL;
/* load the file */
len = ri.FS_LoadFile( filename, (void **) &raw );
if ( !raw )
{
ri.Con_Printf( PRINT_DEVELOPER, "Bad pcx file %s\n", filename );
return;
}
/* parse the PCX file */
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 );
raw = &pcx->data;
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 );
return;
}
out = malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) );
*pic = out;
pix = out;
if ( palette )
{
*palette = malloc( 768 );
memcpy( *palette, (byte *) pcx + len - 768, 768 );
}
if ( width )
{
*width = pcx->xmax + 1;
}
if ( height )
{
*height = pcx->ymax + 1;
}
for ( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 )
{
for ( x = 0; x <= pcx->xmax; )
{
dataByte = *raw++;
if ( ( dataByte & 0xC0 ) == 0xC0 )
{
runLength = dataByte & 0x3F;
dataByte = *raw++;
}
else
{
runLength = 1;
}
while ( runLength-- > 0 )
{
pix [ x++ ] = dataByte;
}
}
}
if ( raw - (byte *) pcx > len )
{
ri.Con_Printf( PRINT_DEVELOPER, "PCX file %s was malformed", filename );
free( *pic );
*pic = NULL;
}
ri.FS_FreeFile( pcx );
}
typedef struct _TargaHeader
{