From 753dc02debee009d4cb2a378afcdd5be9b091d02 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 4 Sep 2003 18:09:02 +0000 Subject: [PATCH] use dtrings to do the filename manipulation --- include/QF/image.h | 40 +++++++++++++++++++++++++++++- include/QF/png.h | 38 ++++++++++++++++++++++++++++- libs/image/image.c | 61 +++++++++++++++++++--------------------------- 3 files changed, 101 insertions(+), 38 deletions(-) diff --git a/include/QF/image.h b/include/QF/image.h index db46bf5d0..2424cce26 100644 --- a/include/QF/image.h +++ b/include/QF/image.h @@ -1 +1,39 @@ -tex_t *LoadImage (char *imageFile, QFile *fp); +/* + image.h + + General image handling + + Copyright (C) 2003 Harry Roberts + + Author: Harry Roberts + Date: Sep 4 2003 + + 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 + + $Id$ +*/ + +#ifndef __QF_image_h +#define __QF_image_h + +#include "QF/quakeio.h" + +struct tex_s *LoadImage (const char *imageFile, QFile *fp); + +#endif//__QF_image_h diff --git a/include/QF/png.h b/include/QF/png.h index 28656e890..599cf713b 100644 --- a/include/QF/png.h +++ b/include/QF/png.h @@ -1,3 +1,39 @@ +/* + png.h + + PNG image handling + + Copyright (C) 2003 Harry Roberts + + Author: Harry Roberts + Date: Sep 4 2003 + + 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 + + $Id$ +*/ + +#ifndef __QF_png_h +#define __QF_png_h + #include "QF/quakefs.h" -tex_t *LoadPNG (QFile *infile); +struct tex_s *LoadPNG (QFile *infile); + +#endif//__QF_png_h diff --git a/libs/image/image.c b/libs/image/image.c index 1a4cd9943..77483dda3 100644 --- a/libs/image/image.c +++ b/libs/image/image.c @@ -38,71 +38,60 @@ static __attribute__ ((unused)) const char rcsid[] = # include #endif -#include "compat.h" - -#include "QF/qtypes.h" +#include "QF/dstring.h" +#include "QF/image.h" +#include "QF/pcx.h" +#include "QF/png.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) +LoadImage (const char *imageFile, QFile *fp) { - int tmp; - char *tmpFile, *ext; - tex_t *tex = NULL; + int tmp; + dstring_t *tmpFile; + char *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; + tmpFile = dstring_new (); + dstring_copystr (tmpFile, imageFile); + ext = strrchr (tmpFile->str, '.'); + if (ext) + tmp = ext - tmpFile->str; + else + tmp = tmpFile->size; /* Check for a .png */ - strcat (ext, ".png"); - QFS_FOpenFile (tmpFile, &fp); + dstring_replace (tmpFile, tmp, tmpFile->size, ".png", 5); + QFS_FOpenFile (tmpFile->str, &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 (!tex) { + dstring_replace (tmpFile, tmp, tmpFile->size, ".tga", 5); + QFS_FOpenFile (tmpFile->str, &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 (!tex) { + dstring_replace (tmpFile, tmp, tmpFile->size, ".pcx", 5); + QFS_FOpenFile (tmpFile->str, &fp); if (fp) { tex = LoadPCX (fp); // FIXME: needs extra arguments, how should we be passed them? Qclose (fp); - tmp = 1; } }*/ - free (tmpFile); + dstring_delete (tmpFile); return (tex); }