From fd387f3e998d49066782bf4d4285dedc012c8634 Mon Sep 17 00:00:00 2001 From: Shpoike Date: Sun, 14 Apr 2024 04:54:07 +0100 Subject: [PATCH] 'dir textures/*/*.wal' can now show previews. --- engine/client/image.c | 40 ++++++++++++++++++++++++++++++++++++++++ engine/common/fs.c | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/engine/client/image.c b/engine/client/image.c index 092cf2e72..9bebd8125 100644 --- a/engine/client/image.c +++ b/engine/client/image.c @@ -7516,6 +7516,46 @@ qbyte *ReadRawImageFile(qbyte *buf, int len, int *width, int *height, uploadfmt_ } #endif +#ifdef Q2BSPS + if (len >= sizeof(q2miptex_t)) //.lmp has no magic id. guess at it. + { + const q2miptex_t *wal = (const q2miptex_t *)buf; + size_t w = LittleLong(wal->width), h = LittleLong(wal->height); + size_t sz = sizeof(*wal) + + (w>>0)*(h>>0) + + (w>>1)*(h>>1) + + (w>>2)*(h>>2) + + (w>>3)*(h>>3); + if (sz == len) + { + if (force_rgba8) + { + qboolean foundalpha = false; + qbyte *in = buf+sizeof(*wal); + data = BZ_Malloc(w * h * sizeof(int)); + for (i = 0; i < w * h; i++) + { +// if (in[i] == 255) +// foundalpha = true; + ((unsigned int*)data)[i] = d_8to24rgbtable[in[i]]; + } + *width = w; + *height = h; + *format = foundalpha?PTI_RGBA8:PTI_RGBX8; + } + else + { + data = BZ_Malloc(w * h); + memcpy(data, buf+sizeof(*wal), w*h); + *width = w; + *height = h; + *format = TF_SOLID8; + } + return data; + } + } +#endif + TRACE(("dbg: Read32BitImageFile: life sucks\n")); return NULL; diff --git a/engine/common/fs.c b/engine/common/fs.c index 95b4f8952..e11ec8c46 100644 --- a/engine/common/fs.c +++ b/engine/common/fs.c @@ -1585,7 +1585,8 @@ static int QDECL COM_Dir_List(const char *name, qofs_t size, time_t mtime, void else if (!Q_strcasecmp(ext, "tga") || !Q_strcasecmp(ext, "png") || !Q_strcasecmp(ext, "jpg") || !Q_strcasecmp(ext, "jpeg")|| !Q_strcasecmp(ext, "lmp") || !Q_strcasecmp(ext, "ico") || !Q_strcasecmp(ext, "pcx") || !Q_strcasecmp(ext, "bmp") || !Q_strcasecmp(ext, "dds") || !Q_strcasecmp(ext, "ktx") || !Q_strcasecmp(ext, "ktx2")|| !Q_strcasecmp(ext, "vtf") || !Q_strcasecmp(ext, "astc")|| !Q_strcasecmp(ext, "htga")|| !Q_strcasecmp(ext, "exr") || !Q_strcasecmp(ext, "xcf") || !Q_strcasecmp(ext, "psd") || !Q_strcasecmp(ext, "iwi") || - !Q_strcasecmp(ext, "pbm") || !Q_strcasecmp(ext, "ppm") || !Q_strcasecmp(ext, "pgm") || !Q_strcasecmp(ext, "pam") || !Q_strcasecmp(ext, "pfm") || !Q_strcasecmp(ext, "hdr") ) + !Q_strcasecmp(ext, "pbm") || !Q_strcasecmp(ext, "ppm") || !Q_strcasecmp(ext, "pgm") || !Q_strcasecmp(ext, "pam") || !Q_strcasecmp(ext, "pfm") || !Q_strcasecmp(ext, "hdr") || + !Q_strcasecmp(ext, "wal") ) { //FIXME: image replacements are getting in the way here. Q_snprintfz(link, sizeof(link), "\\tiprawimg\\%s\\tip\\(note: image replacement rules are context-dependant, including base path, sub path, extension, or complete replacement via a shader)", name);