@@ -134,6 +134,9 @@ class GfxMatWriteMethod(enum.Enum):
134134}
135135
136136
137+ EMU64_SWIZZLE_SIZES = {"G_IM_SIZ_4b" : (8 , 8 ), "G_IM_SIZ_8b" : (8 , 4 ), "G_IM_SIZ_16b" : (4 , 4 ), "G_IM_SIZ_32b" : (2 , 2 )}
138+
139+
137140def isUcodeF3DEX1 (F3D_VER : str ) -> bool :
138141 return F3D_VER in {"F3DLP.Rej" , "F3DLX.Rej" , "F3DEX/LX" }
139142
@@ -3311,16 +3314,16 @@ class FImage:
33113314 width : int
33123315 height : int
33133316 filename : str
3314- data : bytearray = field (init = False , compare = False , default_factory = bytearray )
3317+ data : np . ndarray = field (init = False , compare = False , default = np . ndarray ([]) )
33153318 startAddress : int = field (init = False , compare = False , default = 0 )
33163319 isLargeTexture : bool = field (init = False , compare = False , default = False )
33173320 converted : bool = field (init = False , compare = False , default = False )
33183321
33193322 def size (self ):
3320- return len ( self .data )
3323+ return self .data . size * self . data . itemsize
33213324
33223325 def to_binary (self ):
3323- return self .data
3326+ return self .data . astype ( self . data . dtype . newbyteorder ( ">" )). tobytes ()
33243327
33253328 def to_c (self , texArrayBitSize , f3d ):
33263329 return self .to_c_helper (self .to_c_data (texArrayBitSize ), texArrayBitSize , f3d )
@@ -3342,38 +3345,14 @@ def to_c_helper(self, texData, bitsPerValue, f3d):
33423345 code .source += "\n };\n \n "
33433346 return code
33443347
3345- def to_c_data (self , bitsPerValue ):
3348+ def to_c_data (self , bits_per_val : int ):
33463349 if not self .converted :
33473350 raise PluginError (
33483351 "Error: Trying to write texture data to C, but haven't actually converted the image file to bytes yet."
33493352 )
3350-
3351- bytesPerValue = int (bitsPerValue / 8 )
3352- numValues = int (len (self .data ) / bytesPerValue )
3353- remainderCount = len (self .data ) - numValues * bytesPerValue
3354- digits = 2 + 2 * bytesPerValue
3355-
3356- code = "" .join (
3357- [
3358- format (
3359- int .from_bytes (self .data [i * bytesPerValue : (i + 1 ) * bytesPerValue ], "big" ),
3360- "#0" + str (digits ) + "x" ,
3361- )
3362- + ", "
3363- + ("\n \t " if i % 8 == 7 else "" )
3364- for i in range (numValues )
3365- ]
3366- )
3367-
3368- if remainderCount > 0 :
3369- start = numValues * bytesPerValue
3370- end = (numValues + 1 ) * bytesPerValue
3371- code += format (
3372- int .from_bytes (self .data [start :end ], "big" ) << (8 * (bytesPerValue - remainderCount )),
3373- "#0" + str (digits ) + "x" ,
3374- )
3375-
3376- return code
3353+ data = self .data .astype (dtype = self .data .dtype .newbyteorder (">" ))
3354+ hex_str = data .tobytes ().hex (":" , bits_per_val // 8 ).split (":" )
3355+ return "" .join ([f"0x{ s } , " + ("\n \t " if i % 8 == 7 else "" ) for i , s in enumerate (hex_str )])
33773356
33783357 def set_addr (self , startAddress ):
33793358 startAddress = get64bitAlignedAddr (startAddress )
0 commit comments