DrSpliff's LoadImage code (thanks:)

This commit is contained in:
Bill Currie 2003-09-04 16:32:39 +00:00
parent ff43d61f81
commit d186f242b7
4 changed files with 116 additions and 7 deletions

View file

@ -3,9 +3,9 @@ SUBDIRS = GL plugin
includedir = $(prefix)/include/QF
include_HEADERS = bspfile.h cbuf.h cdaudio.h checksum.h clip_hull.h cmd.h \
console.h crc.h csqc.h cvar.h dstring.h draw.h gib.h hash.h hl.h \
idparse.h in_event.h info.h input.h joystick.h keys.h link.h llist.h \
locs.h mathlib.h mdfour.h model.h modelgen.h msg.h pak.h pakfile.h \
pcx.h png.h plugin.h pr_comp.h pr_debug.h pr_obj.h progs.h qargs.h \
qdefs.h qendian.h qfplist.h qtypes.h quakefs.h quakeio.h render.h riff.h \
screen.h sizebuf.h skin.h sound.h spritegn.h sys.h teamplay.h texture.h \
tga.h uint32.h va.h ver_check.h vid.h view.h wad.h zone.h
idparse.h image.h in_event.h info.h input.h joystick.h keys.h link.h \
llist.h locs.h mathlib.h mdfour.h model.h modelgen.h msg.h pak.h \
pakfile.h pcx.h png.h plugin.h pr_comp.h pr_debug.h pr_obj.h progs.h \
qargs.h qdefs.h qendian.h qfplist.h qtypes.h quakefs.h quakeio.h render.h \
riff.h screen.h sizebuf.h skin.h sound.h spritegn.h sys.h teamplay.h \
texture.h tga.h uint32.h va.h ver_check.h vid.h view.h wad.h zone.h

1
include/QF/image.h Normal file
View file

@ -0,0 +1 @@
tex_t *LoadImage (char *imageFile, QFile *fp);

View file

@ -8,6 +8,6 @@ libQFimage_la_LDFLAGS= -version-info 1:0:0
libQFimage_la_LIBADD= -lpng
libQFimage_la_DEPENDENCIES=
libQFimage_la_SOURCES= \
pcx.c png.c tga.c
image.c pcx.c png.c tga.c
EXTRA_DIST=

108
libs/image/image.c Normal file
View file

@ -0,0 +1,108 @@
/*
image.c
General image handling
Copyright (C) 2003 Harry Roberts
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((unused)) const char rcsid[] =
"$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "compat.h"
#include "QF/qtypes.h"
#include "QF/quakefs.h"
#include "QF/texture.h"
#include "QF/png.h"
#include "QF/tga.h"
#include "QF/pcx.h"
#include "QF/image.h"
tex_t *
LoadImage (char *imageFile, QFile *fp)
{
int tmp;
char *tmpFile, *ext;
tex_t *tex = NULL;
/* Get the file name without extension */
tmp = strlen (imageFile);
tmpFile = strdup (imageFile);
ext = strrchr (tmpFile, '.');
ext[0] = '\0';
if (strlen(tmpFile) != (tmp - 4))
return (NULL); /* Extension must be 3 characters long */
tmp = 0;
/* Check for a .png */
strcat (ext, ".png");
QFS_FOpenFile (tmpFile, &fp);
if (fp) {
tex = LoadPNG (fp);
Qclose (fp);
tmp = 1;
}
/* Check for a .tga */
if (tmp == 0) {
ext = strrchr (tmpFile, '.');
ext[0] = '\0';
strcat (ext, ".tga");
QFS_FOpenFile (tmpFile, &fp);
if (fp) {
tex = LoadTGA (fp);
Qclose (fp);
tmp = 1;
}
}
/* Check for a .pcx */
/*if (tmp == 0) {
ext = strrchr (tmpFile, '.');
ext[0] = '\0';
strcat (ext, ".tga");
QFS_FOpenFile (tmpFile, &fp);
if (fp) {
tex = LoadPCX (fp); // FIXME: needs extra arguments, how should we be passed them?
Qclose (fp);
tmp = 1;
}
}*/
free (tmpFile);
return (tex);
}