diff --git a/src/v_video.c b/src/v_video.c index a78434255..061027dc1 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -314,9 +314,6 @@ UINT32 V_GammaCorrect(UINT32 input, double power) static void LoadPalette(const char *lumpname) { lumpnum_t lumpnum = W_GetNumForName(lumpname); - boolean remap = wadfiles[WADFILENUM(lumpnum)]->compatmode; - if (remap) // if we're remapping, start with PLAYPAL as a base - lumpnum = W_GetNumForName("PLAYPAL"); size_t i, palsize = W_LumpLength(lumpnum)/3; UINT8 *pal; @@ -334,7 +331,6 @@ static void LoadPalette(const char *lumpname) pLocalPalette = pMasterPalette; pGammaCorrectedPalette = Z_Malloc(sizeof (*pGammaCorrectedPalette)*palsize, PU_STATIC, NULL); - // load the new palette (or PLAYPAL if remapping) pal = W_CacheLumpNum(lumpnum, PU_CACHE); for (i = 0; i < palsize; i++) { @@ -344,35 +340,18 @@ static void LoadPalette(const char *lumpname) pMasterPalette[i].s.alpha = 0xFF; } - RGBA_t *target = NULL; - if (remap) + // remap the palette from 2.1 to 2.2 indices in compatmode + RGBA_t *palcopy = NULL; + if (wadfiles[WADFILENUM(lumpnum)]->compatmode) { - // get the target palette we want - lumpnum = W_GetNumForName(lumpname); - pal = W_CacheLumpNum(lumpnum, PU_CACHE); - palsize = W_LumpLength(lumpnum)/3; - target = malloc(sizeof (*target)*palsize); - - pMasterPalette = Z_Realloc(pMasterPalette, sizeof (*pMasterPalette)*palsize, PU_STATIC, NULL); - if (Cubeapply) - pLocalPalette = Z_Realloc(pLocalPalette, sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL); - else - pLocalPalette = pMasterPalette; - pGammaCorrectedPalette = Z_Realloc(pGammaCorrectedPalette, sizeof (*pGammaCorrectedPalette)*palsize, PU_STATIC, NULL); - - for (i = 0; i < palsize; i++) - { - target[i].s.red = *pal++; - target[i].s.green = *pal++; - target[i].s.blue = *pal++; - target[i].s.alpha = 0xFF; - } + palcopy = malloc(sizeof(*palcopy)*palsize); + memcpy(palcopy, pMasterPalette, sizeof(*palcopy)*palsize); } for (i = 0; i < palsize; i++) { - if (remap) // now map the target palette (2.1) to master palette (2.2) - pMasterPalette[i].rgba = target[R_InvPaletteRemap(i)].rgba; + if (palcopy) + pMasterPalette[i].rgba = palcopy[R_InvPaletteRemap(i)].rgba; pGammaCorrectedPalette[i].rgba = V_GammaDecode(pMasterPalette[i].rgba); if (!Cubeapply) @@ -385,8 +364,8 @@ static void LoadPalette(const char *lumpname) pLocalPalette[i].rgba = V_GammaEncode(pGammaCorrectedPalette[i].rgba); } - if (remap) - free(target); + if (palcopy) + free(palcopy); } void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue)