mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
Optimize memory consumption of swizzled textures
This commit is contained in:
parent
4e991d85fb
commit
1fc504e587
@ -92,7 +92,18 @@ namespace AssetStudio
|
||||
reader.GetData(buff);
|
||||
if (switchSwizzled)
|
||||
{
|
||||
buff = Texture2DSwitchDeswizzler.Unswizzle(buff, GetUncroppedSize(), blockSize, gobsPerBlock);
|
||||
var unswizzledData = BigArrayPool<byte>.Shared.Rent(reader.Size);
|
||||
try
|
||||
{
|
||||
Texture2DSwitchDeswizzler.Unswizzle(buff, GetUncroppedSize(), blockSize, gobsPerBlock, unswizzledData);
|
||||
BigArrayPool<byte>.Shared.Return(buff, clearArray: true);
|
||||
buff = unswizzledData;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BigArrayPool<byte>.Shared.Return(unswizzledData, clearArray: true);
|
||||
Logger.Error(e.Message, e);
|
||||
}
|
||||
}
|
||||
|
||||
switch (m_TextureFormat)
|
||||
|
@ -43,10 +43,8 @@ namespace AssetStudio
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
internal static byte[] Unswizzle(byte[] data, Size imageSize, Size blockSize, int gobsPerBlock)
|
||||
internal static void Unswizzle(byte[] data, Size imageSize, Size blockSize, int gobsPerBlock, byte[] newData)
|
||||
{
|
||||
byte[] newData = new byte[data.Length];
|
||||
|
||||
int width = imageSize.Width;
|
||||
int height = imageSize.Height;
|
||||
|
||||
@ -71,14 +69,13 @@ namespace AssetStudio
|
||||
int gobDstY = (i * gobsPerBlock + k) * GOB_Y_TEXEL_COUNT + gobY;
|
||||
int gobDstLinPos = gobDstY * blockCountX * TEXEL_BYTE_SIZE + gobDstX * TEXEL_BYTE_SIZE;
|
||||
|
||||
Array.Copy(data, srcPos, newData, gobDstLinPos, TEXEL_BYTE_SIZE);
|
||||
Buffer.BlockCopy(data, srcPos, newData, gobDstLinPos, TEXEL_BYTE_SIZE);
|
||||
|
||||
srcPos += TEXEL_BYTE_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return newData;
|
||||
}
|
||||
|
||||
//this should be the amount of pixels that can fit 16 bytes
|
||||
|
Loading…
Reference in New Issue
Block a user