From e52e55f5c85537cc09a2259d652f08c1bef3d2c5 Mon Sep 17 00:00:00 2001
From: Logan Aerl Arias <logana@srb2.org>
Date: Sat, 6 Jan 2024 16:30:16 -0500
Subject: [PATCH] PICTURE_PNG_USELOOKUP for everyone

remove the need for PICTURE_PNG_USELOOKUP define
remove the need for NO_PNG_LUMPS define
---
 src/hardware/hw_cache.c |  4 ----
 src/p_setup.c           |  4 ----
 src/r_picformats.c      | 17 -----------------
 src/r_picformats.h      |  4 ----
 src/r_textures.c        | 14 --------------
 src/r_things.c          |  4 ----
 src/w_wad.c             |  2 --
 7 files changed, 49 deletions(-)

diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c
index d6245df649..2d39311604 100644
--- a/src/hardware/hw_cache.c
+++ b/src/hardware/hw_cache.c
@@ -505,11 +505,9 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex)
 		pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE);
 		realpatch = (softwarepatch_t *)pdata;
 
-#ifndef NO_PNG_LUMPS
 		if (Picture_IsLumpPNG((UINT8 *)realpatch, lumplength))
 			realpatch = (softwarepatch_t *)Picture_PNGConvert(pdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, 0);
 		else
-#endif
 #ifdef WALLFLATS
 		if (texture->type == TEXTURETYPE_FLAT)
 			realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0);
@@ -904,7 +902,6 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
 		levelflat->height = (UINT16)(patch->height);
 		HWR_GetPatch(patch);
 	}
-#ifndef NO_PNG_LUMPS
 	else if (levelflat->type == LEVELFLAT_PNG)
 	{
 		GLMipmap_t *mipmap = levelflat->mipmap;
@@ -950,7 +947,6 @@ void HWR_GetLevelFlat(levelflat_t *levelflat)
 		// Tell the hardware driver to bind the current texture to the flat's mipmap
 		HWR_SetCurrentTexture(mipmap);
 	}
-#endif
 	else // set no texture
 		HWR_SetCurrentTexture(NULL);
 }
