mirror of https://github.com/kivy/kivy.git
core: new tex image loader, abstract format generated from texturecompress.py
This commit is contained in:
parent
e5b1db2997
commit
2b697d657a
|
@ -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'), }
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue