mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 23:11:38 +00:00
Give the 24-8 bit converter a massive speedup.
The biggest part of the speedup is reading from blender's image only once (it seems that every read does so from GL rather than memory: ouch). Also, cache the results for each color.
This commit is contained in:
parent
2e2484250c
commit
1277c17cd9
1 changed files with 15 additions and 11 deletions
|
@ -60,24 +60,28 @@ def make_skin(mdl, mesh):
|
|||
skin = MDL.Skin()
|
||||
skin.type = 0
|
||||
skin.pixels = bytearray(mdl.skinwidth * mdl.skinheight) # preallocate
|
||||
cache = {}
|
||||
pixels = image.pixels[:]
|
||||
for y in range(mdl.skinheight):
|
||||
for x in range(mdl.skinwidth):
|
||||
outind = y * mdl.skinwidth + x
|
||||
# quake textures are top to bottom, but blender images
|
||||
# are bottom to top
|
||||
inind = ((mdl.skinheight - 1 - y) * mdl.skinwidth + x) * 4
|
||||
rgb = image.pixels[inind : inind + 3] # ignore alpha
|
||||
rgb = pixels[inind : inind + 3] # ignore alpha
|
||||
rgb = tuple(map(lambda x: int(x * 255 + 0.5), rgb))
|
||||
best = (3*256*256, -1)
|
||||
for i, p in enumerate(palette):
|
||||
if i > 255: # should never happen
|
||||
break
|
||||
r = 0
|
||||
for x in map (lambda a, b: (a - b) ** 2, rgb, p):
|
||||
r += x
|
||||
if r < best[0]:
|
||||
best = (r, i)
|
||||
skin.pixels[outind] = best[1]
|
||||
if rgb not in cache:
|
||||
best = (3*256*256, -1)
|
||||
for i, p in enumerate(palette):
|
||||
if i > 255: # should never happen
|
||||
break
|
||||
r = 0
|
||||
for x in map (lambda a, b: (a - b) ** 2, rgb, p):
|
||||
r += x
|
||||
if r < best[0]:
|
||||
best = (r, i)
|
||||
cache[rgb] = best[1]
|
||||
skin.pixels[outind] = cache[rgb]
|
||||
mdl.skins.append(skin)
|
||||
|
||||
def build_tris(mesh):
|
||||
|
|
Loading…
Reference in a new issue