mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
Rewrite wrapper dll
This commit is contained in:
parent
c2f7f0a92d
commit
5688f03869
@ -84,10 +84,10 @@ namespace Unity_Studio
|
|||||||
public QFORMAT q_format;
|
public QFORMAT q_format;
|
||||||
|
|
||||||
[DllImport("PVRTexLibWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PVRTexLibWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void DecompressPVR(byte[] buffer, IntPtr bmp, int len);
|
private static extern bool DecompressPVR(byte[] buffer, IntPtr bmp, int len);
|
||||||
|
|
||||||
[DllImport("TextureConverterWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("TextureConverterWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type);
|
private static extern bool Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type, int bmpsize, bool fixAlpha);
|
||||||
|
|
||||||
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
||||||
{
|
{
|
||||||
@ -988,7 +988,12 @@ namespace Unity_Studio
|
|||||||
var rect = new Rectangle(0, 0, m_Width, m_Height);
|
var rect = new Rectangle(0, 0, m_Width, m_Height);
|
||||||
var bmd = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
var bmd = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||||
var len = Math.Abs(bmd.Stride) * bmd.Height;
|
var len = Math.Abs(bmd.Stride) * bmd.Height;
|
||||||
DecompressPVR(pvrdata, bmd.Scan0, len);
|
if (!DecompressPVR(pvrdata, bmd.Scan0, len))
|
||||||
|
{
|
||||||
|
bitmap.UnlockBits(bmd);
|
||||||
|
bitmap.Dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
bitmap.UnlockBits(bmd);
|
bitmap.UnlockBits(bmd);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
@ -998,27 +1003,19 @@ namespace Unity_Studio
|
|||||||
var bitmap = new Bitmap(m_Width, m_Height);
|
var bitmap = new Bitmap(m_Width, m_Height);
|
||||||
var rect = new Rectangle(0, 0, m_Width, m_Height);
|
var rect = new Rectangle(0, 0, m_Width, m_Height);
|
||||||
var bmd = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
var bmd = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||||
Ponvert(image_data, bmd.Scan0, m_Width, m_Height, image_data_size, (int)q_format);
|
var len = Math.Abs(bmd.Stride) * bmd.Height;
|
||||||
|
var fixAlpha = glBaseInternalFormat == KTXHeader.GL_RED || glBaseInternalFormat == KTXHeader.GL_RG;
|
||||||
|
if (!Ponvert(image_data, bmd.Scan0, m_Width, m_Height, image_data_size, (int)q_format, len, fixAlpha))
|
||||||
|
{
|
||||||
|
bitmap.UnlockBits(bmd);
|
||||||
|
bitmap.Dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
bitmap.UnlockBits(bmd);
|
bitmap.UnlockBits(bmd);
|
||||||
if (glBaseInternalFormat == KTXHeader.GL_RED || glBaseInternalFormat == KTXHeader.GL_RG)
|
|
||||||
FixAlpha(bitmap);
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixAlpha(Bitmap imageTexture)
|
|
||||||
{
|
|
||||||
for (var y = 0; y < imageTexture.Height; y++)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < imageTexture.Width; x++)
|
|
||||||
{
|
|
||||||
var color = imageTexture.GetPixel(x, y);
|
|
||||||
color = Color.FromArgb(255, color.R, color.G, color.B);
|
|
||||||
imageTexture.SetPixel(x, y, color);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public enum TextureFormat
|
public enum TextureFormat
|
||||||
{
|
{
|
||||||
@ -1075,9 +1072,8 @@ namespace Unity_Studio
|
|||||||
ETC_RGB4_3DS,
|
ETC_RGB4_3DS,
|
||||||
ETC_RGBA8_3DS
|
ETC_RGBA8_3DS
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class KTXHeader
|
public static class KTXHeader
|
||||||
{
|
{
|
||||||
public static byte[] IDENTIFIER = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A };
|
public static byte[] IDENTIFIER = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A };
|
||||||
public static byte[] ENDIANESS_LE = new byte[] { 1, 2, 3, 4 };
|
public static byte[] ENDIANESS_LE = new byte[] { 1, 2, 3, 4 };
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user