Fixed ASTC Decoding

This commit is contained in:
Perfare 2019-04-04 21:05:44 +08:00
parent 558adb0b66
commit e1bb9a6cf0
4 changed files with 46 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -67,6 +67,9 @@ namespace AssetStudio
private QFORMAT q_format;
//texgenpack
private texgenpack_texturetype texturetype;
//astc
private int astcBlockWidth;
private int astcBlockHeight;
[DllImport("PVRTexLibWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern bool DecompressPVR(byte[] buffer, IntPtr bmp, int len);
@ -83,6 +86,8 @@ namespace AssetStudio
[DllImport("texgenpack.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void Decode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp);
[DllImport("astc.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern bool decode_astc(byte[] data, int width, int height, int blockwidth, int blockheight, IntPtr bmp);
public Texture2DConverter(Texture2D m_Texture2D)
{
@ -514,37 +519,43 @@ namespace AssetStudio
case TextureFormat.ASTC_RGB_4x4: //test pass
case TextureFormat.ASTC_RGBA_4x4: //test pass
{
pvrPixelFormat = 27;
astcBlockWidth = 4;
astcBlockHeight = 4;
break;
}
case TextureFormat.ASTC_RGB_5x5: //test pass
case TextureFormat.ASTC_RGBA_5x5: //test pass
{
pvrPixelFormat = 29;
astcBlockWidth = 5;
astcBlockHeight = 5;
break;
}
case TextureFormat.ASTC_RGB_6x6: //test pass
case TextureFormat.ASTC_RGBA_6x6: //test pass
{
pvrPixelFormat = 31;
astcBlockWidth = 6;
astcBlockHeight = 6;
break;
}
case TextureFormat.ASTC_RGB_8x8: //test pass
case TextureFormat.ASTC_RGBA_8x8: //test pass
{
pvrPixelFormat = 34;
astcBlockWidth = 8;
astcBlockHeight = 8;
break;
}
case TextureFormat.ASTC_RGB_10x10: //test pass
case TextureFormat.ASTC_RGBA_10x10: //test pass
{
pvrPixelFormat = 38;
astcBlockWidth = 10;
astcBlockHeight = 10;
break;
}
case TextureFormat.ASTC_RGB_12x12: //test pass
case TextureFormat.ASTC_RGBA_12x12: //test pass
{
pvrPixelFormat = 40;
astcBlockWidth = 12;
astcBlockHeight = 12;
break;
}
case TextureFormat.RG16: //test pass
@ -837,18 +848,6 @@ namespace AssetStudio
case TextureFormat.ETC2_RGB:
case TextureFormat.ETC2_RGBA1:
case TextureFormat.ETC2_RGBA8:
case TextureFormat.ASTC_RGB_4x4:
case TextureFormat.ASTC_RGB_5x5:
case TextureFormat.ASTC_RGB_6x6:
case TextureFormat.ASTC_RGB_8x8:
case TextureFormat.ASTC_RGB_10x10:
case TextureFormat.ASTC_RGB_12x12:
case TextureFormat.ASTC_RGBA_4x4:
case TextureFormat.ASTC_RGBA_5x5:
case TextureFormat.ASTC_RGBA_6x6:
case TextureFormat.ASTC_RGBA_8x8:
case TextureFormat.ASTC_RGBA_10x10:
case TextureFormat.ASTC_RGBA_12x12:
case TextureFormat.ETC_RGB4_3DS:
case TextureFormat.ETC_RGBA8_3DS:
bitmap = PVRToBitmap(ConvertToPVR());
@ -886,6 +885,20 @@ namespace AssetStudio
DecompressCRN();
bitmap = PVRToBitmap(ConvertToPVR());
break;
case TextureFormat.ASTC_RGB_4x4:
case TextureFormat.ASTC_RGB_5x5:
case TextureFormat.ASTC_RGB_6x6:
case TextureFormat.ASTC_RGB_8x8:
case TextureFormat.ASTC_RGB_10x10:
case TextureFormat.ASTC_RGB_12x12:
case TextureFormat.ASTC_RGBA_4x4:
case TextureFormat.ASTC_RGBA_5x5:
case TextureFormat.ASTC_RGBA_6x6:
case TextureFormat.ASTC_RGBA_8x8:
case TextureFormat.ASTC_RGBA_10x10:
case TextureFormat.ASTC_RGBA_12x12:
bitmap = DecodeASTC();
break;
default:
return null;
}
@ -997,6 +1010,21 @@ namespace AssetStudio
bitmap.UnlockBits(bmd);
return bitmap;
}
private Bitmap DecodeASTC()
{
var bitmap = new Bitmap(m_Width, m_Height);
var rect = new Rectangle(0, 0, m_Width, m_Height);
var bmd = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
if (!decode_astc(image_data, m_Width, m_Height, astcBlockWidth, astcBlockHeight, bmd.Scan0))
{
bitmap.UnlockBits(bmd);
bitmap.Dispose();
return null;
}
bitmap.UnlockBits(bmd);
return bitmap;
}
}
public static class KTXHeader