public void Export(string exportFilename) { switch (this.m_TextureFormat) { case 1: case 2: case 3: case 4: case 5: case 7: case 10: case 12: case 13: using (BinaryWriter writer = new BinaryWriter(File.Open(exportFilename, FileMode.Create))) { writer.Write(0x20534444); writer.Write(0x7c); writer.Write(this.dwFlags); writer.Write(this.m_Height); writer.Write(this.m_Width); writer.Write(this.dwPitchOrLinearSize); writer.Write(0); writer.Write(this.dwMipMapCount); writer.Write(new byte[0x2c]); writer.Write(this.dwSize); writer.Write(this.dwFlags2); writer.Write(this.dwFourCC); writer.Write(this.dwRGBBitCount); writer.Write(this.dwRBitMask); writer.Write(this.dwGBitMask); writer.Write(this.dwBBitMask); writer.Write(this.dwABitMask); writer.Write(this.dwCaps); writer.Write(this.dwCaps2); writer.Write(new byte[12]); writer.Write(this.image_data); writer.Close(); } return; case 30: case 0x1f: case 0x20: case 0x21: case 0x22: { using (PVRTextureHeader headerIn = new PVRTextureHeader((ulong)((uint)this.pvrPixelFormat), this.m_Height, this.m_Width, 1, 1, 1, 1, EPVRTColourSpace.ePVRTCSpacelRGB, EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm, false)) { IntPtr destination = Marshal.AllocHGlobal(this.image_data.Length); try { Marshal.Copy(this.image_data, 0, destination, this.image_data.Length); using (PVRTexture sTexture = new PVRTexture(headerIn, destination)) { Utilities.Transcode(sTexture, PixelType.Standard8PixelType, headerIn.GetChannelType(), headerIn.GetColourSpace(), ECompressorQuality.ePVRTCNormal, true); Utilities.Rotate90(sTexture, EPVRTAxis.ePVRTAxisZ, true); Utilities.Rotate90(sTexture, EPVRTAxis.ePVRTAxisZ, true); sTexture.Save(exportFilename); } } catch (Exception ex) { throw ex; } finally { Marshal.FreeHGlobal(destination); } return; } } } using (BinaryWriter writer2 = new BinaryWriter(File.Open(exportFilename, FileMode.Create))) { writer2.Write(this.image_data); writer2.Close(); } }
private SiliconStudio.Paradox.Graphics.PixelFormat RetrieveFormatFromNativeData(PVRTextureHeader header) { SiliconStudio.Paradox.Graphics.PixelFormat format = header.GetFormat(); if (format == SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeFloat: return(SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float); case EPVRTVariableType.ePVRTVarTypeUnsignedInteger: return(SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt); case EPVRTVariableType.ePVRTVarTypeSignedInteger: return(SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt); } } else if (format == SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeUnsignedShortNorm: return(SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm); case EPVRTVariableType.ePVRTVarTypeUnsignedShort: return(SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt); case EPVRTVariableType.ePVRTVarTypeSignedShortNorm: return(SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm); case EPVRTVariableType.ePVRTVarTypeSignedShort: return(SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt); } } else if (format == SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm) { switch (header.GetChannelType()) { case EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm: { if (header.GetColourSpace() == EPVRTColourSpace.ePVRTCSpacelRGB) { return(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm); } else { return(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb); } } case EPVRTVariableType.ePVRTVarTypeUnsignedByte: return(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt); case EPVRTVariableType.ePVRTVarTypeSignedByteNorm: return(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm); case EPVRTVariableType.ePVRTVarTypeSignedByte: return(SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt); } } return(format); }