From: havoc Date: Wed, 19 Jul 2006 04:50:45 +0000 (+0000) Subject: changed Draw_CachePic to load both tga/png/jpg and lmp/wad images at once and take... X-Git-Tag: xonotic-v0.1.0preview~3865 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b349a290a769771544e5d4e77d8238d2810fe921;p=xonotic%2Fdarkplaces.git changed Draw_CachePic to load both tga/png/jpg and lmp/wad images at once and take the pic size from the lmp/wad, and cleaned up parts of wad and lmp loading, eliminated SwapPic git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6515 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_draw.c b/gl_draw.c index 5f40fb73..2a6368e5 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -302,8 +302,10 @@ cachepic_t *Draw_CachePic (const char *path, qboolean persistent) { int crc, hashkey; cachepic_t *pic; - qpic_t *p; int flags; + fs_offset_t lmpsize; + unsigned char *lmpdata; + char lmpname[MAX_QPATH]; if (!strncmp(CLVIDEOPREFIX, path, sizeof(CLVIDEOPREFIX) - 1)) { @@ -338,53 +340,91 @@ cachepic_t *Draw_CachePic (const char *path, qboolean persistent) if (!strcmp(path, "gfx/colorcontrol/ditherpattern")) flags |= TEXF_CLAMP; - // load the pic from disk + // load a high quality image from disk if possible pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, flags); if (pic->tex == NULL && !strncmp(path, "gfx/", 4)) { - // compatibility with older versions + // compatibility with older versions which did not require gfx/ prefix pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, flags); - // failed to find gfx/whatever.tga or similar, try the wad - if (pic->tex == NULL && (p = (qpic_t *)W_GetLumpName (path + 4))) + } + // if a high quality image was loaded, set the pic's size to match it, just + // in case there's no low quality version to get the size from + if (pic->tex) + { + pic->width = R_TextureWidth(pic->tex); + pic->height = R_TextureHeight(pic->tex); + } + + // now read the low quality version (wad or lmp file), and take the pic + // size from that even if we don't upload the texture, this way the pics + // show up the right size in the menu even if they were replaced with + // higher or lower resolution versions + dpsnprintf(lmpname, sizeof(lmpname), "%s.lmp", path); + if (!strncmp(path, "gfx/", 4) && (lmpdata = FS_LoadFile(lmpname, tempmempool, false, &lmpsize))) + { + if (lmpsize >= 9) { - if (!strcmp(path, "gfx/conchars")) - { - // conchars is a raw image and with color 0 as transparent instead of 255 - pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, (unsigned char *)p, TEXTYPE_PALETTE, flags, palette_font); - } - else - pic->tex = R_LoadTexture2D(drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_PALETTE, flags, palette_transparent); + pic->width = lmpdata[0] + lmpdata[1] * 256 + lmpdata[2] * 65536 + lmpdata[3] * 16777216; + pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216; + // if no high quality replacement image was found, upload the original low quality texture + if (!pic->tex) + pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, flags, palette_transparent); + } + Mem_Free(lmpdata); + } + else if ((lmpdata = W_GetLumpName (path + 4))) + { + if (!strcmp(path, "gfx/conchars")) + { + // conchars is a raw image and with color 0 as transparent instead of 255 + pic->width = 128; + pic->height = 128; + // if no high quality replacement image was found, upload the original low quality texture + if (!pic->tex) + pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, lmpdata, TEXTYPE_PALETTE, flags, palette_font); + } + else + { + pic->width = lmpdata[0] + lmpdata[1] * 256 + lmpdata[2] * 65536 + lmpdata[3] * 16777216; + pic->height = lmpdata[4] + lmpdata[5] * 256 + lmpdata[6] * 65536 + lmpdata[7] * 16777216; + // if no high quality replacement image was found, upload the original low quality texture + if (!pic->tex) + pic->tex = R_LoadTexture2D(drawtexturepool, path, pic->width, pic->height, lmpdata + 8, TEXTYPE_PALETTE, flags, palette_transparent); } } - if (pic->tex == NULL && !strcmp(path, "gfx/conchars")) - pic->tex = draw_generateconchars(); - if (pic->tex == NULL && !strcmp(path, "ui/mousepointer")) - pic->tex = draw_generatemousepointer(); - if (pic->tex == NULL && !strcmp(path, "gfx/prydoncursor001")) - pic->tex = draw_generatemousepointer(); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair1")) - pic->tex = draw_generatecrosshair(0); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair2")) - pic->tex = draw_generatecrosshair(1); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair3")) - pic->tex = draw_generatecrosshair(2); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair4")) - pic->tex = draw_generatecrosshair(3); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair5")) - pic->tex = draw_generatecrosshair(4); - if (pic->tex == NULL && !strcmp(path, "gfx/crosshair6")) - pic->tex = draw_generatecrosshair(5); - if (pic->tex == NULL && !strcmp(path, "gfx/colorcontrol/ditherpattern")) - pic->tex = draw_generateditherpattern(); + // if it's not found on disk, check if it's one of the builtin images if (pic->tex == NULL) { - Con_Printf("Draw_CachePic: failed to load %s\n", path); - pic->tex = r_texture_notexture; + if (pic->tex == NULL && !strcmp(path, "gfx/conchars")) + pic->tex = draw_generateconchars(); + if (pic->tex == NULL && !strcmp(path, "ui/mousepointer")) + pic->tex = draw_generatemousepointer(); + if (pic->tex == NULL && !strcmp(path, "gfx/prydoncursor001")) + pic->tex = draw_generatemousepointer(); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair1")) + pic->tex = draw_generatecrosshair(0); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair2")) + pic->tex = draw_generatecrosshair(1); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair3")) + pic->tex = draw_generatecrosshair(2); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair4")) + pic->tex = draw_generatecrosshair(3); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair5")) + pic->tex = draw_generatecrosshair(4); + if (pic->tex == NULL && !strcmp(path, "gfx/crosshair6")) + pic->tex = draw_generatecrosshair(5); + if (pic->tex == NULL && !strcmp(path, "gfx/colorcontrol/ditherpattern")) + pic->tex = draw_generateditherpattern(); + if (pic->tex == NULL) + { + Con_Printf("Draw_CachePic: failed to load %s\n", path); + pic->tex = r_texture_notexture; + } + pic->width = R_TextureWidth(pic->tex); + pic->height = R_TextureHeight(pic->tex); } - pic->width = R_TextureWidth(pic->tex); - pic->height = R_TextureHeight(pic->tex); return pic; } diff --git a/image.c b/image.c index 529d7472..353a4b5d 100644 --- a/image.c +++ b/image.c @@ -712,11 +712,6 @@ unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, in return image_buffer; } -static unsigned char *LoadLMPRGBA (const unsigned char *f, int filesize, int matchwidth, int matchheight) -{ - return LoadLMP(f, filesize, matchwidth, matchheight, false); -} - typedef struct q2wal_s { @@ -836,7 +831,6 @@ imageformat_t imageformats_gfx[] = {"%s.png", PNG_LoadImage}, {"%s.jpg", JPEG_LoadImage}, {"%s.pcx", LoadPCX}, - {"%s.lmp", LoadLMPRGBA}, {NULL, NULL} }; diff --git a/wad.c b/wad.c index 7087ce69..48e87bd6 100644 --- a/wad.c +++ b/wad.c @@ -24,9 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "wad.h" -void SwapPic (qpic_t *pic); - - /* ================== W_CleanupName @@ -58,7 +55,7 @@ static void W_CleanupName (const char *in, char *out) out[i] = 0; } -void *W_GetLumpName(const char *name) +unsigned char *W_GetLumpName(const char *name) { int i; fs_offset_t filesize; @@ -96,8 +93,6 @@ void *W_GetLumpName(const char *name) lump->filepos = LittleLong(lump->filepos); lump->size = LittleLong(lump->size); W_CleanupName (lump->name, lump->name); - if (lump->type == TYP_QPIC) - SwapPic ( (qpic_t *)(wad_base + lump->filepos)); } } } @@ -105,7 +100,7 @@ void *W_GetLumpName(const char *name) for (lump = wad_lumps, i = 0;i < wad_numlumps;i++, lump++) if (!strcmp(clean, lump->name)) - return (void *)(wad_base + lump->filepos); + return (wad_base + lump->filepos); if (wad_base) Con_DPrintf("W_GetLumpByName(\"%s\"): couldn't find file in gfx.wad\n", name); @@ -122,12 +117,6 @@ automatic byte swapping ============================================================================= */ -void SwapPic (qpic_t *pic) -{ - pic->width = LittleLong(pic->width); - pic->height = LittleLong(pic->height); -} - // LordHavoc: added alternate WAD2/WAD3 system for HalfLife texture wads #define TEXWAD_MAXIMAGES 16384 typedef struct texwadlump_s diff --git a/wad.h b/wad.h index 39dd7df6..982a49fe 100644 --- a/wad.h +++ b/wad.h @@ -69,7 +69,7 @@ extern int wad_numlumps; extern lumpinfo_t *wad_lumps; extern unsigned char *wad_base; -void *W_GetLumpName (const char *name); +unsigned char *W_GetLumpName (const char *name); // LordHavoc: added alternate texture WAD2/WAD3 system for easier loading of HalfLife texture wads