@@ -219,14 +219,9 @@ def image_to_texture2d(
219219 tex_format = TF .RGB24
220220 pil_mode = "RGB"
221221 # 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
230225
231226 if TextureSwizzler .is_switch_swizzled (platform , platform_blob ):
232227 if TYPE_CHECKING :
@@ -244,11 +239,22 @@ def image_to_texture2d(
244239 width , height = TextureSwizzler .get_padded_texture_size (
245240 img .width , img .height , * block_size , gobsPerBlock
246241 )
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 :
249252 img = pad_image (img , width , height )
250- enc_img = img .tobytes ("raw" , pil_mode )
251253
254+ enc_img = img .tobytes ("raw" , pil_mode )
255+
256+ if switch_info is not None :
257+ block_size , gobsPerBlock = switch_info
252258 enc_img = bytes (
253259 TextureSwizzler .swizzle (enc_img , width , height , * block_size , gobsPerBlock )
254260 )
0 commit comments