From ebc450a3971ccf92df9a0a26643df91688624c25 Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Sat, 2 Jan 2010 21:08:19 -0800 Subject: [PATCH] Optimized blit functions. --- pyhexen/vid.py | 53 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/pyhexen/vid.py b/pyhexen/vid.py index 63ebcae..6204f2c 100644 --- a/pyhexen/vid.py +++ b/pyhexen/vid.py @@ -1,6 +1,7 @@ import pygame import struct import wad +import numpy class VidException(Exception): pass @@ -9,13 +10,13 @@ class Video: def __init__(self, wad): self.palette = [] self.wad = wad - self.tinttab = self.wad.CacheLumpName ('TINTTAB') + self.tinttab = map(ord, self.wad.CacheLumpName ('TINTTAB')) # Stuff from I_* in the C code. def SetPalette(self, data): self.palette = [] for i in range (0, 768, 3): - rgb = [ord(x) for x in data[i:i+3]] + rgb = map (ord, data[i:i+3]) self.palette.append(rgb) self.screen.set_palette(self.palette) @@ -25,32 +26,46 @@ class Video: # Stuff from V_* in the C code. def __blitRaw (self, data, w, h): screen = pygame.surfarray.pixels2d (self.screen) - for y in range(0, h): - for x in range (0, w): - screen[x,y] = ord (data[y * w + x]) + img = map (ord, data) + for y in xrange(h): + start = y * w + end = start + w + screen[0:w,y] = img[start:end] - def __blitPatch(self, data, x, y, trans = lambda a, b: a): + def __blitPatch(self, data, x, y, trans = None): (width, height) = struct.unpack_from ('