def load_image(path): surface = pygame.image.load(path) width, height = surface.get_size() Bpp = surface.get_bytesize() bpp = surface.get_bitsize() pygame_buffer = surface.get_buffer() buffer = create_string_buffer(pygame_buffer.raw, pygame_buffer.length) image = TextureImage() image.width = width image.height = height image.level = 0 image.storage = RGBA #FIXME: don't assume either image.type = UNSIGNED_BYTE #FIXME: don't assume 32 bit RGBA image.format = RGBA #FIXME: don't assume 32 bit RGBA image.border = 0 image.data = buffer return image
def checkerboard_teximage(w, h, primary=(255, 0, 255), secondary=(0, 0, 0)): assert not w % 2 assert not h % 2 image = TextureImage() image.width = w image.height = h image.level = 0 image.storage = c_int(3) image.format = RGB image.type = UNSIGNED_BYTE image.border = 0 size = w * h * 3 pairs = Cycle([primary + secondary, secondary + primary]) data = ''.join( [pack('BBBBBB', *(pairs.next())) * (w / 2) for line in xrange(h)]) image.data = create_string_buffer(data, size) return image
def checkerboard_teximage(w, h, primary=(255, 0, 255), secondary=(0, 0, 0)): assert not w % 2 assert not h % 2 image = TextureImage() image.width = w image.height = h image.level = 0 image.storage = c_int(3) image.format = RGB image.type = UNSIGNED_BYTE image.border = 0 size = w * h * 3 pairs = Cycle([primary + secondary, secondary + primary]) data = ''.join([pack('BBBBBB', *(pairs.next())) * (w / 2) for line in xrange(h)]) image.data = create_string_buffer(data, size) return image