Ajout du GUI
This commit is contained in:
1002
kivy/core/image/__init__.py
Normal file
1002
kivy/core/image/__init__.py
Normal file
File diff suppressed because it is too large
Load Diff
BIN
kivy/core/image/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_dds.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_dds.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_ffpyplayer.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_ffpyplayer.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_pil.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_pil.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_pygame.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_pygame.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_sdl2.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_sdl2.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/__pycache__/img_tex.cpython-310.pyc
Normal file
BIN
kivy/core/image/__pycache__/img_tex.cpython-310.pyc
Normal file
Binary file not shown.
BIN
kivy/core/image/_img_sdl2.cpython-310-x86_64-linux-gnu.so
Executable file
BIN
kivy/core/image/_img_sdl2.cpython-310-x86_64-linux-gnu.so
Executable file
Binary file not shown.
40
kivy/core/image/img_dds.py
Normal file
40
kivy/core/image/img_dds.py
Normal file
@@ -0,0 +1,40 @@
|
||||
'''
|
||||
DDS: DDS image loader
|
||||
'''
|
||||
|
||||
__all__ = ('ImageLoaderDDS', )
|
||||
|
||||
from kivy.lib.ddsfile import DDSFile
|
||||
from kivy.logger import Logger
|
||||
from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
||||
|
||||
|
||||
class ImageLoaderDDS(ImageLoaderBase):
|
||||
|
||||
@staticmethod
|
||||
def extensions():
|
||||
return ('dds', )
|
||||
|
||||
def load(self, filename):
|
||||
try:
|
||||
dds = DDSFile(filename=filename)
|
||||
except:
|
||||
Logger.warning('Image: Unable to load image <%s>' % filename)
|
||||
raise
|
||||
|
||||
self.filename = filename
|
||||
width, height = dds.size
|
||||
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
|
||||
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]
|
||||
|
||||
|
||||
# register
|
||||
ImageLoader.register(ImageLoaderDDS)
|
||||
87
kivy/core/image/img_ffpyplayer.py
Normal file
87
kivy/core/image/img_ffpyplayer.py
Normal file
@@ -0,0 +1,87 @@
|
||||
'''
|
||||
FFPyPlayer: FFmpeg based image loader
|
||||
'''
|
||||
|
||||
__all__ = ('ImageLoaderFFPy', )
|
||||
|
||||
import ffpyplayer
|
||||
from ffpyplayer.pic import ImageLoader as ffImageLoader, SWScale
|
||||
from ffpyplayer.tools import set_log_callback, get_log_callback
|
||||
|
||||
from kivy.logger import Logger
|
||||
from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
||||
|
||||
|
||||
Logger.info('ImageLoaderFFPy: Using ffpyplayer {}'.format(ffpyplayer.version))
|
||||
|
||||
|
||||
logger_func = {'quiet': Logger.critical, 'panic': Logger.critical,
|
||||
'fatal': Logger.critical, 'error': Logger.error,
|
||||
'warning': Logger.warning, 'info': Logger.info,
|
||||
'verbose': Logger.debug, 'debug': Logger.debug}
|
||||
|
||||
|
||||
def _log_callback(message, level):
|
||||
message = message.strip()
|
||||
if message:
|
||||
logger_func[level]('ffpyplayer: {}'.format(message))
|
||||
|
||||
|
||||
if not get_log_callback():
|
||||
set_log_callback(_log_callback)
|
||||
|
||||
|
||||
class ImageLoaderFFPy(ImageLoaderBase):
|
||||
'''Image loader based on the ffpyplayer library.
|
||||
|
||||
.. versionadded:: 1.9.0
|
||||
|
||||
.. note:
|
||||
This provider may support more formats than what is listed in
|
||||
:meth:`extensions`.
|
||||
'''
|
||||
|
||||
@staticmethod
|
||||
def extensions():
|
||||
'''Return accepted extensions for this loader'''
|
||||
# See https://www.ffmpeg.org/general.html#Image-Formats
|
||||
return ('bmp', 'dpx', 'exr', 'gif', 'ico', 'jpeg', 'jpg2000', 'jpg',
|
||||
'jls', 'pam', 'pbm', 'pcx', 'pgm', 'pgmyuv', 'pic', 'png',
|
||||
'ppm', 'ptx', 'sgi', 'ras', 'tga', 'tiff', 'webp', 'xbm',
|
||||
'xface', 'xwd')
|
||||
|
||||
def load(self, filename):
|
||||
try:
|
||||
loader = ffImageLoader(filename)
|
||||
except:
|
||||
Logger.warning('Image: Unable to load image <%s>' % filename)
|
||||
raise
|
||||
|
||||
# update internals
|
||||
self.filename = filename
|
||||
images = []
|
||||
|
||||
while True:
|
||||
frame, t = loader.next_frame()
|
||||
if frame is None:
|
||||
break
|
||||
images.append(frame)
|
||||
if not len(images):
|
||||
raise Exception('No image found in {}'.format(filename))
|
||||
|
||||
w, h = images[0].get_size()
|
||||
ifmt = images[0].get_pixel_format()
|
||||
if ifmt != 'rgba' and ifmt != 'rgb24':
|
||||
fmt = 'rgba'
|
||||
sws = SWScale(w, h, ifmt, ofmt=fmt)
|
||||
for i, image in enumerate(images):
|
||||
images[i] = sws.scale(image)
|
||||
else:
|
||||
fmt = ifmt if ifmt == 'rgba' else 'rgb'
|
||||
|
||||
return [ImageData(w, h, fmt, img.to_memoryview()[0], source_image=img)
|
||||
for img in images]
|
||||
|
||||
|
||||
# register
|
||||
ImageLoader.register(ImageLoaderFFPy)
|
||||
123
kivy/core/image/img_pil.py
Normal file
123
kivy/core/image/img_pil.py
Normal file
@@ -0,0 +1,123 @@
|
||||
'''
|
||||
PIL: PIL image loader
|
||||
'''
|
||||
|
||||
__all__ = ('ImageLoaderPIL', )
|
||||
|
||||
try:
|
||||
import Image as PILImage
|
||||
except ImportError:
|
||||
# for python3
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from kivy.logger import Logger
|
||||
from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
||||
|
||||
try:
|
||||
# Pillow
|
||||
PILImage.frombytes
|
||||
PILImage.Image.tobytes
|
||||
except AttributeError:
|
||||
# PIL
|
||||
# monkey patch frombytes and tobytes methods, refs:
|
||||
# https://github.com/kivy/kivy/issues/5460
|
||||
PILImage.frombytes = PILImage.frombuffer
|
||||
PILImage.Image.tobytes = PILImage.Image.tostring
|
||||
|
||||
|
||||
class ImageLoaderPIL(ImageLoaderBase):
|
||||
'''Image loader based on the PIL library.
|
||||
|
||||
.. versionadded:: 1.0.8
|
||||
|
||||
Support for GIF animation added.
|
||||
|
||||
Gif animation has a lot of issues(transparency/color depths... etc).
|
||||
In order to keep it simple, what is implemented here is what is
|
||||
natively supported by the PIL library.
|
||||
|
||||
As a general rule, try to use gifs that have no transparency.
|
||||
Gif's with transparency will work but be prepared for some
|
||||
artifacts until transparency support is improved.
|
||||
|
||||
'''
|
||||
|
||||
@staticmethod
|
||||
def can_save(fmt, is_bytesio):
|
||||
if is_bytesio:
|
||||
return False
|
||||
return fmt in ImageLoaderPIL.extensions()
|
||||
|
||||
@staticmethod
|
||||
def can_load_memory():
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def extensions():
|
||||
'''Return accepted extensions for this loader'''
|
||||
PILImage.init()
|
||||
return tuple((ext_with_dot[1:] for ext_with_dot in PILImage.EXTENSION))
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def load(self, filename):
|
||||
try:
|
||||
im = PILImage.open(filename)
|
||||
except:
|
||||
Logger.warning('Image: Unable to load image <%s>' % filename)
|
||||
raise
|
||||
# update internals
|
||||
if not self._inline:
|
||||
self.filename = filename
|
||||
# returns an array of type ImageData len 1 if not a sequence image
|
||||
return list(self._img_read(im))
|
||||
|
||||
@staticmethod
|
||||
def save(filename, width, height, pixelfmt, pixels, flipped=False,
|
||||
imagefmt=None):
|
||||
image = PILImage.frombytes(pixelfmt.upper(), (width, height), pixels)
|
||||
if flipped:
|
||||
image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
|
||||
image.save(filename)
|
||||
return True
|
||||
|
||||
|
||||
# register
|
||||
ImageLoader.register(ImageLoaderPIL)
|
||||
119
kivy/core/image/img_pygame.py
Normal file
119
kivy/core/image/img_pygame.py
Normal file
@@ -0,0 +1,119 @@
|
||||
'''
|
||||
Pygame: Pygame image loader
|
||||
|
||||
.. warning::
|
||||
|
||||
Pygame has been deprecated and will be removed in the release after Kivy
|
||||
1.11.0.
|
||||
'''
|
||||
|
||||
__all__ = ('ImageLoaderPygame', )
|
||||
|
||||
from kivy.logger import Logger
|
||||
from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
||||
from os.path import isfile
|
||||
from kivy.utils import deprecated
|
||||
|
||||
try:
|
||||
import pygame
|
||||
except:
|
||||
raise
|
||||
|
||||
|
||||
class ImageLoaderPygame(ImageLoaderBase):
|
||||
'''Image loader based on the PIL library'''
|
||||
|
||||
@deprecated(
|
||||
msg='Pygame has been deprecated and will be removed after 1.11.0')
|
||||
def __init__(self, *largs, **kwargs):
|
||||
super(ImageLoaderPygame, self).__init__(*largs, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def extensions():
|
||||
'''Return accepted extensions for this loader'''
|
||||
# under OS X, i got with "pygame.error: File is not a Windows BMP
|
||||
# file". documentation said: The image module is a required dependency
|
||||
# of Pygame, but it only optionally supports any extended file formats.
|
||||
# By default it can only load uncompressed BMP image
|
||||
if pygame.image.get_extended() == 0:
|
||||
return ('bmp', )
|
||||
return ('jpg', 'jpeg', 'jpe', 'png', 'bmp', 'pcx', 'tga', 'tiff',
|
||||
'tif', 'lbm', 'pbm', 'ppm', 'xpm')
|
||||
|
||||
@staticmethod
|
||||
def can_save(fmt, is_bytesio):
|
||||
if is_bytesio:
|
||||
return False
|
||||
return fmt in ('png', 'jpg')
|
||||
|
||||
@staticmethod
|
||||
def can_load_memory():
|
||||
return True
|
||||
|
||||
def load(self, filename):
|
||||
if not filename:
|
||||
import traceback
|
||||
traceback.print_stack()
|
||||
return
|
||||
try:
|
||||
im = None
|
||||
if self._inline:
|
||||
im = pygame.image.load(filename, 'x.{}'.format(self._ext))
|
||||
elif isfile(filename):
|
||||
with open(filename, 'rb') as fd:
|
||||
im = pygame.image.load(fd)
|
||||
elif isinstance(filename, bytes):
|
||||
try:
|
||||
fname = filename.decode()
|
||||
if isfile(fname):
|
||||
with open(fname, 'rb') as fd:
|
||||
im = pygame.image.load(fd)
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
if im is None:
|
||||
im = pygame.image.load(filename)
|
||||
except:
|
||||
# Logger.warning(type(filename)('Image: Unable to load image <%s>')
|
||||
# % filename)
|
||||
raise
|
||||
|
||||
fmt = ''
|
||||
if im.get_bytesize() == 3 and not im.get_colorkey():
|
||||
fmt = 'rgb'
|
||||
elif im.get_bytesize() == 4:
|
||||
fmt = 'rgba'
|
||||
|
||||
# image loader work only with rgb/rgba image
|
||||
if fmt not in ('rgb', 'rgba'):
|
||||
try:
|
||||
imc = im.convert(32)
|
||||
fmt = 'rgba'
|
||||
except:
|
||||
try:
|
||||
imc = im.convert_alpha()
|
||||
fmt = 'rgba'
|
||||
except:
|
||||
Logger.warning(
|
||||
'Image: Unable to convert image %r to rgba (was %r)' %
|
||||
(filename, im.fmt))
|
||||
raise
|
||||
im = imc
|
||||
|
||||
# update internals
|
||||
if not self._inline:
|
||||
self.filename = filename
|
||||
data = pygame.image.tostring(im, fmt.upper())
|
||||
return [ImageData(im.get_width(), im.get_height(),
|
||||
fmt, data, source=filename)]
|
||||
|
||||
@staticmethod
|
||||
def save(filename, width, height, pixelfmt, pixels, flipped,
|
||||
imagefmt=None):
|
||||
surface = pygame.image.fromstring(
|
||||
pixels, (width, height), pixelfmt.upper(), flipped)
|
||||
pygame.image.save(surface, filename)
|
||||
return True
|
||||
|
||||
|
||||
# register
|
||||
ImageLoader.register(ImageLoaderPygame)
|
||||
66
kivy/core/image/img_sdl2.py
Normal file
66
kivy/core/image/img_sdl2.py
Normal file
@@ -0,0 +1,66 @@
|
||||
'''
|
||||
SDL2 image loader
|
||||
=================
|
||||
'''
|
||||
|
||||
__all__ = ('ImageLoaderSDL2', )
|
||||
|
||||
from kivy.logger import Logger
|
||||
from kivy.core.image import ImageLoaderBase, ImageData, ImageLoader
|
||||
try:
|
||||
from kivy.core.image import _img_sdl2
|
||||
except ImportError:
|
||||
from kivy.core import handle_win_lib_import_error
|
||||
handle_win_lib_import_error(
|
||||
'image', 'sdl2', 'kivy.core.image._img_sdl2')
|
||||
raise
|
||||
|
||||
|
||||
class ImageLoaderSDL2(ImageLoaderBase):
|
||||
'''Image loader based on SDL2_image'''
|
||||
|
||||
def _ensure_ext(self):
|
||||
_img_sdl2.init()
|
||||
|
||||
@staticmethod
|
||||
def extensions():
|
||||
'''Return accepted extensions for this loader'''
|
||||
return ('bmp', 'jpg', 'jpeg', 'jpe', 'lbm', 'pcx', 'png', 'pnm',
|
||||
'tga', 'tiff', 'webp', 'xcf', 'xpm', 'xv')
|
||||
|
||||
@staticmethod
|
||||
def can_save(fmt, is_bytesio):
|
||||
return fmt in ('jpg', 'png')
|
||||
|
||||
@staticmethod
|
||||
def can_load_memory():
|
||||
return True
|
||||
|
||||
def load(self, filename):
|
||||
if self._inline:
|
||||
data = filename.read()
|
||||
info = _img_sdl2.load_from_memory(data)
|
||||
else:
|
||||
info = _img_sdl2.load_from_filename(filename)
|
||||
if not info:
|
||||
Logger.warning('Image: Unable to load image <%s>' % filename)
|
||||
raise Exception('SDL2: Unable to load image')
|
||||
|
||||
w, h, fmt, pixels, rowlength = info
|
||||
|
||||
# update internals
|
||||
if not self._inline:
|
||||
self.filename = filename
|
||||
return [ImageData(
|
||||
w, h, fmt, pixels, source=filename,
|
||||
rowlength=rowlength)]
|
||||
|
||||
@staticmethod
|
||||
def save(filename, width, height, pixelfmt, pixels, flipped, imagefmt):
|
||||
_img_sdl2.save(filename, width, height, pixelfmt, pixels, flipped,
|
||||
imagefmt)
|
||||
return True
|
||||
|
||||
|
||||
# register
|
||||
ImageLoader.register(ImageLoaderSDL2)
|
||||
58
kivy/core/image/img_tex.py
Normal file
58
kivy/core/image/img_tex.py
Normal file
@@ -0,0 +1,58 @@
|
||||
'''
|
||||
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 range(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)
|
||||
Reference in New Issue
Block a user