diff --git a/kivy/__init__.py b/kivy/__init__.py index c2c6861ec..5315f9000 100644 --- a/kivy/__init__.py +++ b/kivy/__init__.py @@ -190,7 +190,7 @@ kivy_options = { 'text': ('pil', 'pygame', 'sdlttf'), 'video': ('ffmpeg', 'gstreamer', 'pyglet'), 'audio': ('pygame', 'gstreamer', 'sdl'), - 'image': ('imageio', 'dds', 'gif', 'pil', 'pygame'), + 'image': ('tex', 'imageio', 'dds', 'gif', 'pil', 'pygame'), 'camera': ('opencv', 'gstreamer', 'videocapture'), 'spelling': ('enchant', 'osxappkit', ), 'clipboard': ('pygame', 'dummy'), } diff --git a/kivy/core/image/__init__.py b/kivy/core/image/__init__.py index 499c27d82..601041840 100644 --- a/kivy/core/image/__init__.py +++ b/kivy/core/image/__init__.py @@ -44,7 +44,8 @@ class ImageData(object): __slots__ = ('fmt', 'mipmaps', 'source', 'flip_vertical') _supported_fmts = ('rgb', 'rgba', 'bgr', 'bgra', - 's3tc_dxt1', 's3tc_dxt3', 's3tc_dxt5') + 's3tc_dxt1', 's3tc_dxt3', 's3tc_dxt5', + 'pvrtc_rgb2', 'pvrtc_rgb4', 'pvrtc_rgba2', 'pvrtc_rgba4') def __init__(self, width, height, fmt, data, source=None, flip_vertical=True): assert fmt in ImageData._supported_fmts @@ -709,6 +710,7 @@ image_libs = [] if platform() in ('macosx', 'ios'): image_libs += [('imageio', 'img_imageio')] image_libs += [ + ('tex', 'img_tex'), ('dds', 'img_dds'), ('pygame', 'img_pygame'), ('pil', 'img_pil'), diff --git a/kivy/core/image/img_tex.py b/kivy/core/image/img_tex.py new file mode 100644 index 000000000..1fb388aea --- /dev/null +++ b/kivy/core/image/img_tex.py @@ -0,0 +1,57 @@ +''' +Tex: Compressed texture +''' + +__all__ = ('ImageLoaderTex', ) + +import json +from struct import unpack +from kivy.logger import Logger +from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader + + +class ImageLoaderTex(ImageLoaderBase): + + @staticmethod + def extensions(): + return ('tex', ) + + def load(self, filename): + try: + fd = open(filename, 'rb') + if fd.read(4) != 'KTEX': + raise Exception('Invalid tex identifier') + + headersize = unpack('I', fd.read(4))[0] + header = fd.read(headersize) + if len(header) != headersize: + raise Exception('Truncated tex header') + + info = json.loads(header) + data = fd.read() + if len(data) != info['datalen']: + raise Exception('Truncated tex data') + + except: + Logger.warning('Image: Image <%s> is corrupted' % filename) + raise + + width, height = info['image_size'] + tw, th = info['texture_size'] + + images = [data] + im = ImageData(width, height, str(info['format']), images[0], + source=filename) + ''' + if len(dds.images) > 1: + images = dds.images + images_size = dds.images_size + for index in xrange(1, len(dds.images)): + w, h = images_size[index] + data = images[index] + im.add_mipmap(index, w, h, data) + ''' + return [im] + +# register +ImageLoader.register(ImageLoaderTex)