mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
use dtrings to do the filename manipulation
This commit is contained in:
parent
9cd2d366ed
commit
753dc02deb
3 changed files with 101 additions and 38 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -38,71 +38,60 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
# include <strings.h>
|
||||
#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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue