|
7 | 7 | except:
|
8 | 8 | raise
|
9 | 9 |
|
| 10 | +from kivy.cache import Cache |
10 | 11 | from kivy.logger import Logger
|
11 | 12 | from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
12 | 13 |
|
| 14 | +from kivy.graphics.texture import Texture, TextureRegion |
13 | 15 | Debug = False
|
14 | 16 |
|
15 | 17 | import io
|
@@ -60,4 +62,32 @@ def load(self, filename):
|
60 | 62 |
|
61 | 63 | return (ImageData(size[0], size[1], 'rgba', im.tostring()),)
|
62 | 64 |
|
| 65 | + def populate(self): |
| 66 | + self._textures = [] |
| 67 | + if __debug__: |
| 68 | + Logger.trace('Image: %r, populate to textures (%d)' % |
| 69 | + (self.filename, len(self._data))) |
| 70 | + |
| 71 | + # first, check if a texture with the same name already exist in the |
| 72 | + # cache |
| 73 | + uid = '%s|%s|%s' % ( |
| 74 | + self.filename, |
| 75 | + self._mipmap, |
| 76 | + hasattr(self, 'page') and self.page or 0) |
| 77 | + |
| 78 | + texture = Cache.get('kv.texture', uid) |
| 79 | + |
| 80 | + # if not create it and append to the cache |
| 81 | + if texture is None: |
| 82 | + texture = Texture.create_from_data( |
| 83 | + self._data[0], mipmap=self._mipmap) |
| 84 | + Cache.append('kv.texture', uid, texture) |
| 85 | + |
| 86 | + # set as our current texture |
| 87 | + self._textures.append(texture) |
| 88 | + |
| 89 | + # release data if ask |
| 90 | + if not self.keep_data: |
| 91 | + self._data[0].release_data() |
| 92 | + |
63 | 93 | ImageLoader.register(ImageLoaderPDF)
|
0 commit comments