diff --git a/src/p_setup.c b/src/p_setup.c
index 9ae73c18bf..2226287804 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -561,9 +561,7 @@ or NULL if we want to allocate it now.
 static INT32
 Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize)
 {
-#ifndef NO_PNG_LUMPS
 	UINT8         buffer[8];
-#endif
 
 	lumpnum_t    flatnum;
 	int       texturenum;
@@ -631,7 +629,6 @@ flatfound:
 			levelflat->type = LEVELFLAT_PATCH;
 		else
 		{
-#ifndef NO_PNG_LUMPS
 			/*
 			Only need eight bytes for PNG headers.
 			FIXME: Put this elsewhere.
@@ -640,7 +637,6 @@ flatfound:
 			if (Picture_IsLumpPNG(buffer, lumplength))
 				levelflat->type = LEVELFLAT_PNG;
 			else
-#endif/*NO_PNG_LUMPS*/
 				levelflat->type = LEVELFLAT_FLAT;/* phew */
 		}
 		if (flatpatch)
diff --git a/src/r_picformats.c b/src/r_picformats.c
index 481c0ec3e7..52b42e8225 100644
--- a/src/r_picformats.c
+++ b/src/r_picformats.c
@@ -47,9 +47,7 @@
 
 static unsigned char imgbuf[1<<26];
 
-#ifdef PICTURE_PNG_USELOOKUP
 static colorlookup_t png_colorlookup;
-#endif
 
 /** Converts a picture between two formats.
   *
@@ -822,9 +820,6 @@ boolean Picture_IsLumpPNG(const UINT8 *d, size_t s)
 	return (memcmp(&d[0], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", 8) == 0);
 }
 
-#ifndef NO_PNG_LUMPS
-#ifdef HAVE_PNG
-
 /*#if PNG_LIBPNG_VER_DLLNUM < 14
 typedef PNG_CONST png_byte *png_const_bytep;
 #endif*/
@@ -1136,10 +1131,8 @@ void *Picture_PNGConvert(
 	if (outbpp == PICDEPTH_8BPP)
 		memset(flat, TRANSPARENTPIXEL, (width * height));
 
-#ifdef PICTURE_PNG_USELOOKUP
 	if (outbpp != PICDEPTH_32BPP)
 		InitColorLUT(&png_colorlookup, pMasterPalette, false);
-#endif
 
 	if (outbpp == PICDEPTH_32BPP)
 	{
@@ -1208,11 +1201,7 @@ void *Picture_PNGConvert(
 
 					if (alpha)
 					{
-#ifdef PICTURE_PNG_USELOOKUP
 						UINT8 palidx = GetColorLUT(&png_colorlookup, red, green, blue);
-#else
-						UINT8 palidx = NearestColor(red, green, blue);
-#endif
 						outflat[((y * width) + x)] = (0xFF << 8) | palidx;
 					}
 					else
@@ -1249,11 +1238,7 @@ void *Picture_PNGConvert(
 
 					if (alpha)
 					{
-#ifdef PICTURE_PNG_USELOOKUP
 						UINT8 palidx = GetColorLUT(&png_colorlookup, red, green, blue);
-#else
-						UINT8 palidx = NearestColor(red, green, blue);
-#endif
 						outflat[((y * width) + x)] = palidx;
 					}
 				}
@@ -1385,8 +1370,6 @@ boolean Picture_PNGDimensions(UINT8 *png, INT32 *width, INT32 *height, INT16 *to
 	*height = (INT32)h;
 	return true;
 }
-#endif
-#endif
 
 //
 // R_ParseSpriteInfoFrame
diff --git a/src/r_picformats.h b/src/r_picformats.h
index 4050a1b71d..55010f072c 100644
--- a/src/r_picformats.h
+++ b/src/r_picformats.h
@@ -108,7 +108,6 @@ typedef struct
 boolean Picture_IsLumpPNG(const UINT8 *d, size_t s);
 #define Picture_ThrowPNGError(lumpname, wadfilename) I_Error("W_Wad: Lump \"%s\" in file \"%s\" is a .png - please convert to either Doom or Flat (raw) image format.", lumpname, wadfilename); // Fears Of LJ Sonic
 
-#ifndef NO_PNG_LUMPS
 void *Picture_PNGConvert(
 	const UINT8 *png, pictureformat_t outformat,
 	INT32 *w, INT32 *h,
@@ -117,9 +116,6 @@ void *Picture_PNGConvert(
 	pictureflags_t flags);
 boolean Picture_PNGDimensions(UINT8 *png, INT32 *width, INT32 *height, INT16 *topoffset, INT16 *leftoffset, size_t size);
 
-#define PICTURE_PNG_USELOOKUP
-#endif
-
 // SpriteInfo
 extern spriteinfo_t spriteinfo[NUMSPRITES];
 void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps);
diff --git a/src/r_textures.c b/src/r_textures.c
index 8b47f455e8..c4e776521f 100644
--- a/src/r_textures.c
+++ b/src/r_textures.c
@@ -295,10 +295,8 @@ UINT8 *R_GenerateTexture(size_t texnum)
 		pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
 		realpatch = (softwarepatch_t *)pdata;
 
-#ifndef NO_PNG_LUMPS
 		if (Picture_IsLumpPNG((UINT8 *)realpatch, lumplength))
 			goto multipatch;
-#endif
 #ifdef WALLFLATS
 		if (texture->type == TEXTURETYPE_FLAT)
 			goto multipatch;
@@ -392,11 +390,9 @@ UINT8 *R_GenerateTexture(size_t texnum)
 		realpatch = (softwarepatch_t *)pdata;
 		dealloc = true;
 
-#ifndef NO_PNG_LUMPS
 		if (Picture_IsLumpPNG((UINT8 *)realpatch, lumplength))
 			realpatch = (softwarepatch_t *)Picture_PNGConvert((UINT8 *)realpatch, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, 0);
 		else
-#endif
 #ifdef WALLFLATS
 		if (texture->type == TEXTURETYPE_FLAT)
 			realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0);
@@ -576,7 +572,6 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
 		}
 		else
 		{
-#ifndef NO_PNG_LUMPS
 			if (levelflat->type == LEVELFLAT_PNG)
 			{
 				INT32 pngwidth, pngheight;
@@ -589,7 +584,6 @@ void *R_GetLevelFlat(levelflat_t *levelflat)
 				ds_flatheight = levelflat->height;
 			}
 			else
-#endif
 			if (levelflat->type == LEVELFLAT_PATCH)
 			{
 				UINT8 *converted;
@@ -778,7 +772,6 @@ Rloadflats (INT32 i, INT32 w)
 			M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
 			texture->hash = quickncasehash(texture->name, 8);
 
-#ifndef NO_PNG_LUMPS
 			if (Picture_IsLumpPNG(header, lumplength))
 			{
 				UINT8 *flatlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
@@ -789,7 +782,6 @@ Rloadflats (INT32 i, INT32 w)
 				Z_Free(flatlump);
 			}
 			else
-#endif
 				texture->width = texture->height = flatsize;
 
 			texture->type = TEXTURETYPE_FLAT;
@@ -855,9 +847,7 @@ Rloadtextures (INT32 i, INT32 w)
 		{
 			UINT16 wadnum = (UINT16)w;
 			lumpnum_t lumpnum = texstart + j;
-#ifndef NO_PNG_LUMPS
 			size_t lumplength;
-#endif
 
 			if (W_FileHasFolders(wadfiles[w]))
 			{
@@ -866,9 +856,7 @@ Rloadtextures (INT32 i, INT32 w)
 			}
 
 			W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, PNG_HEADER_SIZE, 0);
-#ifndef NO_PNG_LUMPS
 			lumplength = W_LumpLengthPwad(wadnum, lumpnum);
-#endif
 
 			//CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height);
 			texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL);
@@ -877,7 +865,6 @@ Rloadtextures (INT32 i, INT32 w)
 			M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
 			texture->hash = quickncasehash(texture->name, 8);
 
-#ifndef NO_PNG_LUMPS
 			if (Picture_IsLumpPNG((UINT8 *)&patchlump, lumplength))
 			{
 				UINT8 *png = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE);
@@ -888,7 +875,6 @@ Rloadtextures (INT32 i, INT32 w)
 				Z_Free(png);
 			}
 			else
-#endif
 			{
 				texture->width = SHORT(patchlump.width);
 				texture->height = SHORT(patchlump.height);
diff --git a/src/r_things.c b/src/r_things.c
index 9d2868d4cf..ce6c8d86e1 100644
--- a/src/r_things.c
+++ b/src/r_things.c
@@ -286,9 +286,7 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16
 		{
 			INT32 width, height;
 			INT16 topoffset, leftoffset;
-#ifndef NO_PNG_LUMPS
 			boolean isPNG = false;
-#endif
 
 			frame = R_Char2Frame(lumpinfo[l].name[4]);
 			rotation = R_Char2Rotation(lumpinfo[l].name[5]);
@@ -306,7 +304,6 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16
 			// store sprite info in lookup tables
 			//FIXME : numspritelumps do not duplicate sprite replacements
 
-#ifndef NO_PNG_LUMPS
 			{
 				softwarepatch_t *png = W_CacheLumpNumPwad(wadnum, l, PU_STATIC);
 				size_t len = W_LumpLengthPwad(wadnum, l);
@@ -321,7 +318,6 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16
 			}
 
 			if (!isPNG)
-#endif
 			{
 				W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof(INT16) * 4, 0);
 				width = (INT32)(SHORT(patch.width));
diff --git a/src/w_wad.c b/src/w_wad.c
index 88e139f0ed..381d5555af 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -2031,10 +2031,8 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
 		W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0);
 		ptr = lumpdata;
 
-#ifndef NO_PNG_LUMPS
 		if (Picture_IsLumpPNG((UINT8 *)lumpdata, len))
 			ptr = Picture_PNGConvert((UINT8 *)lumpdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, len, &len, 0);
-#endif
 
 		dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]);
 		Patch_Create(ptr, len, dest);
-- 
GitLab