From ade2b682c6217d7a096937ff25b09f1440236320 Mon Sep 17 00:00:00 2001 From: Spoike Date: Wed, 1 Sep 2004 00:02:00 +0000 Subject: [PATCH] made gldraw_cachepic more resiliant to binaray files that are not lmps git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@96 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/gl/gl_draw.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/engine/gl/gl_draw.c b/engine/gl/gl_draw.c index 056d22c92..7634805ca 100644 --- a/engine/gl/gl_draw.c +++ b/engine/gl/gl_draw.c @@ -374,6 +374,47 @@ qpic_t *GLDraw_SafeCachePic (char *path) BZ_Free(dat); } } + + { + char *mem; + char alternatename[MAX_QPATH]; + _snprintf(alternatename, MAX_QPATH-1, "%s", path); + dat = (qpic_t *)COM_LoadMallocFile (alternatename); + if (dat) + { + strcpy(pic->name, path); + mem = NULL; + if (!mem) + mem = ReadTargaFile((qbyte *)dat, com_filesize, &pic->pic.width, &pic->pic.height, 0); +#ifdef AVAIL_PNGLIB + if (!mem); + mem = ReadPNGFile((qbyte *)dat, com_filesize, &pic->pic.width, &pic->pic.height); +#endif +#ifdef AVAIL_JPEGLIB + if (!mem) + mem = ReadJPEGFile((qbyte *)dat, com_filesize, &pic->pic.width, &pic->pic.height); +#endif + if (!mem) + mem = ReadPCXFile((qbyte *)dat, com_filesize, &pic->pic.width, &pic->pic.height); + if (mem) + { + gl = (glpic_t *)pic->pic.data; + if (!(gl->texnum = Mod_LoadReplacementTexture(alternatename, false, true))) + gl->texnum = GL_LoadTexture32(path, pic->pic.width, pic->pic.height, (unsigned *)dat, false, true); + gl->sl = 0; + gl->sh = 1; + gl->tl = 0; + gl->th = 1; + + BZ_Free(dat); + BZ_Free(mem); + glmenu_numcachepics++; + return &pic->pic; + } + BZ_Free(dat); + } + } + #ifdef AVAIL_JPEGLIB { char *mem; @@ -442,6 +483,15 @@ qpic_t *GLDraw_SafeCachePic (char *path) SwapPic (dat); + if (((8+dat->width*dat->height+3)&(~3)) != ((com_filesize+3)&(~3))) //round up to the nearest 4. + { + char alternatename[MAX_QPATH]; + sprintf(alternatename, "gfx/%s.lmp", path); + dat = (qpic_t *)COM_LoadTempFile (alternatename); + if (!dat) + return GLDraw_SafePicFromWad(path); + } + // HACK HACK HACK --- we need to keep the bytes for // the translatable player picture just for the menu // configuration dialog