Permalink
Browse files

core/image: prevent to flip the source vertically, prefer to flip the…

… texture coordinate.

Current implementation: pygame/pil need vertical flip, gif/dds don't need.
  • Loading branch information...
1 parent 489235b commit ce106459de26b4dd324d209508bb470f192fefda @tito tito committed Oct 11, 2012
@@ -41,11 +41,11 @@ class ImageData(object):
The container will always have at least the mipmap level 0.
'''
- __slots__ = ('fmt', 'mipmaps', 'source')
+ __slots__ = ('fmt', 'mipmaps', 'source', 'flip_vertical')
_supported_fmts = ('rgb', 'rgba', 'bgr', 'bgra',
's3tc_dxt1', 's3tc_dxt3', 's3tc_dxt5')
- def __init__(self, width, height, fmt, data, source=None):
+ def __init__(self, width, height, fmt, data, source=None, flip_vertical=True):
assert fmt in ImageData._supported_fmts
#: Decoded image format, one of a available texture format
@@ -58,6 +58,9 @@ def __init__(self, width, height, fmt, data, source=None):
#: Image source, if available
self.source = source
+ #: Indicate if the texture will need to be vertically flipped
+ self.flip_vertical = flip_vertical
+
def release_data(self):
mm = self.mipmaps
for item in mm.itervalues():
@@ -165,10 +168,13 @@ def populate(self):
# if not create it and append to the cache
if texture is None:
+ imagedata = self._data[count]
texture = Texture.create_from_data(
- self._data[count], mipmap=self._mipmap)
+ imagedata, mipmap=self._mipmap)
if not self._nocache:
Cache.append('kv.texture', uid, texture)
+ if imagedata.flip_vertical:
+ texture.flip_vertical()
# set as our current texture
self._textures.append(texture)
@@ -24,7 +24,8 @@ def load(self, filename):
self.filename = filename
width, height = dds.size
- im = ImageData(width, height, dds.dxt, dds.images[0], source=filename)
+ im = ImageData(width, height, dds.dxt, dds.images[0], source=filename,
+ flip_vertical=False)
if len(dds.images) > 1:
images = dds.images
images_size = dds.images_size
@@ -133,7 +133,7 @@ def load(self, filename):
i += 1
img_data_append(ImageData(ls_width, ls_height,
- 'rgba', pixel_map.tostring()))
+ 'rgba', pixel_map.tostring(), flip_vertical=False))
if draw_method_replace:
pixel_map = array('B', [0] * (ls_width * ls_height * 4))
@@ -54,8 +54,6 @@ def _img_correct(self, _img_tmp):
raise
_img_tmp = imc
- # image are not in the good direction, flip !
- _img_tmp = _img_tmp.transpose(PILImage.FLIP_TOP_BOTTOM)
return _img_tmp
def _img_read(self, im):
@@ -64,7 +64,7 @@ def load(self, filename):
# update internals
self.filename = filename
- data = pygame.image.tostring(im, fmt.upper(), True)
+ data = pygame.image.tostring(im, fmt.upper())
return [ImageData(im.get_width(), im.get_height(),
fmt, data, source=filename)]

0 comments on commit ce10645

Please sign in to comment.