@@ -148,15 +148,15 @@ def image_to_texture2d(
148
148
149
149
# defaults
150
150
compress_func = None
151
- tex_format = TF .RGBA32
151
+ texture_format = TF .RGBA32
152
152
pil_mode = "RGBA"
153
153
154
154
# DXT / BC
155
155
if target_texture_format in [TF .DXT1 , TF .DXT1Crunched ]:
156
- tex_format = TF .DXT1
156
+ texture_format = TF .DXT1
157
157
compress_func = compress_etcpak
158
158
elif target_texture_format in [TF .DXT5 , TF .DXT5Crunched ]:
159
- tex_format = TF .DXT5
159
+ texture_format = TF .DXT5
160
160
compress_func = compress_etcpak
161
161
elif target_texture_format in [TF .BC4 , TF .BC5 , TF .BC7 ]:
162
162
compress_func = compress_etcpak
@@ -166,28 +166,32 @@ def image_to_texture2d(
166
166
block_size = TEXTURE_FORMAT_BLOCK_SIZE_TABLE [target_texture_format ]
167
167
assert block_size is not None
168
168
if img .mode == "RGB" :
169
- tex_format = getattr (TF , f"ASTC_RGB_{ block_size [0 ]} x{ block_size [1 ]} " )
169
+ texture_format = getattr (
170
+ TF , f"ASTC_RGB_{ block_size [0 ]} x{ block_size [1 ]} "
171
+ )
170
172
else :
171
- tex_format = getattr (TF , f"ASTC_RGBA_{ block_size [0 ]} x{ block_size [1 ]} " )
173
+ texture_format = getattr (
174
+ TF , f"ASTC_RGBA_{ block_size [0 ]} x{ block_size [1 ]} "
175
+ )
172
176
else :
173
- tex_format = target_texture_format
177
+ texture_format = target_texture_format
174
178
compress_func = compress_astc
175
179
# ETC
176
180
elif target_texture_format in [TF .ETC_RGB4 , TF .ETC_RGB4Crunched , TF .ETC_RGB4_3DS ]:
177
181
if target_texture_format == TF .ETC_RGB4_3DS :
178
- tex_format = TF .ETC_RGB4_3DS
182
+ texture_format = TF .ETC_RGB4_3DS
179
183
else :
180
- tex_format = target_texture_format
184
+ texture_format = target_texture_format
181
185
compress_func = compress_etcpak
182
186
elif target_texture_format == TF .ETC2_RGB :
183
- tex_format = TF .ETC2_RGB
187
+ texture_format = TF .ETC2_RGB
184
188
compress_func = compress_etcpak
185
189
elif target_texture_format in [TF .ETC2_RGBA8 , TF .ETC2_RGBA8Crunched , TF .ETC2_RGBA1 ]:
186
- tex_format = TF .ETC2_RGBA8
190
+ texture_format = TF .ETC2_RGBA8
187
191
compress_func = compress_etcpak
188
192
# L
189
193
elif target_texture_format == TF .Alpha8 :
190
- tex_format = TF .Alpha8
194
+ texture_format = TF .Alpha8
191
195
pil_mode = "L"
192
196
# R - should probably be merged into #L, as pure R is used as Alpha
193
197
# but need test data for this first
@@ -199,7 +203,7 @@ def image_to_texture2d(
199
203
TF .EAC_R ,
200
204
TF .EAC_R_SIGNED ,
201
205
]:
202
- tex_format = TF .R8
206
+ texture_format = TF .R8
203
207
pil_mode = "R"
204
208
# RGBA
205
209
elif target_texture_format in [
@@ -211,49 +215,47 @@ def image_to_texture2d(
211
215
TF .PVRTC_RGB4 ,
212
216
TF .ATC_RGB4 ,
213
217
]:
214
- tex_format = TF .RGB24
218
+ texture_format = TF .RGB24
215
219
pil_mode = "RGB"
216
220
# everything else defaulted to RGBA
217
221
218
222
switch_swizzle = None
219
223
if platform == BuildTarget .Switch and platform_blob :
220
224
gobs_per_block = TextureSwizzler .get_switch_gobs_per_block (platform_blob )
221
225
222
- if tex_format == TextureFormat .RGB24 :
223
- tex_format = TextureFormat .RGBA32
226
+ if texture_format == TF .RGB24 :
227
+ texture_format = TF .RGBA32
224
228
pil_mode = "RGBA"
225
- elif tex_format == TextureFormat .BGR24 :
226
- tex_format = TextureFormat .BGRA32
229
+ elif texture_format == TF .BGR24 :
230
+ texture_format = TF .BGRA32
227
231
pil_mode = "BGRA"
228
232
229
- block_size = TextureSwizzler .TEXTUREFORMAT_BLOCK_SIZE_MAP .get (tex_format )
233
+ block_size = TextureSwizzler .TEXTUREFORMAT_BLOCK_SIZE_MAP .get (texture_format )
230
234
if not block_size :
231
235
raise NotImplementedError (
232
- f"Not implemented swizzle format: { tex_format .name } "
236
+ f"Not implemented swizzle format: { texture_format .name } "
233
237
)
234
238
235
239
width , height = TextureSwizzler .get_padded_texture_size (
236
240
img .width , img .height , * block_size , gobs_per_block
237
241
)
238
242
switch_swizzle = (block_size , gobs_per_block )
239
243
else :
240
- width , height = get_compressed_image_size (img .width , img .height , tex_format )
244
+ width , height = get_compressed_image_size (img .width , img .height , texture_format )
241
245
242
246
img = pad_image (img , width , height )
243
247
if compress_func :
244
248
enc_img = compress_func (
245
- img .tobytes ("raw" , pil_mode ), img .width , img .height , tex_format
249
+ img .tobytes ("raw" , pil_mode ), img .width , img .height , texture_format
246
250
)
247
251
else :
248
252
enc_img = img .tobytes ("raw" , pil_mode )
249
253
250
254
if switch_swizzle is not None :
251
255
block_size , gobs_per_block = switch_swizzle
252
- enc_img = bytes (
253
- TextureSwizzler .swizzle (enc_img , width , height , * block_size , gobs_per_block )
254
- )
256
+ enc_img = TextureSwizzler .swizzle (enc_img , width , height , * block_size , gobs_per_block )
255
257
256
- return enc_img , tex_format
258
+ return enc_img , texture_format
257
259
258
260
259
261
def assert_rgba (img : Image .Image , target_texture_format : TextureFormat ) -> Image .Image :
@@ -320,12 +322,12 @@ def parse_image_data(
320
322
gobs_per_block = TextureSwizzler .get_switch_gobs_per_block (platform_blob )
321
323
322
324
pil_mode = "RGBA"
323
- if texture_format == TextureFormat .RGB24 :
324
- texture_format = TextureFormat .RGBA32
325
- elif texture_format == TextureFormat .BGR24 :
326
- texture_format = TextureFormat .BGRA32
325
+ if texture_format == TF .RGB24 :
326
+ texture_format = TF .RGBA32
327
+ elif texture_format == TF .BGR24 :
328
+ texture_format = TF .BGRA32
327
329
pil_mode = "BGRA"
328
- elif texture_format == TextureFormat .Alpha8 :
330
+ elif texture_format == TF .Alpha8 :
329
331
texture_format = texture_format
330
332
pil_mode = "L"
331
333
@@ -355,11 +357,8 @@ def parse_image_data(
355
357
356
358
if switch_swizzle is not None :
357
359
block_size , gobs_per_block , pil_mode = switch_swizzle
358
- image_data = bytes (
359
- TextureSwizzler .deswizzle (
360
- image_data , width , height , * block_size , gobs_per_block
361
- )
362
- )
360
+ image_data = TextureSwizzler .deswizzle (image_data , width , height , * block_size , gobs_per_block )
361
+
363
362
364
363
conv_func = CONV_TABLE .get (texture_format )
365
364
if not conv_func :
@@ -555,11 +554,15 @@ def rgb9e5float(image_data: bytes, width: int, height: int) -> Image.Image:
555
554
556
555
CONV_TABLE : Dict [TextureFormat , Callable [[bytes , int , int ], Image .Image ]] = {
557
556
TF .Alpha8 : lambda data , w , h : pillow (data , w , h , "L" , "raw" , "L" ),
558
- TF .ARGB4444 : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "RGBA;4B" , (2 , 1 , 0 , 3 )),
557
+ TF .ARGB4444 : lambda data , w , h : pillow (
558
+ data , w , h , "RGBA" , "raw" , "RGBA;4B" , (2 , 1 , 0 , 3 )
559
+ ),
559
560
TF .RGB24 : lambda data , w , h : pillow (data , w , h , "RGB" , "raw" , "RGB" ),
560
561
TF .RGBA32 : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "RGBA" ),
561
562
TF .ARGB32 : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "ARGB" ),
562
- TF .ARGBFloat : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "RGBAF" , (2 , 1 , 0 , 3 )),
563
+ TF .ARGBFloat : lambda data , w , h : pillow (
564
+ data , w , h , "RGBA" , "raw" , "RGBAF" , (2 , 1 , 0 , 3 )
565
+ ),
563
566
TF .RGB565 : lambda data , w , h : pillow (data , w , h , "RGB" , "raw" , "BGR;16" ),
564
567
TF .BGR24 : lambda data , w , h : pillow (data , w , h , "RGB" , "raw" , "BGR" ),
565
568
TF .R8 : lambda data , w , h : pillow (data , w , h , "RGB" , "raw" , "R" ),
@@ -568,7 +571,9 @@ def rgb9e5float(image_data: bytes, width: int, height: int) -> Image.Image:
568
571
TF .DXT1 : lambda data , w , h : pillow (data , w , h , "RGBA" , "bcn" , 1 ),
569
572
TF .DXT3 : lambda data , w , h : pillow (data , w , h , "RGBA" , "bcn" , 2 ),
570
573
TF .DXT5 : lambda data , w , h : pillow (data , w , h , "RGBA" , "bcn" , 3 ),
571
- TF .RGBA4444 : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "RGBA;4B" , (3 , 2 , 1 , 0 )),
574
+ TF .RGBA4444 : lambda data , w , h : pillow (
575
+ data , w , h , "RGBA" , "raw" , "RGBA;4B" , (3 , 2 , 1 , 0 )
576
+ ),
572
577
TF .BGRA32 : lambda data , w , h : pillow (data , w , h , "RGBA" , "raw" , "BGRA" ),
573
578
TF .RHalf : lambda data , w , h : half (data , w , h , "R" , "raw" , "R" ),
574
579
TF .RGHalf : lambda data , w , h : rg (data , w , h , "RGB" , "raw" , "RGE" ),
0 commit comments