@@ -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
3636def 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
6874def make_foundation (
0 commit comments