Python: Add PIL export

This commit is contained in:
Vicki Pfau 2017-06-14 17:28:01 -07:00
parent 732ed5fa4d
commit 0e40168a1b
2 changed files with 56 additions and 45 deletions

View File

@ -6,6 +6,11 @@
from ._pylib import ffi, lib
from . import png
try:
import PIL.Image as PImage
except ImportError:
pass
class Image:
def __init__(self, width, height, stride=0):
self.width = width
@ -25,6 +30,11 @@ class Image:
p.writeClose()
return success
if 'PImage' in globals():
def toPIL(self):
return PImage.frombytes("RGBX", (self.width, self.height), ffi.buffer(self.buffer), "raw",
"RGBX", self.stride * 4)
def u16ToU32(c):
r = c & 0x1F
g = (c >> 5) & 0x1F

View File

@ -23,6 +23,7 @@ setup(name="${BINARY_NAME}",
packages=["mgba"],
setup_requires=['cffi>=1.6'],
install_requires=['cffi>=1.6', 'cached-property'],
extras_require={'pil': ['Pillow>=2.3']},
cffi_modules=["_builder.py:ffi"],
license="MPL 2.0",
classifiers=classifiers