From d186f242b78fbf963436c3a5c3de4b76d4168d8d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 4 Sep 2003 16:32:39 +0000 Subject: [PATCH] DrSpliff's LoadImage code (thanks:) --- include/QF/Makefile.am | 12 ++--- include/QF/image.h | 1 + libs/image/Makefile.am | 2 +- libs/image/image.c | 108 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 include/QF/image.h create mode 100644 libs/image/image.c diff --git a/include/QF/Makefile.am b/include/QF/Makefile.am index 0609e2cf6..2f5db08cd 100644 --- a/include/QF/Makefile.am +++ b/include/QF/Makefile.am @@ -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 diff --git a/include/QF/image.h b/include/QF/image.h new file mode 100644 index 000000000..db46bf5d0 --- /dev/null +++ b/include/QF/image.h @@ -0,0 +1 @@ +tex_t *LoadImage (char *imageFile, QFile *fp); diff --git a/libs/image/Makefile.am b/libs/image/Makefile.am index 5016a3a4c..4f650e4cc 100644 --- a/libs/image/Makefile.am +++ b/libs/image/Makefile.am @@ -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= diff --git a/libs/image/image.c b/libs/image/image.c new file mode 100644 index 000000000..1a4cd9943 --- /dev/null +++ b/libs/image/image.c @@ -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 +#endif +#ifdef HAVE_STRINGS_H +# include +#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); +}