Skip to content

Commit f1b5698

Browse files
committed
..
1 parent 428b122 commit f1b5698

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

agrf/graphics/cv/foundation.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,45 @@ def get_left_part(left_parts, r, c, solid, scale):
3030
assert left_parts % 4 == 3
3131
left *= r * 2 - c <= 48 * scale
3232

33-
return left
33+
return left.astype(np.uint8)
3434

3535

3636
def make_foundation_subimage(
3737
img: LayeredImage, scale, left_parts, right_parts, nw, ne, y_limit, cut_inside, zshift, solid
3838
) -> LayeredImage:
39-
if img.alpha is not None:
40-
r = np.arange(img.h)[:, np.newaxis] + img.yofs + 0.5 + zshift * scale
41-
c = np.arange(img.w)[np.newaxis] + img.xofs - scale + 0.5
39+
r = np.arange(img.h)[:, np.newaxis] + img.yofs + 0.5 + zshift * scale
40+
c = np.arange(img.w)[np.newaxis] + img.xofs - scale + 0.5
4241

43-
alphamask = np.zeros((img.h, img.w), dtype=np.uint8)
44-
if left_parts is not None:
45-
alphamask = np.maximum(alphamask, get_left_part(left_parts, r, c, solid, scale))
42+
alphamask = np.zeros((img.h, img.w), dtype=np.uint8)
43+
if left_parts is not None:
44+
alphamask = np.maximum(alphamask, get_left_part(left_parts, r, c, solid, scale))
4645

47-
if right_parts is not None:
48-
alphamask = np.maximum(alphamask, get_left_part(right_parts, r, -c, solid, scale))
46+
if right_parts is not None:
47+
alphamask = np.maximum(alphamask, get_left_part(right_parts, r, -c, solid, scale))
4948

50-
if cut_inside:
51-
# FIXME
52-
pass
49+
if cut_inside:
50+
# FIXME
51+
pass
5352

54-
if nw:
55-
alphamask *= (1 - (c < 0) * (r * 2 + c <= 0 * scale) * (r * 2 - c <= 48 * scale)).astype(np.uint8)
56-
if ne:
57-
alphamask *= (1 - (c > 0) * (r * 2 - c <= 0 * scale) * (r * 2 + c <= 48 * scale)).astype(np.uint8)
53+
if nw and not solid:
54+
alphamask *= (1 - (c < 0) * (r * 2 + c <= 0 * scale) * (r * 2 - c <= 48 * scale)).astype(np.uint8)
55+
if ne and not solid:
56+
alphamask *= (1 - (c > 0) * (r * 2 - c <= 0 * scale) * (r * 2 + c <= 48 * scale)).astype(np.uint8)
5857

59-
alphamask *= (1 - (r * 2 - c > y_limit * scale) * (r * 2 + c > y_limit * scale)).astype(np.uint8)
58+
alphamask *= (1 - (r * 2 - c > y_limit * scale) * (r * 2 + c > y_limit * scale)).astype(np.uint8)
6059

61-
alpha = img.alpha * alphamask
62-
else:
60+
if img.alpha is None:
61+
assert False
6362
alpha = None
63+
assert img.mask is not None
64+
assert img.rgb is None
65+
mask = img.mask * alphamask
66+
else:
67+
alpha = img.alpha * alphamask
68+
assert img.rgb is not None
69+
mask = img.mask
6470

65-
return LayeredImage(xofs=img.xofs, yofs=img.yofs, w=img.w, h=img.h, rgb=img.rgb, alpha=alpha, mask=None)
71+
return LayeredImage(xofs=img.xofs, yofs=img.yofs, w=img.w, h=img.h, rgb=img.rgb, alpha=alpha, mask=mask)
6672

6773

6874
def make_foundation(

agrf/lib/building/foundation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def make_foundations_subset(self, subset):
130130
l, r, y_limit = self.get_sprite_conf(style, i)
131131
alts = []
132132
for scale in [1, 2, 4]:
133-
for bpp in [32]:
133+
for bpp in [8, 32]:
134134
if self.solid is not None:
135135
s = self.solid.get_sprite(zoom=SCALE_TO_ZOOM[scale], bpp=bpp)
136136
else:
@@ -155,6 +155,8 @@ def make_foundations_subset(self, subset):
155155
)
156156
alts.append(fs)
157157

158+
assert len(alts) > 0
159+
158160
alt_sprite = grf.AlternativeSprites(*alts)
159161
if self.debug_number != -1:
160162
alt_sprite = number_alternatives(alt_sprite, self.debug_number)

0 commit comments

Comments
 (0)