Add files via upload

This commit is contained in:
themixray 2021-11-02 13:25:13 +03:00 committed by GitHub
parent e87b3c276a
commit 1170f1521c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 764 additions and 0 deletions

42
pygwin/image.py Normal file
View file

@ -0,0 +1,42 @@
from pygwin._pg import pg as _pg
from pygwin.surface import surface as _surface
from PIL import Image as _image
import pickle as _p
def load(path):
if path.endswith('.gif'):
im = Image.open(path)
surfs = []
for i in range(im.n_frames):
im.seek(i)
image = _pg.image.fromstring(im.tobytes(),im.size,im.mode)
surf = _surface(image.get_size())
surf._surface_orig = image
surfs.append(surf)
return surfs
else:
image = _pg.image.load(path)
surf = _surface(image.get_size())
surf._surface_orig = image
return surf
def save(surface, path):
if type(surface) == _surface:
orig = surface._surface_orig
else:
orig = surface._orig
_pg.image.save_extended(orig, path)
def toString(surface):
if type(surface) == _surface:
orig = surface._surface_orig
else:
orig = surface._orig
return _p.dumps([_pg.image.tostring(orig, "RGBA"), list(surface.size)])
def fromString(string):
string = _p.loads(string)
surf = _pg.image.fromstring(string[0], tuple(string[1]), "RGBA")
surface = _surface(tuple(string[1]))
surface._surface_orig = surf
return surface