comparison tools/images.py @ 6:910b26feca76

full game flow
author ark
date 2026-10-19 01:05 +0200
parents 5492efd60e2c
children
comparison
equal deleted inserted replaced
5:67bf3c505145 6:910b26feca76
27 def darken(im, factor): 27 def darken(im, factor):
28 """return a copy with the colour scaled by factor, alpha unchanged.""" 28 """return a copy with the colour scaled by factor, alpha unchanged."""
29 r, g, b, a = im.split() 29 r, g, b, a = im.split()
30 r, g, b = (c.point(lambda v: int(v * factor)) for c in (r, g, b)) 30 r, g, b = (c.point(lambda v: int(v * factor)) for c in (r, g, b))
31 return Image.merge("RGBA", (r, g, b, a)) 31 return Image.merge("RGBA", (r, g, b, a))
32
33
34 def recolour(im, hue):
35 """
36 return a copy with every pixel's hue set to hue (degrees), saturation,
37 brightness and alpha unchanged. grey and black pixels stay as they are.
38 """
39 a = im.getchannel("A")
40 h, s, v = im.convert("RGB").convert("HSV").split()
41 h = h.point(lambda _: round(hue / 360 * 255))
42 out = Image.merge("HSV", (h, s, v)).convert("RGBA")
43 out.putalpha(a)
44 return out
32 45
33 46
34 def split_strip(im): 47 def split_strip(im):
35 """ 48 """
36 split a strip of drawings side by side at columns without pencil. 49 split a strip of drawings side by side at columns without pencil.