@@ -84,10 +84,11 @@ def squash(self, ratio):
8484
8585
8686class CustomCropMixin :
87- def __init__ (self , * args , fixed_crop = False , crop_amount = (0 , 0 ), ** kw ):
87+ def __init__ (self , * args , fixed_crop = False , crop_amount = (0 , 0 ), keep_br_space = False , ** kw ):
8888 super ().__init__ (* args , ** kw )
8989 self .fixed_crop = fixed_crop
9090 self .crop_amount = crop_amount
91+ self .keep_br_space = keep_br_space
9192 if fixed_crop :
9293 assert crop_amount [0 ] <= self .h
9394 assert crop_amount [1 ] <= self .w
@@ -98,23 +99,27 @@ def _do_crop(self, context, w, h, rgb, alpha, mask):
9899 crop_x , crop_y = self .crop_amount
99100
100101 timer = context .start_timer ()
101- if alpha is not None :
102- cols_bitset = alpha .any (0 )
103- rows_bitset = alpha .any (1 )
104- elif rgb is not None :
105- cols_bitset = rgb .any ((0 , 2 ))
106- rows_bitset = rgb .any ((1 , 2 ))
107- elif mask is not None :
108- cols_bitset = mask .any (0 )
109- rows_bitset = mask .any (1 )
110- else :
111- raise context .failure (self , "All data layers are None" )
112-
113- cols_used = np .arange (w )[cols_bitset ]
114- rows_used = np .arange (h )[rows_bitset ]
115102
116- w = max (cols_used , default = 0 ) - crop_x + 1
117- h = max (rows_used , default = 0 ) - crop_y + 1
103+ if self .keep_br_space :
104+ w = rgb .shape [1 ] - crop_x
105+ h = rgb .shape [0 ] - crop_y
106+ else :
107+ if alpha is not None :
108+ cols_bitset = alpha .any (0 )
109+ rows_bitset = alpha .any (1 )
110+ elif rgb is not None :
111+ cols_bitset = rgb .any ((0 , 2 ))
112+ rows_bitset = rgb .any ((1 , 2 ))
113+ elif mask is not None :
114+ cols_bitset = mask .any (0 )
115+ rows_bitset = mask .any (1 )
116+ else :
117+ raise context .failure (self , "All data layers are None" )
118+ cols_used = np .arange (w )[cols_bitset ]
119+ rows_used = np .arange (h )[rows_bitset ]
120+
121+ w = max (cols_used , default = 0 ) - crop_x + 1
122+ h = max (rows_used , default = 0 ) - crop_y + 1
118123
119124 if w <= 0 or h <= 0 :
120125 w = h = 1
@@ -163,6 +168,7 @@ def spritesheet_template(
163168 shift = 0 ,
164169 mode = "vehicle" ,
165170 manual_crop = None ,
171+ keep_br_space = False ,
166172 childsprite = False ,
167173 relative_childsprite = False ,
168174 nomask = False ,
@@ -229,7 +235,13 @@ def get_rels(direction, scale):
229235 def with_optional_mask (sprite , mask ):
230236 if mask is None :
231237 return sprite
232- return CustomCropWithMask (sprite , mask , fixed_crop = sprite .fixed_crop , crop_amount = sprite .crop_amount )
238+ return CustomCropWithMask (
239+ sprite ,
240+ mask ,
241+ fixed_crop = sprite .fixed_crop ,
242+ crop_amount = sprite .crop_amount ,
243+ keep_br_space = sprite .keep_br_space ,
244+ )
233245
234246 return [
235247 LazyAlternativeSprites (
@@ -256,6 +268,7 @@ def with_optional_mask(sprite, mask):
256268 ),
257269 bpp = bpp ,
258270 zoom = SCALE_TO_ZOOM [scale ],
271+ keep_br_space = keep_br_space ,
259272 ** (
260273 {}
261274 if manual_crop is None
0 commit comments