From 25fa88ca9be1f0a59233ac0fd3cac749eb90d21c Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 30 Jun 2024 18:10:39 +0300 Subject: [PATCH] renders: load swl as paletted image --- src/client/refresh/files/stb.c | 16 ++++++----- src/client/refresh/files/wal.c | 47 +++++++++++++++------------------ src/client/refresh/ref_shared.h | 3 +-- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/client/refresh/files/stb.c b/src/client/refresh/files/stb.c index 552b72d7..ea5a148b 100644 --- a/src/client/refresh/files/stb.c +++ b/src/client/refresh/files/stb.c @@ -500,13 +500,21 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t if (!image) { - if (!strcmp(ext, "pcx")) + if (!strcmp(ext, "pcx") || !strcmp(ext, "swl")) { int width = 0, height = 0, realwidth = 0, realheight = 0; byte *pic = NULL; byte *palette = NULL; - LoadPCX (namewe, &pic, &palette, &width, &height); + if (!strcmp(ext, "pcx")) + { + LoadPCX (namewe, &pic, &palette, &width, &height); + } + else if (!strcmp(ext, "swl")) + { + LoadSWL (namewe, &pic, &palette, &width, &height); + } + if (!pic) { return NULL; @@ -581,10 +589,6 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t { image = LoadM32(name, namewe, type, load_image); } - else if (!strcmp(ext, "swl")) - { - image = LoadSWL(name, namewe, type, load_image); - } else if (!strcmp(ext, "tga") || !strcmp(ext, "png") || !strcmp(ext, "jpg")) diff --git a/src/client/refresh/files/wal.c b/src/client/refresh/files/wal.c index ea67439b..73af7ba8 100644 --- a/src/client/refresh/files/wal.c +++ b/src/client/refresh/files/wal.c @@ -209,60 +209,55 @@ LoadM8(const char *origname, const char *namewe, imagetype_t type, return image; } -struct image_s * -LoadSWL(const char *origname, const char *namewe, imagetype_t type, - loadimage_t load_image) +void +LoadSWL(const char *origname, byte **pic, byte **palette, int *width, int *height) { - int width, height, ofs, size, i; - byte *image_buffer = NULL; - struct image_s *image; + int ofs, size, i; char name[256]; sinmiptex_t *mt; - FixFileExt(namewe, "swl", name, sizeof(name)); + FixFileExt(origname, "swl", name, sizeof(name)); size = ri.FS_LoadFile(name, (void **)&mt); + *pic = NULL; + if (!mt) { - return NULL; + return; } if (size < sizeof(*mt)) { R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name); ri.FS_FreeFile((void *)mt); - return NULL; + return; } - width = LittleLong(mt->width); - height = LittleLong(mt->height); + *width = LittleLong(mt->width); + *height = LittleLong(mt->height); ofs = LittleLong(mt->offsets[0]); - if ((ofs <= 0) || (width <= 0) || (height <= 0) || - (((size - ofs) / height) < width)) + if ((ofs <= 0) || (*width <= 0) || (*height <= 0) || + (((size - ofs) / *height) < *width)) { R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name); ri.FS_FreeFile((void *)mt); - return NULL; + return; } - image_buffer = malloc ((size - ofs) * 4); - for(i=0; i<(size - ofs); i++) + *pic = malloc (size - ofs); + memcpy(*pic, (byte *)mt + ofs, size - ofs); + + *palette = malloc(768); + for (i = 0; i < 256; i ++) { - byte value = *((byte *)mt + ofs + i); - memcpy(image_buffer + i * 4, mt->palette + value * 4, 4); + (*palette)[i * 3 + 0] = mt->palette[i * 4 + 0]; + (*palette)[i * 3 + 1] = mt->palette[i * 4 + 1]; + (*palette)[i * 3 + 2] = mt->palette[i * 4 + 2]; } - image = load_image(origname, image_buffer, - width, 0, - height, 0, - (size - ofs), type, 32); - free(image_buffer); - ri.FS_FreeFile((void *)mt); - - return image; } struct image_s * diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index 2d147d97..bd2b23ef 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -102,8 +102,7 @@ extern struct image_s* LoadM8(const char *origname, const char *namewe, imagetyp loadimage_t load_image); extern struct image_s* LoadM32(const char *origname, const char *namewe, imagetype_t type, loadimage_t load_image); -extern struct image_s* LoadSWL(const char *origname, const char *namewe, imagetype_t type, - loadimage_t load_image); +extern void LoadSWL(const char *origname, byte **pic, byte **palette, int *width, int *height); extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size); extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height); extern void GetPCXInfo(const char *origname, int *width, int *height);