query_docstring
stringlengths 1
21.6k
| positive_code
stringlengths 36
104k
| hard_negative_code
stringlengths 36
104k
| similarity_score
float64 -0
0.93
| query_repo
stringclasses 219
values | query_path
stringlengths 5
148
| hn_repo
stringclasses 216
values | hn_path
stringlengths 5
148
| hn_license
stringclasses 4
values | language
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|
Add a image for a specific mipmap level.
.. versionadded:: 1.0.7 | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | 0.522208 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Add a image for a specific mipmap level.
.. versionadded:: 1.0.7 | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | 0.418251 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Add a image for a specific mipmap level.
.. versionadded:: 1.0.7 | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.401828 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Add a image for a specific mipmap level.
.. versionadded:: 1.0.7 | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.371796 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Add a image for a specific mipmap level.
.. versionadded:: 1.0.7 | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.36935 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7 | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | def add_mipmap(self, level, width, height, data, rowlength):
'''Add a image for a specific mipmap level.
.. versionadded:: 1.0.7
'''
self.mipmaps[level] = [int(width), int(height), data, rowlength] | 0.630128 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7 | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | 0.547371 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7 | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | def data(self):
'''Image data.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][2] | 0.516582 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7 | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | def width(self):
'''Image width in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][0] | 0.455412 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7 | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | def size(self):
'''Image (width, height) in pixels.
(If the image is mipmapped, it will use the level 0)
'''
mm = self.mipmaps[0]
return mm[0], mm[1] | 0.442205 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Iterate over all mipmap images available.
.. versionadded:: 1.0.7 | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.527589 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Iterate over all mipmap images available.
.. versionadded:: 1.0.7 | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | def data(self):
'''Image data.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][2] | 0.432525 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Iterate over all mipmap images available.
.. versionadded:: 1.0.7 | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | def get_mipmap(self, level):
'''Get the mipmap image at a specific level if it exists
.. versionadded:: 1.0.7
'''
if level == 0:
return self.width, self.height, self.data, self.rowlength
assert level < len(self.mipmaps)
return self.mipmaps[level] | 0.430205 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Iterate over all mipmap images available.
.. versionadded:: 1.0.7 | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | 0.39581 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Iterate over all mipmap images available.
.. versionadded:: 1.0.7 | def iterate_mipmaps(self):
'''Iterate over all mipmap images available.
.. versionadded:: 1.0.7
'''
mm = self.mipmaps
for x in range(len(mm)):
item = mm.get(x, None)
if item is None:
raise Exception('Invalid mipmap level, found empty one')
yield x, item[0], item[1], item[2], item[3] | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | 0.36823 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image | def load(self, filename):
'''Load an image'''
return None | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.711842 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image | def load(self, filename):
'''Load an image'''
return None | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.629 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Load an image | def load(self, filename):
'''Load an image'''
return None | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.532467 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Load an image | def load(self, filename):
'''Load an image'''
return None | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.521129 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image | def load(self, filename):
'''Load an image'''
return None | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | 0.502715 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added | def can_save(fmt, is_bytesio=False):
'''Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added
'''
return False | def _img_correct(self, _img_tmp):
'''Convert image to the correct format and orientation.
'''
# image loader work only with rgb/rgba image
if _img_tmp.mode.lower() not in ('rgb', 'rgba'):
try:
imc = _img_tmp.convert('RGBA')
except:
Logger.warning(
'Image: Unable to convert image to rgba (was %s)' %
(_img_tmp.mode.lower()))
raise
_img_tmp = imc
return _img_tmp | 0.48096 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added | def can_save(fmt, is_bytesio=False):
'''Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added
'''
return False | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.462602 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added | def can_save(fmt, is_bytesio=False):
'''Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added
'''
return False | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | 0.421271 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added | def can_save(fmt, is_bytesio=False):
'''Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added
'''
return False | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.384807 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added | def can_save(fmt, is_bytesio=False):
'''Indicate if the loader can save the Image object
.. versionchanged:: 1.11.0
Parameter `fmt` and `is_bytesio` added
'''
return False | def _copy_to_gpu(self):
"""
A dummy placeholder (the image is already in GPU) to be consistent
with other providers.
"""
self.dispatch('on_texture') | 0.380476 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
Indicate if the loader can load an image by passing data | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | def _img_correct(self, _img_tmp):
'''Convert image to the correct format and orientation.
'''
# image loader work only with rgb/rgba image
if _img_tmp.mode.lower() not in ('rgb', 'rgba'):
try:
imc = _img_tmp.convert('RGBA')
except:
Logger.warning(
'Image: Unable to convert image to rgba (was %s)' %
(_img_tmp.mode.lower()))
raise
_img_tmp = imc
return _img_tmp | 0.48778 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Indicate if the loader can load an image by passing data | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.458843 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Indicate if the loader can load an image by passing data | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.44463 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the loader can load an image by passing data | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.411118 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the loader can load an image by passing data | def can_load_memory():
'''Indicate if the loader can load an image by passing data
'''
return False | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.374763 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Image width | def width(self):
'''Image width
'''
return self._data[0].width | def width(self):
'''Image width in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][0] | 0.627056 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image width | def width(self):
'''Image width
'''
return self._data[0].width | def height(self):
'''Image height
'''
return self._data[0].height | 0.494178 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image width | def width(self):
'''Image width
'''
return self._data[0].width | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | 0.47291 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image width | def width(self):
'''Image width
'''
return self._data[0].width | def height(self):
'''Image height in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][1] | 0.45629 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image width | def width(self):
'''Image width
'''
return self._data[0].width | def rowlength(self):
'''Image rowlength.
(If the image is mipmapped, it will use the level 0)
.. versionadded:: 1.9.0
'''
return self.mipmaps[0][3] | 0.453989 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image height | def height(self):
'''Image height
'''
return self._data[0].height | def height(self):
'''Image height in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][1] | 0.659313 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image height | def height(self):
'''Image height
'''
return self._data[0].height | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | 0.523009 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image height | def height(self):
'''Image height
'''
return self._data[0].height | def width(self):
'''Image width
'''
return self._data[0].width | 0.498967 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image height | def height(self):
'''Image height
'''
return self._data[0].height | def width(self):
'''Image width in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][0] | 0.492736 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image height | def height(self):
'''Image height
'''
return self._data[0].height | def size(self):
'''Image (width, height) in pixels.
(If the image is mipmapped, it will use the level 0)
'''
mm = self.mipmaps[0]
return mm[0], mm[1] | 0.435751 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image size (width, height) | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | def size(self):
'''Image (width, height) in pixels.
(If the image is mipmapped, it will use the level 0)
'''
mm = self.mipmaps[0]
return mm[0], mm[1] | 0.592065 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image size (width, height) | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | def width(self):
'''Image width in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][0] | 0.523558 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image size (width, height) | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | def height(self):
'''Image height in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][1] | 0.501587 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image size (width, height) | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | def width(self):
'''Image width
'''
return self._data[0].width | 0.494708 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Image size (width, height) | def size(self):
'''Image size (width, height)
'''
return self._data[0].width, self._data[0].height | def height(self):
'''Image height
'''
return self._data[0].height | 0.486383 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the image texture (created on the first call) | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | 0.556012 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the image texture (created on the first call) | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | def _copy_to_gpu(self):
"""
A dummy placeholder (the image is already in GPU) to be consistent
with other providers.
"""
self.dispatch('on_texture') | 0.548612 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
Get the image texture (created on the first call) | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | def _copy_to_gpu(self):
'''Copy the buffer into the texture.'''
if self._texture is None:
Logger.debug('Camera: copy_to_gpu() failed, _texture is None !')
return
self._texture.blit_buffer(self._buffer, colorfmt=self._format)
self._buffer = None
self.dispatch('on_texture') | 0.535337 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/__init__.py | MIT | python |
Get the image texture (created on the first call) | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.502887 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Get the image texture (created on the first call) | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | def data(self):
'''Image data.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][2] | 0.446932 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8 | def textures(self):
'''Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8
'''
if self._textures is None:
self.populate()
return self._textures | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | 0.605375 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8 | def textures(self):
'''Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8
'''
if self._textures is None:
self.populate()
return self._textures | def data(self):
'''Image data.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][2] | 0.456288 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8 | def textures(self):
'''Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8
'''
if self._textures is None:
self.populate()
return self._textures | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | 0.403725 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8 | def textures(self):
'''Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8
'''
if self._textures is None:
self.populate()
return self._textures | def extensions():
'''Return accepted extensions for this loader'''
return ('bmp', 'jpg', 'jpeg', 'jpe', 'lbm', 'pcx', 'png', 'pnm',
'tga', 'tiff', 'webp', 'xcf', 'xpm', 'xv') | 0.395115 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_sdl2.py | MIT | python |
Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8 | def textures(self):
'''Get the textures list (for mipmapped image or animated image)
.. versionadded:: 1.0.8
'''
if self._textures is None:
self.populate()
return self._textures | def _copy_to_gpu(self):
"""
A dummy placeholder (the image is already in GPU) to be consistent
with other providers.
"""
self.dispatch('on_texture') | 0.3882 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0 | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | 0.498264 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0 | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | def exists(self, key):
'''Check if a key exists in the store.
'''
return self.store_exists(key) | 0.46791 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/storage/__init__.py | MIT | python |
Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0 | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | 0.467638 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0 | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | 0.457524 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0 | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | 0.435955 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.69264 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.650227 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.603932 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | def read_frame(self):
"""
Grab and decode frame in one call
"""
return self.decode_frame(self.grab_frame()) | 0.420079 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.405649 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.496699 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | def clear(self):
'''Wipe the whole storage.
'''
return self.store_clear() | 0.408951 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/storage/__init__.py | MIT | python |
Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.405018 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | def load(self, filename):
'''Load an image'''
return None | 0.394948 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk | def remove_from_cache(self):
'''Remove the Image from cache. This facilitates re-loading of
images from disk in case the image content has changed.
.. versionadded:: 1.3.0
Usage::
im = CoreImage('1.jpg')
# -- do something --
im.remove_from_cache()
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
'''
count = 0
uid = f'{self.filename}|{self._mipmap:d}|{count:d}'
Cache.remove("kv.image", uid)
while Cache.get("kv.texture", uid):
Cache.remove("kv.texture", uid)
count += 1
uid = f'{self.filename}|{self._mipmap:d}|{count:d}' | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | 0.392925 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20. | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | 0.57342 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20. | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | 0.521332 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20. | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | def reset_dpi(self, *args):
"""Resets the dpi (and possibly density) to the platform values,
overwriting any manually set values.
"""
self.dpi = self.get_dpi(force_recompute=True) | 0.362942 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/metrics.py | MIT | python |
Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20. | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | def reset_metrics(self):
"""Resets the dpi/density/fontscale to the platform values, overwriting
any manually set values.
"""
self.dpi = self.get_dpi(force_recompute=True)
self.density = self.get_density(force_recompute=True)
self.fontscale = self.get_fontscale(force_recompute=True) | 0.340273 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/metrics.py | MIT | python |
Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20. | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | def pause(self, *largs):
'''Pause the application.
On Android set OS state to pause, Kivy app state follows.
No functionality on other OS.
.. versionadded:: 2.2.0
'''
if platform == 'android':
from android import mActivity
mActivity.moveTaskToBack(True)
else:
Logger.info('App.pause() is not available on this OS.') | 0.320301 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/app.py | MIT | python |
Return True if this Image instance has animation available.
.. versionadded:: 1.0.8 | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | def nocache(self):
'''Indicate if the texture will not be stored in the cache
.. versionadded:: 1.6.0
'''
return self._nocache | 0.4631 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return True if this Image instance has animation available.
.. versionadded:: 1.0.8 | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | 0.460741 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return True if this Image instance has animation available.
.. versionadded:: 1.0.8 | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | def anim_reset(self, allow_anim):
'''Reset an animation if available.
.. versionadded:: 1.0.8
:Parameters:
`allow_anim`: bool
Indicate whether the animation should restart playing or not.
Usage::
# start/reset animation
image.anim_reset(True)
# or stop the animation
image.anim_reset(False)
You can change the animation speed whilst it is playing::
# Set to 20 FPS
image.anim_delay = 1 / 20.
'''
# stop animation
if self._anim_ev is not None:
self._anim_ev.cancel()
self._anim_ev = None
if allow_anim and self._anim_available and self._anim_delay >= 0:
self._anim_ev = Clock.schedule_interval(self._anim,
self.anim_delay)
self._anim() | 0.459934 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return True if this Image instance has animation available.
.. versionadded:: 1.0.8 | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | def on_pause(self):
'''Event handler called when Pause mode is requested. You should
return True if your app can go into Pause mode, otherwise
return False and your application will be stopped.
You cannot control when the application is going to go into this mode.
It's determined by the Operating System and mostly used for mobile
devices (android/ios) and for resizing.
The default return value is True.
.. versionadded:: 1.1.0
.. versionchanged:: 1.10.0
The default return value is now True.
'''
return True | 0.405314 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/app.py | MIT | python |
Return True if this Image instance has animation available.
.. versionadded:: 1.0.8 | def anim_available(self):
'''Return True if this Image instance has animation available.
.. versionadded:: 1.0.8
'''
return self._anim_available | def is_color_terminal():
""" Detect whether the environment supports color codes in output.
.. versionadded:: 2.2.0
"""
return (
(
os.environ.get("WT_SESSION") or
os.environ.get("COLORTERM") == 'truecolor' or
os.environ.get('PYCHARM_HOSTED') == '1' or
os.environ.get('TERM') in (
'rxvt',
'rxvt-256color',
'rxvt-unicode',
'rxvt-unicode-256color',
'xterm',
'xterm-256color',
)
)
and platform not in ('android', 'ios')
) | 0.395395 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/logger.py | MIT | python |
Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8 | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | 0.583493 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8 | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | def width(self):
'''Image width in pixels.
(If the image is mipmapped, it will use the level 0)
'''
return self.mipmaps[0][0] | 0.497205 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8 | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | def width(self):
'''Image width
'''
return self._data[0].width | 0.443359 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8 | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | def rowlength(self):
'''Image rowlength.
(If the image is mipmapped, it will use the level 0)
.. versionadded:: 1.9.0
'''
return self.mipmaps[0][3] | 0.439147 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8 | def anim_index(self):
'''Return the index number of the image currently in the texture.
.. versionadded:: 1.0.8
'''
return self._anim_index | def get_camera_count():
"""
Get the number of available cameras.
"""
return Camera.getNumberOfCameras() | 0.431884 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8 | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | def texture(self):
'''Get the image texture (created on the first call)
'''
if self._textures is None:
self.populate()
if self._textures is None:
return None
return self._textures[0] | 0.48456 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8 | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | def _copy_to_gpu(self):
"""
A dummy placeholder (the image is already in GPU) to be consistent
with other providers.
"""
self.dispatch('on_texture') | 0.45804 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8 | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | def on_start(self):
'''Event handler for the `on_start` event which is fired after
initialization (after build() has been called) but before the
application has started running.
'''
pass | 0.409622 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/app.py | MIT | python |
This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8 | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | def on_resume(self):
'''Event handler called when your application is resuming from
the Pause mode.
.. versionadded:: 1.1.0
.. warning::
When resuming, the OpenGL Context might have been damaged / freed.
This is where you can reconstruct some of your OpenGL state
e.g. FBO content.
'''
pass | 0.393617 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/app.py | MIT | python |
This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8 | def on_texture(self, *largs):
'''This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.
.. versionadded:: 1.0.8
'''
pass | def on_config_change(self, config, section, key, value):
'''Event handler fired when a configuration token has been changed by
the settings page.
.. versionchanged:: 1.10.1
Added corresponding ``on_config_change`` event.
'''
pass | 0.390918 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/app.py | MIT | python |
Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created. | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.682563 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created. | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 0.628434 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created. | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | def load(self, filename):
'''Load an image'''
return None | 0.579694 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created. | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | 0.524015 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created. | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | def _copy_to_gpu(self):
"""
A dummy placeholder (the image is already in GPU) to be consistent
with other providers.
"""
self.dispatch('on_texture') | 0.507799 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/camera/camera_android.py | MIT | python |
(internal) Method to load an image from raw data. | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | def load(filename, **kwargs):
'''Load an image
:Parameters:
`filename`: str
Filename of the image.
`keep_data`: bool, defaults to False
Keep the image data when the texture is created.
'''
kwargs.setdefault('keep_data', False)
return Image(filename, **kwargs) | 0.633465 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
(internal) Method to load an image from raw data. | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | 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 range(1, len(dds.images)):
w, h = images_size[index]
data = images[index]
im.add_mipmap(index, w, h, data)
'''
return [im] | 0.572279 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_tex.py | MIT | python |
(internal) Method to load an image from raw data. | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | def _img_read(self, im):
'''Read images from an animated file.
'''
im.seek(0)
# Read all images inside
try:
img_ol = None
while True:
img_tmp = im
img_tmp = self._img_correct(img_tmp)
if img_ol and (hasattr(im, 'dispose') and not im.dispose):
# paste new frame over old so as to handle
# transparency properly
img_ol.paste(img_tmp, (0, 0), img_tmp)
img_tmp = img_ol
img_ol = img_tmp
yield ImageData(img_tmp.size[0], img_tmp.size[1],
img_tmp.mode.lower(), img_tmp.tobytes())
im.seek(im.tell() + 1)
except EOFError:
pass | 0.53471 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
(internal) Method to load an image from raw data. | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | def _img_correct(self, _img_tmp):
'''Convert image to the correct format and orientation.
'''
# image loader work only with rgb/rgba image
if _img_tmp.mode.lower() not in ('rgb', 'rgba'):
try:
imc = _img_tmp.convert('RGBA')
except:
Logger.warning(
'Image: Unable to convert image to rgba (was %s)' %
(_img_tmp.mode.lower()))
raise
_img_tmp = imc
return _img_tmp | 0.51727 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/img_pil.py | MIT | python |
(internal) Method to load an image from raw data. | def load_memory(self, data, ext, filename='__inline__'):
'''(internal) Method to load an image from raw data.
'''
self._filename = filename
# see if there is a available loader for it
loaders = [loader for loader in ImageLoader.loaders if
loader.can_load_memory() and
ext in loader.extensions()]
if not loaders:
raise Exception(f'No inline loader found to load {ext}')
image = loaders[0](filename, ext=ext, rawdata=data, inline=True,
nocache=self._nocache, mipmap=self._mipmap,
keep_data=self._keep_data)
if isinstance(image, Texture):
self._texture = image
self._size = image.size
else:
self.image = image | def zip_loader(filename, **kwargs):
'''Read images from an zip file.
.. versionadded:: 1.0.8
Returns an Image with a list of type ImageData stored in Image._data
'''
# read zip in memory for faster access
_file = BytesIO(open(filename, 'rb').read())
# read all images inside the zip
z = zipfile.ZipFile(_file)
image_data = []
# sort filename list
znamelist = z.namelist()
znamelist.sort()
image = None
for zfilename in znamelist:
try:
# read file and store it in mem with fileIO struct around it
tmpfile = BytesIO(z.read(zfilename))
ext = zfilename.split('.')[-1].lower()
im = None
for loader in ImageLoader.loaders:
if (ext not in loader.extensions() or
not loader.can_load_memory()):
continue
Logger.debug('Image%s: Load <%s> from <%s>' %
(loader.__name__[11:], zfilename, filename))
try:
im = loader(zfilename, ext=ext, rawdata=tmpfile,
inline=True, **kwargs)
except:
# Loader failed, continue trying.
continue
break
if im is not None:
# append ImageData to local variable before its
# overwritten
image_data.append(im._data[0])
image = im
# else: if not image file skip to next
except:
Logger.warning('Image: Unable to load image'
'<%s> in zip <%s> trying to continue...'
% (zfilename, filename))
z.close()
if len(image_data) == 0:
raise Exception('no images in zip <%s>' % filename)
# replace Image.Data with the array of all the images in the zip
image._data = image_data
image.filename = filename
return image | 0.461198 | kivy/kivy | kivy/core/image/__init__.py | kivy/kivy | kivy/core/image/__init__.py | MIT | python |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.