From 7d54bf6e4129944ee8d1ce42cb15a5aa45902aa2 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Thu, 21 Oct 2010 07:35:45 +0000 Subject: [PATCH] PCX in ne eigene Datei --- Makefile | 7 ++- src/refresh/files/pcx.c | 129 ++++++++++++++++++++++++++++++++++++++++ src/refresh/gl_image.c | 102 ------------------------------- 3 files changed, 135 insertions(+), 103 deletions(-) create mode 100644 src/refresh/files/pcx.c diff --git a/Makefile b/Makefile index 600f5ea2..1cc0fe13 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/refresh/files/pcx.c b/src/refresh/files/pcx.c new file mode 100644 index 00000000..f52834f6 --- /dev/null +++ b/src/refresh/files/pcx.c @@ -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 ); +} diff --git a/src/refresh/gl_image.c b/src/refresh/gl_image.c index 80ee20fc..92285cea 100644 --- a/src/refresh/gl_image.c +++ b/src/refresh/gl_image.c @@ -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 {