# HG changeset patch # User Emmanuel Gil Peyrot # Date 1357592762 -3600 # Node ID 45e1a9a37e66edbbd6ba1ae6168ec7aa5c167fad # Parent 84b15196270882bc75ac4d0e1c93003f3fbf14b4 When merging RGB and alpha data, get the C arrays only at the start of the loop. diff --git a/pytouhou/ui/texture.pyx b/pytouhou/ui/texture.pyx --- a/pytouhou/ui/texture.pyx +++ b/pytouhou/ui/texture.pyx @@ -44,8 +44,7 @@ cdef class TextureManager: def load_texture(self, key): - cdef bytes data, alpha_data - cdef char *new_data + cdef char *image, *alpha, *new_data cdef unsigned int i, width, height, pixels first_name, secondary_name = key @@ -58,16 +57,19 @@ cdef class TextureManager: width, height = image_file.width, image_file.height pixels = width * height - data = image_file.get_data('RGB', width * 3) + + image_data = image_file.get_data('RGB', width * 3) alpha_data = alpha_file.get_data('RGB', width * 3) + image = image_data + alpha = alpha_data # TODO: further optimizations new_data = malloc(pixels * 4) for i in range(pixels): - new_data[i*4] = (data)[i*3] - new_data[i*4+1] = (data)[i*3+1] - new_data[i*4+2] = (data)[i*3+2] - new_data[i*4+3] = (alpha_data)[i*3] + new_data[i*4] = image[i*3] + new_data[i*4+1] = image[i*3+1] + new_data[i*4+2] = image[i*3+2] + new_data[i*4+3] = alpha[i*3] image_file = pyglet.image.ImageData(width, height, 'RGBA', new_data[:(pixels * 4)]) free(new_data)