From 1d8d93b453624e0cd4e31b81b360fa826a115c9e Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 20 Aug 2002 20:24:31 +0000 Subject: [PATCH] fixed menu player colormapping git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2265 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_draw.c | 2 +- image.c | 46 +++++++++++++++++++++++++++++++++++++++++ image.h | 3 +++ menu.c | 61 +++++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 93 insertions(+), 19 deletions(-) diff --git a/gl_draw.c b/gl_draw.c index a798805d..d9292885 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -272,7 +272,7 @@ cachepic_t *Draw_NewPic(char *picname, int width, int height, int alpha, qbyte * if (pic) { - if (pic->tex && R_TextureWidth(pic->tex) == width && R_TextureHeight(pic->tex) == height && (R_TextureHasAlpha(pic->tex) != 0) == (alpha != 0)) + if (pic->tex && pic->width == width && pic->height == height) { R_UpdateTexture(pic->tex, pixels); return pic; diff --git a/image.c b/image.c index d388637b..caa087e0 100644 --- a/image.c +++ b/image.c @@ -453,6 +453,52 @@ qbyte *LoadLMP (qbyte *f, int matchwidth, int matchheight) return image_rgba; } +/* +============ +LoadLMP +============ +*/ +qbyte *LoadLMPAs8Bit (qbyte *f, int matchwidth, int matchheight) +{ + qbyte *image_8bit; + int width, height; + + if (loadsize < 9) + { + Con_Printf("LoadLMPAs8Bit: invalid LMP file\n"); + return NULL; + } + + // parse the very complicated header *chuckle* + width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216; + height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216; + if ((unsigned) width > 4096 || (unsigned) height > 4096) + { + Con_Printf("LoadLMPAs8Bit: invalid size\n"); + return NULL; + } + if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight)) + return NULL; + + if (loadsize < 8 + width * height) + { + Con_Printf("LoadLMPAs8Bit: invalid LMP file\n"); + return NULL; + } + + image_width = width; + image_height = height; + + image_8bit = Mem_Alloc(tempmempool, image_width * image_height); + if (!image_8bit) + { + Con_Printf("LoadLMPAs8Bit: not enough memory for %i by %i image\n", image_width, image_height); + return NULL; + } + memcpy(image_8bit, f + 8, image_width * image_height); + return image_8bit; +} + void Image_StripImageExtension (char *in, char *out) { char *end, *temp; diff --git a/image.h b/image.h index 214d4dd1..b441d72f 100644 --- a/image.h +++ b/image.h @@ -45,5 +45,8 @@ void Image_Resample (void *indata, int inwidth, int inheight, void *outdata, int // scales the image down by a power of 2 (in can be the same as out) void Image_MipReduce(qbyte *in, qbyte *out, int *width, int *height, int destwidth, int destheight, int bytesperpixel); +// only used by menuplyr coloring +qbyte *LoadLMPAs8Bit (qbyte *f, int matchwidth, int matchheight); + #endif diff --git a/menu.c b/menu.c index 1a98c0b6..35ba6387 100644 --- a/menu.c +++ b/menu.c @@ -931,26 +931,52 @@ void M_Menu_Setup_f (void) } // LordHavoc: rewrote this code greatly -void M_MenuPlayerTranslate (qbyte *translation) +void M_MenuPlayerTranslate (qbyte *translation, int top, int bottom) { - int i, c; + int i; unsigned int trans[4096]; - qpic_t *p; + qbyte *data, *f; + static qbyte pixels[4096]; + static int menuplyr_width, menuplyr_height, menuplyr_top, menuplyr_bottom, menuplyr_load = true, menuplyr_failed = false; - p = W_GetLumpName ("gfx/menuplyr.lmp"); - if (!p) + if (menuplyr_failed) return; - c = p->width * p->height; - if (c > 4096) - { - Con_Printf("M_MenuPlayerTranslate: image larger than 4096 pixel buffer\n"); + if (menuplyr_top == top && menuplyr_bottom == bottom) return; + + menuplyr_top = top; + menuplyr_bottom = bottom; + + if (menuplyr_load) + { + menuplyr_load = false; + f = COM_LoadFile("gfx/menuplyr.lmp", true); + if (!f) + { + menuplyr_failed = true; + return; + } + data = LoadLMPAs8Bit (f, 0, 0); + Mem_Free(f); + if (image_width * image_height > 4096) + { + Con_Printf("M_MenuPlayerTranslate: image larger than 4096 pixel buffer\n"); + Mem_Free(data); + menuplyr_failed = true; + return; + } + menuplyr_width = image_width; + menuplyr_height = image_height; + memcpy(pixels, data, menuplyr_width * menuplyr_height); + Mem_Free(data); } - for (i = 0;i < c;i++) - trans[i] = d_8to24table[translation[((qbyte *)p->data)[i]]]; + M_BuildTranslationTable (menuplyr_top*16, menuplyr_bottom*16); + + for (i = 0;i < menuplyr_width * menuplyr_height;i++) + trans[i] = d_8to24table[translation[pixels[i]]]; - Draw_NewPic("gfx/menuplyr.lmp", p->width, p->height, true, (qbyte *)trans); + Draw_NewPic("gfx/menuplyr.lmp", menuplyr_width, menuplyr_height, true, (qbyte *)trans); } void M_Setup_Draw (void) @@ -978,8 +1004,7 @@ void M_Setup_Draw (void) M_DrawPic (160, 64, "gfx/bigbox.lmp"); // LordHavoc: rewrote this code greatly - M_BuildTranslationTable (setup_top*16, setup_bottom*16); - M_MenuPlayerTranslate (translationTable); + M_MenuPlayerTranslate (translationTable, setup_top, setup_bottom); M_DrawPic (172, 72, "gfx/menuplyr.lmp"); M_DrawCharacter (56, setup_cursor_table [setup_cursor], 12+((int)(realtime*4)&1)); @@ -1091,14 +1116,14 @@ forward: } } - if (setup_top > 13) + if (setup_top > 15) setup_top = 0; if (setup_top < 0) - setup_top = 13; - if (setup_bottom > 13) + setup_top = 15; + if (setup_bottom > 15) setup_bottom = 0; if (setup_bottom < 0) - setup_bottom = 13; + setup_bottom = 15; } //============================================================================= -- 2.39.2