raze/polymer/highpalookupmaker.py
helixhorned e745f3abf9 A bunch of mutually unrelated updates.
First, there's a new script for the generation of highpalookup images. Python 2.6, NumPy and PIL are required.
Next, the map corruption checker has been ported to C. This is so that Mapster32 will be able to take decisions more cleverly based on the corruptness of the map. It also catches a few more issues like inconsistent nextwall/nextsector tags now.
Finally, link the executables with --large-address-aware on Windows. This gives a gig more private virtual memory on XP when booting with /3GB. YMMV, but I can play IW2 with Polymer now.

git-svn-id: https://svn.eduke32.com/eduke32@1751 1a8010ca-5511-0410-912e-c29ae57300e0
2011-01-03 22:04:20 +00:00

83 lines
2.3 KiB
Python

#!/usr/bin/python
def makehighpalookuppixel(pal, rgb):
hsv = list(colorsys.rgb_to_hsv(*rgb))
if pal == 0:
# no-op, pass through
return rgb
# frozen, blue light
elif pal == 1:
# make everything blueish
hsv[0] = 0.66
return list(colorsys.hsv_to_rgb(*hsv))
# nightvision
elif pal == 6:
# make everything green and reverse brightness
hsv[0] = 0.33
hsv[2] = 1.0 - hsv[2]
#hsv[1] = 0.5
return list(colorsys.hsv_to_rgb(*hsv))
# pal 20
elif pal == 20:
# blue to gray by removing all saturation
if (hsv[0] > 0.6 and hsv[0] < 0.7):
hsv[1] = 0
# orange and brown to blue
if (hsv[0] > 0.04 and hsv[0] < 0.13):
hsv[0] = 0.66
# purple and reddish to blue
if (hsv[0] > 0.7 and hsv[0] < 0.9):
hsv[0] = 0.66
# green to blue
if (hsv[0] > 0.30 and hsv[0] < 0.36):
hsv[0] = 0.66
return list(colorsys.hsv_to_rgb(*hsv))
else:
print "unknown pal!"
sys.exit()
import colorsys
import sys
import struct
if (len(sys.argv) != 3):
print "Usage: python highpalookupmaker.py palnum outfile"
sys.exit()
# bit depth per dimension
xbits = 7
ybits = 7
zbits = 7
xdim = 1 << xbits
ydim = 1 << ybits
zdim = 1 << zbits
palnum = int(sys.argv[1])
pixels = []
pixelcount = xdim * ydim * zdim
curpix = 0.0
fo = open(sys.argv[2], "w")
# throw in a TGA header in there, this way they'll be able to directly edit it if they feel like it
fo.write(struct.pack("=BBBHHBHHHHBB", 0, 0, 2, 0, 0, 0, 0, 0, 16384, 128, 32, 0))
print "Creating highpalookup map %s for palette %d with depth %d:%d:%d..." % (sys.argv[2], palnum, xbits, ybits, zbits)
for k in range(zdim):
for j in range(ydim):
for i in range(xdim):
rgb = [float(i) / (xdim - 1), float(j) / (ydim - 1), float(k) / (zdim - 1)]
rgb = makehighpalookuppixel(palnum, rgb)
# save as BGRA as that's what TGA uses
pixels.append(struct.pack('BBBB', int(rgb[2] * 255), int(rgb[1] * 255), int(rgb[0] * 255), 255))
curpix += 1
if (curpix % 128 == 0):
print "\r%f%% done." % (curpix * 100 / pixelcount),
fo.writelines(pixels)
fo.close()
print "\n"