@@ -219,14 +219,9 @@ def image_to_texture2d(
219
219
tex_format = TF .RGB24
220
220
pil_mode = "RGB"
221
221
# everything else defaulted to RGBA
222
- if compress_func :
223
- width , height = get_compressed_image_size (img .width , img .height , tex_format )
224
- img = pad_image (img , width , height )
225
- enc_img = compress_func (
226
- img .tobytes ("raw" , "RGBA" ), img .width , img .height , tex_format
227
- )
228
- else :
229
- enc_img = img .tobytes ("raw" , pil_mode )
222
+
223
+ width , height = img .width , img .height
224
+ switch_info = None
230
225
231
226
if TextureSwizzler .is_switch_swizzled (platform , platform_blob ):
232
227
if TYPE_CHECKING :
@@ -244,11 +239,22 @@ def image_to_texture2d(
244
239
width , height = TextureSwizzler .get_padded_texture_size (
245
240
img .width , img .height , * block_size , gobsPerBlock
246
241
)
247
- if not compress_func :
248
- # recompress with padding and corrected image mode
242
+ switch_info = (block_size , gobsPerBlock )
243
+
244
+ if compress_func :
245
+ width , height = get_compressed_image_size (width , height , tex_format )
246
+ img = pad_image (img , width , height )
247
+ enc_img = compress_func (
248
+ img .tobytes ("raw" , "RGBA" ), img .width , img .height , tex_format
249
+ )
250
+ else :
251
+ if switch_info is not None :
249
252
img = pad_image (img , width , height )
250
- enc_img = img .tobytes ("raw" , pil_mode )
251
253
254
+ enc_img = img .tobytes ("raw" , pil_mode )
255
+
256
+ if switch_info is not None :
257
+ block_size , gobsPerBlock = switch_info
252
258
enc_img = bytes (
253
259
TextureSwizzler .swizzle (enc_img , width , height , * block_size , gobsPerBlock )
254
260
)
0 commit comments