5 using System.Runtime.InteropServices;
7 namespace SiliconStudio.TextureConverter.PvrttWrapper
11 internal enum PixelType
18 internal enum EPVRTColourSpace
25 internal enum EPVRTVariableType
44 internal enum ECompressorQuality
59 internal enum EResizeMode
67 internal enum EChannelName
80 internal enum EPVRTAxis
87 internal enum EPVRTPixelFormat
135 public const uint TOPMIPLEVEL = 0;
136 public const int ALLMIPLEVELS = -1;
137 public const uint PVRTEX3_IDENT = 0x03525650;
138 public const uint PVRTEX3_PREMULTIPLIED = (1 << 1);
145 #region public class Utilities
153 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
154 private extern static bool pvrttTranscodeWithNoConversion(IntPtr texture, PixelType ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality,
bool bDoDither);
156 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
157 private extern static bool pvrttTranscode(IntPtr texture, UInt64 ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality,
bool bDoDither);
159 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
160 private extern static bool pvrttCopyChannels(IntPtr sTexture, IntPtr sTextureSource, uint uiNumChannelCopies, out EChannelName eChannels, out EChannelName eChannelsSource);
162 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
163 private extern static bool pvrttResize(IntPtr sTexture, out uint u32NewWidth, out uint u32NewHeight, out uint u32NewDepth, EResizeMode eResizeMode);
165 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
166 private extern static bool pvrttFlip(IntPtr sTexture, EPVRTAxis eFlipDirection);
168 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
171 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
174 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
175 private extern static int pvrttDecompressPVRTC(IntPtr pCompressedData,
int Do2bitMode,
int XDim,
int YDim, IntPtr pResultImage);
177 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
178 private extern static int pvrttDecompressETC(IntPtr pSrcData, uint x, uint
y, IntPtr pDestData,
int nMode);
180 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
194 public static bool CopyChannels(PVRTexture sTexture, PVRTexture sTextureSource, uint uiNumChannelCopies, out EChannelName eChannels, out EChannelName eChannelsSource)
196 return pvrttCopyChannels(sTexture.texture, sTextureSource.texture, uiNumChannelCopies, out eChannels, out eChannelsSource);
199 public static bool Transcode(PVRTexture sTexture, PixelType ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality = ECompressorQuality.ePVRTCNormal,
bool bDoDither =
false)
204 public static bool Transcode(PVRTexture sTexture, UInt64 ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality = ECompressorQuality.ePVRTCNormal,
bool bDoDither =
false)
206 return pvrttTranscode(sTexture.texture, ptFormat, eChannelType, eColourspace, eQuality, bDoDither);
218 public static bool Resize(PVRTexture sTexture, uint u32NewWidth, uint u32NewHeight, uint u32NewDepth, EResizeMode eResizeMode)
220 return pvrttResize(sTexture.texture, out u32NewWidth, out u32NewHeight, out u32NewDepth, eResizeMode);
230 public static bool Flip(PVRTexture sTexture, EPVRTAxis eFlipDirection)
232 return pvrttFlip(sTexture.texture, eFlipDirection);
235 public static bool GenerateNormalMap(PVRTexture sTexture,
float fScale,
string sChannelOrder)
240 public static UInt64 ConvertPixelType(PixelType pixelFormat)
245 public static int DecompressPVRTC(IntPtr pCompressedData,
int Do2bitMode,
int XDim,
int YDim, IntPtr pResultImage)
247 return pvrttDecompressPVRTC(pCompressedData, Do2bitMode, XDim, YDim, pResultImage);
250 public static int DecompressETC(IntPtr pSrcData, uint x, uint y, IntPtr pDestData,
int nMode)
252 return pvrttDecompressETC(pSrcData, x, y, pDestData, nMode);
255 public static bool PreMultipliedAlpha(PVRTexture sTexture)
262 #region public class CPVRTexture
266 internal class PVRTexture : IDisposable
268 internal IntPtr texture;
271 const uint TOPMIPLEVEL = 0;
272 const int ALLMIPLEVELS = -1;
276 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
279 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
282 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
285 [DllImport(
"PvrttWrapper.dll", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
288 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
291 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
292 private extern static bool pvrttSaveFile(IntPtr texture, String filePath);
294 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
297 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
298 private extern static IntPtr
pvrttGetDataPtr(IntPtr texture, uint uiMIPLevel, uint uiArrayMember, uint uiFaceNumber);
300 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
301 private extern static bool pvrttGenerateMIPMaps(IntPtr texture, EResizeMode eFilterMode,
int uiMIPMapsToDo);
310 public PVRTexture(IntPtr pTexture)
315 public PVRTexture(
string filePath)
320 public PVRTexture(PVRTextureHeader headerIn, IntPtr data)
325 public bool Save(
string filePath)
330 public PVRTextureHeader GetHeader()
335 public IntPtr GetDataPtr(uint uiMIPLevel = 0, uint uiArrayMember = 0, uint uiFaceNumber = 0) {
336 return pvrttGetDataPtr(texture, uiMIPLevel, uiArrayMember, uiFaceNumber);
339 public bool GenerateMIPMaps(EResizeMode eFilterMode,
int uiMIPMapsToDo = ALLMIPLEVELS)
345 public void Dispose()
352 #region public class PvrttTextureHeader
356 internal class PVRTextureHeader : IDisposable
358 public IntPtr header {
internal set;
get; }
361 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
364 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
365 private extern static IntPtr
pvrttCreateTextureHeader(PixelType pixelFormat,
int height,
int width,
int depth,
int numMipMaps,
int numArrayMembers,
int numFaces, EPVRTColourSpace eColourSpace, EPVRTVariableType eChannelType,
bool bPreMultiplied);
367 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
368 private extern static IntPtr
pvrttCreateTextureHeaderFromCompressedTexture(UInt64 pixelFormat,
int height,
int width,
int depth,
int numMipMaps,
int numArrayMembers,
int numFaces, EPVRTColourSpace eColourSpace, EPVRTVariableType eChannelType,
bool bPreMultiplied);
370 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
373 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
374 private extern static UInt32
pvrttGetWidth(IntPtr header, uint uiMipLevel);
376 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
377 private extern static UInt32
pvrttGetHeight(IntPtr header, uint uiMipLevel);
379 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
382 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
385 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
386 private extern static void pvrttSetWidth(IntPtr header, uint newWidth);
388 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
389 private extern static void pvrttSetHeight(IntPtr header, uint newHeight);
391 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
394 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
395 private extern static uint
pvrttGetDataSize(IntPtr header,
int iMipLevel,
bool bAllSurfaces,
bool bAllFaces);
397 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
398 private extern static uint
pvrttGetTextureSize(IntPtr header,
int iMipLevel,
bool bAllSurfaces,
bool bAllFaces);
400 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
401 private extern static uint
pvrttGetDepth(IntPtr header, uint uiMipLevel);
403 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
404 private extern static uint
pvrttGetBPP(IntPtr header);
406 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
409 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
412 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
415 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
418 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
421 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
424 [DllImport(
"PvrttWrapper", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
430 public PVRTextureHeader()
435 public PVRTextureHeader(PixelType pixelFormat,
int height=1,
int width=1,
int depth=1,
int numMipMaps=1,
int numArrayMembers=1,
int numFaces=1, EPVRTColourSpace eColourSpace=EPVRTColourSpace.ePVRTCSpacelRGB, EPVRTVariableType eChannelType=EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm,
bool bPreMultiplied=
false)
437 header =
pvrttCreateTextureHeader(pixelFormat, height, width, depth, numMipMaps, numArrayMembers, numFaces, eColourSpace, eChannelType, bPreMultiplied);
440 public PVRTextureHeader(UInt64 pixelFormat,
int height=1,
int width=1,
int depth=1,
int numMipMaps=1,
int numArrayMembers=1,
int numFaces=1, EPVRTColourSpace eColourSpace=EPVRTColourSpace.ePVRTCSpacelRGB, EPVRTVariableType eChannelType=EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm,
bool bPreMultiplied=
false)
445 public PVRTextureHeader(IntPtr headerPtr)
450 public PVRTextureHeader Copy()
455 public uint GetWidth(uint uiMipLevel =
Constant.TOPMIPLEVEL)
460 public uint GetHeight(uint uiMipLevel =
Constant.TOPMIPLEVEL)
465 public uint GetNumMIPLevels()
470 public void SetNumMIPLevels(
int newMipsLevels)
475 public void SetPixelFormat(PixelType pixelType)
480 public void SetWidth(uint newWidth)
485 public void SetHeight(uint newHeight)
490 public uint GetDataSize(
int iMipLevel =
Constant.ALLMIPLEVELS,
bool bAllSurfaces =
true,
bool bAllFaces =
true)
495 public uint GetTextureSize(
int iMipLevel =
Constant.ALLMIPLEVELS,
bool bAllSurfaces =
true,
bool bAllFaces =
true)
500 public uint GetDepth(uint uiMipLevel =
Constant.TOPMIPLEVEL)
510 public uint GetNumArrayMembers()
516 public uint GetNumFaces()
521 public uint GetMetaDataSize()
526 public EPVRTVariableType GetChannelType()
531 public UInt64 GetPixelType()
536 public EPVRTColourSpace GetColourSpace()
548 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGB;
550 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGBA;
552 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGB;
554 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGBA;
556 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_2bpp;
558 return SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_4bpp;
560 return SiliconStudio.Paradox.Graphics.PixelFormat.ETC1;
562 return SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB;
564 return SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGBA;
566 return SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB_A1;
568 return SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Unsigned;
570 return SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Signed;
572 return SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Unsigned;
574 return SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Signed;
579 if (format ==
Utilities.ConvertPixelType(PixelType.Standard8PixelType))
580 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
581 else if (format ==
Utilities.ConvertPixelType(PixelType.Standard16PixelType))
582 return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm;
583 else if (format ==
Utilities.ConvertPixelType(PixelType.Standard32PixelType))
584 return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float;
586 throw new TextureToolsException(
"Unknown format by PowerVC Texture Tool.");
590 public void Dispose()
bool pvrttPreMultipliedAlpha(PvrttTexture &sTexture)
pvrtexture::uint64 pvrttGetPixelType(PvrttTextureHeader *header)
pvrtexture::uint64 pvrttConvertPixelType(PvrttPixelType pixelFormat)
bool pvrttTranscode(PvrttTexture &texture, pvrtexture::uint64 ptFormat, const EPVRTVariableType eChannelType, const EPVRTColourSpace eColourspace, const pvrtexture::ECompressorQuality eQuality, const bool bDoDither)
void * pvrttGetDataPtr(PvrttTexture *texture, pvrtexture::uint32 uiMIPLevel=0, pvrtexture::uint32 uiArrayMember=0, pvrtexture::uint32 uiFaceNumber=0)
pvrtexture::uint32 pvrttGetNumFaces(PvrttTextureHeader *header)
HRESULT Resize(_In_ const Image &srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage &image)
EPVRTVariableType pvrttGetChannelType(PvrttTextureHeader *header)
bool pvrttGenerateMIPMaps(PvrttTexture &texture, const pvrtexture::EResizeMode eFilterMode, int uiMIPMapsToDo=PVRTEX_ALLMIPLEVELS)
PvrttTextureHeader * pvrttCreateTextureHeaderEmpty()
bool pvrttFlip(PvrttTexture &sTexture, const EPVRTAxis eFlipDirection)
Interpolates by using constant value between keyframes.
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
bool pvrttCopyChannels(PvrttTexture &sTexture, const PvrttTexture &sTextureSource, pvrtexture::uint32 uiNumChannelCopies, pvrtexture::EChannelName *eChannels, pvrtexture::EChannelName *eChannelsSource)
void pvrttSetNumMIPLevels(PvrttTextureHeader *header, int newNumMIPLevels)
pvrtexture::uint32 pvrttGetNumMIPLevels(PvrttTextureHeader *header)
bool pvrttGenerateNormalMap(PvrttTexture &sTexture, const float fScale, const char *sChannelOrder)
bool pvrttResize(PvrttTexture &sTexture, const pvrtexture::uint32 &u32NewWidth, const pvrtexture::uint32 &u32NewHeight, const pvrtexture::uint32 &u32NewDepth, const pvrtexture::EResizeMode eResizeMode)
PvrttTexture * pvrttCreateTextureFromHeader(PvrttTextureHeader *sHeader, const void *pData=NULL)
pvrtexture::uint32 pvrttGetDataSize(PvrttTextureHeader *header, int iMipLevel=PVRTEX_ALLMIPLEVELS, bool bAllSurfaces=true, bool bAllFaces=true)
void pvrttSetHeight(PvrttTextureHeader *header, pvrtexture::uint32 newHeight)
PvrttTexture * pvrttCreateTextureFromFile(const char *szFilePath)
const PvrttTextureHeader * pvrttGetHeader(PvrttTexture *texture)
pvrtexture::uint32 pvrttGetHeight(PvrttTextureHeader *header, pvrtexture::uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL)
SiliconStudio.Core.Utilities Utilities
PvrttTexture * pvrttCreateTexture()
EPVRTColourSpace pvrttGetColourSpace(PvrttTextureHeader *header)
pvrtexture::uint32 pvrttGetBPP(PvrttTextureHeader *header)
void pvrttSetWidth(PvrttTextureHeader *header, pvrtexture::uint32 newWidth)
void pvrttSetPixelFormat(PvrttTextureHeader *header, PvrttPixelType pixelFormat)
void pvrttDestroyTexture(PvrttTexture *texture)
bool pvrttSaveFile(PvrttTexture *texture, const char *filePath)
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
pvrtexture::uint32 pvrttGetNumArrayMembers(PvrttTextureHeader *header)
pvrtexture::uint32 pvrttGetWidth(PvrttTextureHeader *header, pvrtexture::uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL)
bool pvrttIsFileCompressed(PvrttTextureHeader *header)
PvrttTextureHeader * pvrttCopyTextureHeader(const PvrttTextureHeader *headerIn)
PvrttTextureHeader * pvrttCreateTextureHeaderFromCompressedTexture(pvrtexture::uint64 pixelFormat, int height=1, int width=1, int depth=1, int numMipMaps=1, int numArrayMembers=1, int numFaces=1, EPVRTColourSpace eColourSpace=ePVRTCSpacelRGB, EPVRTVariableType eChannelType=ePVRTVarTypeUnsignedByteNorm, bool bPreMultiplied=false)
PixelFormat
Defines various types of pixel formats.
bool pvrttTranscodeWithNoConversion(PvrttTexture &texture, const PvrttPixelType ptFormat, const EPVRTVariableType eChannelType, const EPVRTColourSpace eColourspace, const pvrtexture::ECompressorQuality eQuality=pvrtexture::ePVRTCNormal, const bool bDoDither=false)
pvrtexture::uint32 pvrttGetDepth(PvrttTextureHeader *header, pvrtexture::uint32 uiMipLevel=PVRTEX_TOPMIPLEVEL)
PvrttTexture * pvrttCreateTextureFromMemory(const void *pTexture)
pvrtexture::uint32 pvrttGetTextureSize(PvrttTextureHeader *header, int iMipLevel, bool bAllSurfaces, bool bAllFaces)
PvrttTextureHeader * pvrttCreateTextureHeader(PvrttPixelType pixelFormat, int height=1, int width=1, int depth=1, int numMipMaps=1, int numArrayMembers=1, int numFaces=1, EPVRTColourSpace eColourSpace=ePVRTCSpacelRGB, EPVRTVariableType eChannelType=ePVRTVarTypeUnsignedByteNorm, bool bPreMultiplied=false)
pvrtexture::uint32 pvrttGetMetaDataSize(PvrttTextureHeader *header)