mirror of https://github.com/mgba-emu/mgba.git
Python: Add PIL export
This commit is contained in:
parent
732ed5fa4d
commit
0e40168a1b
|
@ -6,6 +6,11 @@
|
||||||
from ._pylib import ffi, lib
|
from ._pylib import ffi, lib
|
||||||
from . import png
|
from . import png
|
||||||
|
|
||||||
|
try:
|
||||||
|
import PIL.Image as PImage
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
def __init__(self, width, height, stride=0):
|
def __init__(self, width, height, stride=0):
|
||||||
self.width = width
|
self.width = width
|
||||||
|
@ -25,6 +30,11 @@ class Image:
|
||||||
p.writeClose()
|
p.writeClose()
|
||||||
return success
|
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):
|
def u16ToU32(c):
|
||||||
r = c & 0x1F
|
r = c & 0x1F
|
||||||
g = (c >> 5) & 0x1F
|
g = (c >> 5) & 0x1F
|
||||||
|
|
|
@ -23,6 +23,7 @@ setup(name="${BINARY_NAME}",
|
||||||
packages=["mgba"],
|
packages=["mgba"],
|
||||||
setup_requires=['cffi>=1.6'],
|
setup_requires=['cffi>=1.6'],
|
||||||
install_requires=['cffi>=1.6', 'cached-property'],
|
install_requires=['cffi>=1.6', 'cached-property'],
|
||||||
|
extras_require={'pil': ['Pillow>=2.3']},
|
||||||
cffi_modules=["_builder.py:ffi"],
|
cffi_modules=["_builder.py:ffi"],
|
||||||
license="MPL 2.0",
|
license="MPL 2.0",
|
||||||
classifiers=classifiers
|
classifiers=classifiers
|
||||||
|
|
Loading…
Reference in New Issue