shrinko 1.2.6.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shrinko/font.png +0 -0
- shrinko/font64.png +0 -0
- shrinko/media_utils.py +153 -0
- shrinko/pico_cart.py +776 -0
- shrinko/pico_compress.py +668 -0
- shrinko/pico_constfold.py +757 -0
- shrinko/pico_defs.py +360 -0
- shrinko/pico_export.py +999 -0
- shrinko/pico_lint.py +156 -0
- shrinko/pico_minify.py +505 -0
- shrinko/pico_output.py +382 -0
- shrinko/pico_parse.py +1060 -0
- shrinko/pico_preprocess.py +143 -0
- shrinko/pico_process.py +351 -0
- shrinko/pico_rename.py +499 -0
- shrinko/pico_tokenize.py +830 -0
- shrinko/pico_unminify.py +115 -0
- shrinko/pico_utils.py +357 -0
- shrinko/picotron_cart.py +753 -0
- shrinko/picotron_defs.py +267 -0
- shrinko/picotron_export.py +279 -0
- shrinko/picotron_fs.py +541 -0
- shrinko/run_bbs_tests.py +329 -0
- shrinko/run_shrinko.py +715 -0
- shrinko/run_site_tests.py +80 -0
- shrinko/run_tests.py +326 -0
- shrinko/scripts/__init__.py +0 -0
- shrinko/scripts/split.py +197 -0
- shrinko/shrinko8.py +12 -0
- shrinko/shrinkotron.py +12 -0
- shrinko/template.plist +32 -0
- shrinko/template.png +0 -0
- shrinko/template64.png +0 -0
- shrinko/test_gui_utils.py +107 -0
- shrinko/test_utils.py +228 -0
- shrinko/utils.py +2673 -0
- shrinko-1.2.6.6.dist-info/METADATA +1088 -0
- shrinko-1.2.6.6.dist-info/RECORD +42 -0
- shrinko-1.2.6.6.dist-info/WHEEL +5 -0
- shrinko-1.2.6.6.dist-info/entry_points.txt +3 -0
- shrinko-1.2.6.6.dist-info/licenses/LICENSE +21 -0
- shrinko-1.2.6.6.dist-info/top_level.txt +1 -0
shrinko/font.png
ADDED
|
Binary file
|
shrinko/font64.png
ADDED
|
Binary file
|
shrinko/media_utils.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from utils import *
|
|
2
|
+
|
|
3
|
+
# (used to use sdl, now uses pil)
|
|
4
|
+
|
|
5
|
+
class Color(Tuple):
|
|
6
|
+
r = g = b = ...; a = 0xff
|
|
7
|
+
|
|
8
|
+
@staticmethod
|
|
9
|
+
def gray(c):
|
|
10
|
+
return Color(c, c, c)
|
|
11
|
+
|
|
12
|
+
def set_a(m, a):
|
|
13
|
+
return Color(m.r, m.g, m.b, a)
|
|
14
|
+
|
|
15
|
+
class PixelFormat(Enum):
|
|
16
|
+
rgba8 = "RGBA"
|
|
17
|
+
bgra8 = ("RGBA", "BGRA")
|
|
18
|
+
rgb8 = "RGB"
|
|
19
|
+
i8 = "P"
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def _pil_fmt(m):
|
|
23
|
+
return m.value[0] if isinstance(m.value, tuple) else m.value
|
|
24
|
+
@property
|
|
25
|
+
def _pil_raw_fmt(m):
|
|
26
|
+
return m.value[1] if isinstance(m.value, tuple) else m.value
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def bpp(m):
|
|
30
|
+
if m == m.i8:
|
|
31
|
+
return 8
|
|
32
|
+
else:
|
|
33
|
+
return 32
|
|
34
|
+
|
|
35
|
+
def _to_pil_tuple(obj):
|
|
36
|
+
if obj is None:
|
|
37
|
+
return None
|
|
38
|
+
elif len(obj) == 2:
|
|
39
|
+
return tuple(obj)
|
|
40
|
+
elif len(obj) == 4:
|
|
41
|
+
x, y, w, h = obj
|
|
42
|
+
return x, y, x + w, y + h
|
|
43
|
+
else:
|
|
44
|
+
fail(obj)
|
|
45
|
+
|
|
46
|
+
def _pil_module():
|
|
47
|
+
try:
|
|
48
|
+
from PIL import Image # type: ignore
|
|
49
|
+
except ImportError:
|
|
50
|
+
throw("ERROR: You need pillow (or PIL) to read/write PNGs (do 'python -m pip install pillow')")
|
|
51
|
+
return Image
|
|
52
|
+
|
|
53
|
+
class Surface:
|
|
54
|
+
@staticmethod
|
|
55
|
+
def load(f, fmt=None):
|
|
56
|
+
surf = Surface(_pil_module().open(f))
|
|
57
|
+
if e(fmt) and surf.format != fmt:
|
|
58
|
+
surf = surf.convert(fmt)
|
|
59
|
+
return surf
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def create(w, h, fmt=PixelFormat.rgba8):
|
|
63
|
+
return Surface(_pil_module().new(fmt._pil_fmt, (w, h)), fmt)
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def from_data(w, h, fmt, data, pitch=None):
|
|
67
|
+
return Surface(_pil_module().frombytes(fmt._pil_fmt, (w, h), data, "raw", fmt._pil_raw_fmt, pitch or 0), fmt)
|
|
68
|
+
|
|
69
|
+
def __init__(m, pil, fmt=None):
|
|
70
|
+
m.pil = pil
|
|
71
|
+
m.fmt = fmt
|
|
72
|
+
|
|
73
|
+
def to_data(m, fmt=None, flip=False):
|
|
74
|
+
if fmt is None:
|
|
75
|
+
fmt = m.format
|
|
76
|
+
return m.pil.tobytes("raw", fmt._pil_raw_fmt, 0, -1 if flip else 1)
|
|
77
|
+
|
|
78
|
+
def save(m, dest=None, format="png", **format_opts):
|
|
79
|
+
if dest is None:
|
|
80
|
+
dest = BytesIO()
|
|
81
|
+
m.save(dest, format, **format_opts)
|
|
82
|
+
return dest.getvalue()
|
|
83
|
+
|
|
84
|
+
m.pil.save(dest, format, **format_opts)
|
|
85
|
+
|
|
86
|
+
def convert(m, fmt):
|
|
87
|
+
return Surface(m.pil.convert(fmt._pil_fmt))
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def width(m):
|
|
91
|
+
return m.pil.width
|
|
92
|
+
@property
|
|
93
|
+
def height(m):
|
|
94
|
+
return m.pil.height
|
|
95
|
+
@property
|
|
96
|
+
def size(m):
|
|
97
|
+
return Point(m.width, m.height)
|
|
98
|
+
|
|
99
|
+
def resize(m, size):
|
|
100
|
+
return Surface(m.pil.resize(size, _pil_module().NEAREST))
|
|
101
|
+
def scale(m, factor):
|
|
102
|
+
return m.resize(m.size * factor)
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def alpha(m):
|
|
106
|
+
return Surface(m.pil.getchannel('A'))
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def format(m):
|
|
110
|
+
if m.fmt is None:
|
|
111
|
+
m.fmt = PixelFormat(m.pil.mode)
|
|
112
|
+
return m.fmt
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def pixels(m):
|
|
116
|
+
return m.pil.load()
|
|
117
|
+
|
|
118
|
+
def copy(m):
|
|
119
|
+
return Surface(m.pil.copy())
|
|
120
|
+
|
|
121
|
+
def slice(m, rect):
|
|
122
|
+
return Surface(m.pil.crop(_to_pil_tuple(rect)))
|
|
123
|
+
|
|
124
|
+
def draw(m, src, dest=None, srcrect=None):
|
|
125
|
+
src = src.pil.crop(_to_pil_tuple(srcrect)) if e(srcrect) else src.pil
|
|
126
|
+
m.pil.alpha_composite(src, _to_pil_tuple(dest))
|
|
127
|
+
|
|
128
|
+
def fill(m, color, dest=None, mask=None):
|
|
129
|
+
m.pil.paste(color, _to_pil_tuple(dest), mask.pil if mask else None)
|
|
130
|
+
|
|
131
|
+
@writeonly_property
|
|
132
|
+
def palette(m, pal):
|
|
133
|
+
m.pil.putpalette(pal.raw, "RGBA")
|
|
134
|
+
|
|
135
|
+
class Palette: # (pil's ImagePalette doesn't seem fit for purpose)
|
|
136
|
+
@staticmethod
|
|
137
|
+
def create(n):
|
|
138
|
+
return Palette([0] * (4 * n))
|
|
139
|
+
|
|
140
|
+
def __init__(m, raw):
|
|
141
|
+
m.raw = raw
|
|
142
|
+
|
|
143
|
+
def __len__(m):
|
|
144
|
+
return len(m.raw) // 4
|
|
145
|
+
|
|
146
|
+
def __getitem__(m, i):
|
|
147
|
+
return m.raw[4 * i : 4 * (i + 1)]
|
|
148
|
+
|
|
149
|
+
def __setitem__(m, i, v):
|
|
150
|
+
m.raw[4 * i : 4 * (i + 1)] = v
|
|
151
|
+
|
|
152
|
+
def to_surface(m):
|
|
153
|
+
return Surface.from_data(len(m), 1, PixelFormat.rgba8, bytes(m.raw))
|