mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
Add crunch and texgenpack
This commit is contained in:
parent
5688f03869
commit
256eeb8f7c
@ -35,53 +35,55 @@ namespace Unity_Studio
|
|||||||
public string path;
|
public string path;
|
||||||
|
|
||||||
//DDS Start
|
//DDS Start
|
||||||
public byte[] dwMagic = { 0x44, 0x44, 0x53, 0x20, 0x7c };
|
private byte[] dwMagic = { 0x44, 0x44, 0x53, 0x20, 0x7c };
|
||||||
public int dwFlags = 0x1 + 0x2 + 0x4 + 0x1000;
|
private int dwFlags = 0x1 + 0x2 + 0x4 + 0x1000;
|
||||||
//public int dwHeight; m_Height
|
//public int dwHeight; m_Height
|
||||||
//public int dwWidth; m_Width
|
//public int dwWidth; m_Width
|
||||||
public int dwPitchOrLinearSize = 0x0;
|
private int dwPitchOrLinearSize = 0x0;
|
||||||
public int dwMipMapCount = 0x1;
|
private int dwMipMapCount = 0x1;
|
||||||
public int dwSize = 0x20;
|
private int dwSize = 0x20;
|
||||||
public int dwFlags2;
|
private int dwFlags2;
|
||||||
public int dwFourCC = 0x0;
|
private int dwFourCC = 0x0;
|
||||||
public int dwRGBBitCount;
|
private int dwRGBBitCount;
|
||||||
public int dwRBitMask;
|
private int dwRBitMask;
|
||||||
public int dwGBitMask;
|
private int dwGBitMask;
|
||||||
public int dwBBitMask;
|
private int dwBBitMask;
|
||||||
public int dwABitMask;
|
private int dwABitMask;
|
||||||
public int dwCaps = 0x1000;
|
private int dwCaps = 0x1000;
|
||||||
public int dwCaps2 = 0x0;
|
private int dwCaps2 = 0x0;
|
||||||
//DDS End
|
//DDS End
|
||||||
//PVR Start
|
//PVR Start
|
||||||
public int pvrVersion = 0x03525650;
|
private int pvrVersion = 0x03525650;
|
||||||
public int pvrFlags = 0x0;
|
private int pvrFlags = 0x0;
|
||||||
public long pvrPixelFormat;
|
private long pvrPixelFormat;
|
||||||
public int pvrColourSpace = 0x0;
|
private int pvrColourSpace = 0x0;
|
||||||
public int pvrChannelType = 0x0;
|
private int pvrChannelType = 0x0;
|
||||||
//public int pvrHeight; m_Height
|
//public int pvrHeight; m_Height
|
||||||
//public int pvrWidth; m_Width
|
//public int pvrWidth; m_Width
|
||||||
public int pvrDepth = 0x1;
|
private int pvrDepth = 0x1;
|
||||||
public int pvrNumSurfaces = 0x1; //For texture arrays
|
private int pvrNumSurfaces = 0x1; //For texture arrays
|
||||||
public int pvrNumFaces = 0x1; //For cube maps
|
private int pvrNumFaces = 0x1; //For cube maps
|
||||||
//public int pvrMIPMapCount; dwMipMapCount
|
//public int pvrMIPMapCount; dwMipMapCount
|
||||||
public int pvrMetaDataSize = 0x0;
|
private int pvrMetaDataSize = 0x0;
|
||||||
//PVR End
|
//PVR End
|
||||||
//KTX Start
|
//KTX Start
|
||||||
public int glType = 0;
|
private int glType = 0;
|
||||||
public int glTypeSize = 1;
|
private int glTypeSize = 1;
|
||||||
public int glFormat = 0;
|
private int glFormat = 0;
|
||||||
public int glInternalFormat;
|
private int glInternalFormat;
|
||||||
public int glBaseInternalFormat;
|
private int glBaseInternalFormat;
|
||||||
//public int pixelWidth; m_Width
|
//public int pixelWidth; m_Width
|
||||||
//public int pixelHeight; m_Height
|
//public int pixelHeight; m_Height
|
||||||
public int pixelDepth = 0;
|
private int pixelDepth = 0;
|
||||||
public int numberOfArrayElements = 0;
|
private int numberOfArrayElements = 0;
|
||||||
public int numberOfFaces = 1;
|
private int numberOfFaces = 1;
|
||||||
public int numberOfMipmapLevels = 1;
|
private int numberOfMipmapLevels = 1;
|
||||||
public int bytesOfKeyValueData = 0;
|
private int bytesOfKeyValueData = 0;
|
||||||
//KTX End
|
//KTX End
|
||||||
//TextureConverter
|
//TextureConverter
|
||||||
public QFORMAT q_format;
|
private QFORMAT q_format;
|
||||||
|
//texgenpack
|
||||||
|
private texgenpack_texturetype texturetype;
|
||||||
|
|
||||||
[DllImport("PVRTexLibWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PVRTexLibWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool DecompressPVR(byte[] buffer, IntPtr bmp, int len);
|
private static extern bool DecompressPVR(byte[] buffer, IntPtr bmp, int len);
|
||||||
@ -89,6 +91,12 @@ namespace Unity_Studio
|
|||||||
[DllImport("TextureConverterWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("TextureConverterWrapper.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type, int bmpsize, bool fixAlpha);
|
private static extern bool Ponvert(byte[] buffer, IntPtr bmp, int nWidth, int nHeight, int len, int type, int bmpsize, bool fixAlpha);
|
||||||
|
|
||||||
|
[DllImport("crunch.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
private static extern bool DecompressCRN(byte[] pSrc_file_data, int src_file_size, out IntPtr dxtdata, out int dxtsize);
|
||||||
|
|
||||||
|
[DllImport("texgenpack.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
private static extern bool texgenpackdecode(int texturetype, byte[] texturedata, int width, int height, IntPtr bmp, bool fixAlpha);
|
||||||
|
|
||||||
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
public Texture2D(AssetPreloadData preloadData, bool readSwitch)
|
||||||
{
|
{
|
||||||
var sourceFile = preloadData.sourceFile;
|
var sourceFile = preloadData.sourceFile;
|
||||||
@ -492,30 +500,37 @@ namespace Unity_Studio
|
|||||||
}
|
}
|
||||||
case TextureFormat.BC4:
|
case TextureFormat.BC4:
|
||||||
{
|
{
|
||||||
|
texturetype = texgenpack_texturetype.RGTC1;
|
||||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RED_RGTC1;
|
glInternalFormat = KTXHeader.GL_COMPRESSED_RED_RGTC1;
|
||||||
glBaseInternalFormat = KTXHeader.GL_RED;
|
glBaseInternalFormat = KTXHeader.GL_RED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextureFormat.BC5:
|
case TextureFormat.BC5:
|
||||||
{
|
{
|
||||||
|
texturetype = texgenpack_texturetype.RGTC2;
|
||||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RG_RGTC2;
|
glInternalFormat = KTXHeader.GL_COMPRESSED_RG_RGTC2;
|
||||||
glBaseInternalFormat = KTXHeader.GL_RG;
|
glBaseInternalFormat = KTXHeader.GL_RG;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextureFormat.BC6H:
|
case TextureFormat.BC6H:
|
||||||
{
|
{
|
||||||
|
texturetype = texgenpack_texturetype.BPTC_FLOAT;
|
||||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
|
glInternalFormat = KTXHeader.GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
|
||||||
glBaseInternalFormat = KTXHeader.GL_RGB;
|
glBaseInternalFormat = KTXHeader.GL_RGB;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextureFormat.BC7:
|
case TextureFormat.BC7:
|
||||||
{
|
{
|
||||||
|
texturetype = texgenpack_texturetype.BPTC;
|
||||||
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA_BPTC_UNORM;
|
glInternalFormat = KTXHeader.GL_COMPRESSED_RGBA_BPTC_UNORM;
|
||||||
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
glBaseInternalFormat = KTXHeader.GL_RGBA;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextureFormat.DXT1Crunched: //DXT1 Crunched
|
case TextureFormat.DXT1Crunched: //DXT1 Crunched
|
||||||
|
q_format = QFORMAT.Q_FORMAT_S3TC_DXT1_RGB;
|
||||||
|
break;
|
||||||
case TextureFormat.DXT5Crunched: //DXT1 Crunched
|
case TextureFormat.DXT5Crunched: //DXT1 Crunched
|
||||||
|
q_format = QFORMAT.Q_FORMAT_S3TC_DXT5_RGBA;
|
||||||
break;
|
break;
|
||||||
case TextureFormat.PVRTC_RGB2: //test pass
|
case TextureFormat.PVRTC_RGB2: //test pass
|
||||||
{
|
{
|
||||||
@ -952,11 +967,11 @@ namespace Unity_Studio
|
|||||||
case TextureFormat.BC5:
|
case TextureFormat.BC5:
|
||||||
case TextureFormat.BC6H:
|
case TextureFormat.BC6H:
|
||||||
case TextureFormat.BC7:
|
case TextureFormat.BC7:
|
||||||
//texgenpack
|
bitmap = Texgenpack();
|
||||||
break;
|
break;
|
||||||
case TextureFormat.DXT1Crunched:
|
case TextureFormat.DXT1Crunched:
|
||||||
case TextureFormat.DXT5Crunched:
|
case TextureFormat.DXT5Crunched:
|
||||||
//crunch
|
bitmap = CRNToBitmap();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (bitmap != null && flip)
|
if (bitmap != null && flip)
|
||||||
@ -1014,6 +1029,33 @@ namespace Unity_Studio
|
|||||||
bitmap.UnlockBits(bmd);
|
bitmap.UnlockBits(bmd);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bitmap CRNToBitmap()
|
||||||
|
{
|
||||||
|
IntPtr dxtdata;
|
||||||
|
int dxtsize;
|
||||||
|
if (DecompressCRN(image_data, image_data_size, out dxtdata, out dxtsize))
|
||||||
|
{
|
||||||
|
var dxtbytes = new byte[dxtsize];
|
||||||
|
Marshal.Copy(dxtdata, dxtbytes, 0, dxtsize);
|
||||||
|
Marshal.FreeHGlobal(dxtdata);
|
||||||
|
image_data = dxtbytes;
|
||||||
|
image_data_size = dxtsize;
|
||||||
|
return TextureConverter();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap Texgenpack()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
var fixAlpha = glBaseInternalFormat == KTXHeader.GL_RED || glBaseInternalFormat == KTXHeader.GL_RG;
|
||||||
|
texgenpackdecode((int)texturetype, image_data, m_Width, m_Height, bmd.Scan0, fixAlpha);
|
||||||
|
bitmap.UnlockBits(bmd);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1247,3 +1289,11 @@ public enum QFORMAT
|
|||||||
Q_FORMAT_ASTC_8,
|
Q_FORMAT_ASTC_8,
|
||||||
Q_FORMAT_ASTC_16,
|
Q_FORMAT_ASTC_16,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public enum texgenpack_texturetype
|
||||||
|
{
|
||||||
|
RGTC1,
|
||||||
|
RGTC2,
|
||||||
|
BPTC_FLOAT,
|
||||||
|
BPTC
|
||||||
|
}
|
22
Unity Studio/library/crunch_license.txt
Normal file
22
Unity Studio/library/crunch_license.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
crunch/crnlib uses the ZLIB license:
|
||||||
|
http://opensource.org/licenses/Zlib
|
||||||
|
|
||||||
|
Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
13
Unity Studio/library/texgenpack_license.txt
Normal file
13
Unity Studio/library/texgenpack_license.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Copyright (c) 2015 Harm Hanemaaijer <fgenfb@yahoo.com>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
BIN
Unity Studio/library/x64/crunch.dll
Normal file
BIN
Unity Studio/library/x64/crunch.dll
Normal file
Binary file not shown.
BIN
Unity Studio/library/x64/texgenpack.dll
Normal file
BIN
Unity Studio/library/x64/texgenpack.dll
Normal file
Binary file not shown.
BIN
Unity Studio/library/x86/crunch.dll
Normal file
BIN
Unity Studio/library/x86/crunch.dll
Normal file
Binary file not shown.
BIN
Unity Studio/library/x86/texgenpack.dll
Normal file
BIN
Unity Studio/library/x86/texgenpack.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user