public byte[] GenerateMips(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); if (FlipY) { Image.RotateFlip(RotateFlipType.RotateNoneFlipY); } List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
public Bitmap DisplayImage(int mipLevel = 0, int arrayLevel = 0) { LoadTexture(); Bitmap decomp; if (Format == XTXFormats.XTXImageFormat.BC5S) { return(DDSCompressor.DecompressBC5(mipmaps[0], (int)Width, (int)Height, true)); } byte[] d = null; if (IsCompressedFormat(Format)) { d = DDSCompressor.DecompressBlock(mipmaps[0], (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format)); } else { d = DDSCompressor.DecodePixelBlock(mipmaps[0], (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format)); } if (d != null) { decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height); return(TextureData.SwapBlueRedChannels(decomp)); } return(null); }
public byte[] GenerateMips(STCompressionMode CompressionMode, int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); if (GammaFix) { Image = BitmapExtension.AdjustGamma(Image, 2.2f); } List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
public byte[] GenerateMips(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); mipmaps.Add(FTEX.CompressBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, Format)); //while (Image.Width / 2 > 0 && Image.Height / 2 > 0) // for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) int width = Image.Width; int height = Image.Height; for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { if (Image.Width != 1) { width = Image.Width / 2; } if (Image.Height != 1) { height = Image.Height / 2; } Image = BitmapExtension.Resize(Image, width, height); mipmaps.Add(FTEX.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, Format)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
public Tuple <List <byte[]>, ushort[]> GenerateMipList(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); ushort[] paletteData = new ushort[0]; List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } var EncodedData = Decode_Gamecube.EncodeData(BitmapExtension.ImageToByte(Image), Format, PaletteFormat, MipWidth, MipHeight); mipmaps.Add(EncodedData.Item1); if (mipLevel == 0) //Set palette data once { paletteData = EncodedData.Item2; } } Image.Dispose(); return(Tuple.Create(mipmaps, paletteData)); }
public List <byte[]> GenerateMipList(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); if (FlipY) { Image.RotateFlip(RotateFlipType.RotateNoneFlipY); } if (UseBc4Alpha && (Format == GX2.GX2SurfaceFormat.T_BC4_UNORM || Format == GX2.GX2SurfaceFormat.T_BC4_SNORM)) { Image = BitmapExtension.SetChannel(Image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One); } Console.WriteLine($"FlipY {FlipY}"); List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef)); } Image.Dispose(); return(mipmaps); }
public List <byte[]> GenerateMipList(STCompressionMode CompressionMode, bool multiThread, bool bc4Alpha, int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); if (GammaFix) { Image = BitmapExtension.AdjustGamma(Image, 2.2f); } if (bc4Alpha) { Image = BitmapExtension.SetChannel(Image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha); } List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, multiThread, CompressionMode)); } Image.Dispose(); return(mipmaps); }
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, GX2SurfaceFormat Format) { Bitmap decomp; try { if (Format == GX2SurfaceFormat.T_BC5_SNorm) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true)); } byte[] d = null; if (IsCompressedFormat(Format)) { d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format)); } else { d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format)); } if (d != null) { decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height); return(SwapBlueRedChannels(decomp)); } return(BitmapExtension.GetBitmap(d, (int)Width, (int)Height));; } catch { throw new Exception($"Bad size from format {Format}"); } }
public byte[] GenerateMips(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef)); //while (Image.Width / 2 > 0 && Image.Height / 2 > 0) // for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int width = Image.Width / 2; int height = Image.Height / 2; if (width <= 0) { width = 1; } if (height <= 0) { height = 1; } Image = BitmapExtension.Resize(Image, width, height); mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, NUTEXImageFormat Format) { Bitmap decomp; if (Format == NUTEXImageFormat.BC5_SNORM) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true)); } byte[] d = null; if (IsCompressedFormat(Format)) { d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format)); } else { d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format)); } if (d != null) { decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height); return(TextureData.SwapBlueRedChannels(decomp)); } return(null); }
public Bitmap DisplayTexture(int DisplayMipIndex = 0, int ArrayIndex = 0) { if (BadSwizzle) { return(BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32)); } if (IsSwizzled) { LoadTexture(); } else { mipmaps.Add(blocksCompressed[0]); } if (mipmaps[0].Count <= 0) { return(BitmapExtension.GetBitmap(Properties.Resources.Black, 32, 32)); } uint width = (uint)Math.Max(1, Width >> DisplayMipIndex); uint height = (uint)Math.Max(1, Height >> DisplayMipIndex); byte[] data = mipmaps[ArrayIndex][DisplayMipIndex]; return(DecodeBlock(data, width, height, (NUTEXImageFormat)Format)); }
public List <byte[]> GenerateMipList(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); mipmaps.Add(CTR_3DS.EncodeBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, Format)); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int width = Image.Width / 2; int height = Image.Width / 2; if (Format == CTR_3DS.PICASurfaceFormat.ETC1 || Format == CTR_3DS.PICASurfaceFormat.ETC1A4) { if (width < 16) { break; } if (height < 16) { break; } } else { if (width < 8) { break; } if (height < 8) { break; } } Image = BitmapExtension.Resize(Image, width, height); mipmaps.Add(CTR_3DS.EncodeBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, Format)); } Image.Dispose(); return(mipmaps); }
public byte[] GenerateMips(int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef)); //while (Image.Width / 2 > 0 && Image.Height / 2 > 0) // for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2); mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, FTEX.ConvertFromGx2Format((GX2SurfaceFormat)Format), alphaRef)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
public List <byte[]> GenerateMipList(STCompressionMode CompressionMode, bool multiThread, int SurfaceLevel = 0) { Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); if (mipLevel != 0) { Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); } mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, Format, alphaRef, multiThread, CompressionMode)); } Image.Dispose(); return(mipmaps); }
public List <byte[]> GenerateMipList(int SurfaceLevel = 0) { MipCount = 1; Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight); List <byte[]> mipmaps = new List <byte[]>(); mipmaps.Add(CTR_3DS.EncodeBlock(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight, Format)); //while (Image.Width / 2 > 0 && Image.Height / 2 > 0) // for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) { Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2); mipmaps.Add(CTR_3DS.EncodeBlock(BitmapExtension.ImageToByte(Image), Image.Width, Image.Height, Format)); } Image.Dispose(); return(mipmaps); }
private Bitmap DecodeNotDirectXTex(byte[] data, uint Width, uint Height, TEX_FORMAT Format) { if (Format == TEX_FORMAT.R8G8B8A8_UNORM) { return(BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.R8G8B8A8_UNORM_SRGB) { return(BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.BC1_UNORM) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC1_UNORM_SRGB) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC3_UNORM_SRGB) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC3_UNORM) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC4_UNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC4_SNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC5_UNORM) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC7_UNORM) { return(BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.BC7_UNORM_SRGB) { return(BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height)); } else { if (Runtime.UseOpenGL) { Runtime.OpenTKInitialized = true; if (RenderableTex == null || !RenderableTex.GLInitialized) { LoadOpenGLTexture(); } return(RenderableTex.ToBitmap()); } } return(null); }
public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0) { uint width = Math.Max(1, Width >> MipLevel); uint height = Math.Max(1, Height >> MipLevel); byte[] data = GetImageData(ArrayLevel, MipLevel, DepthLevel); byte[] paletteData = GetPaletteData(); if (Format == TEX_FORMAT.R8G8B8A8_UNORM) { return(BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)width, (int)height)); } try { if (data == null) { throw new Exception("Data is null!"); } if (PlatformSwizzle == PlatformSwizzle.Platform_3DS) { var Image = BitmapExtension.GetBitmap(ConvertBgraToRgba(CTR_3DS.DecodeBlock(data, (int)width, (int)height, Format)), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Image.RotateFlip(RotateFlipType.RotateNoneFlipY); //It's upside down for some reason so flip it return(Image); } if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube) { return(BitmapExtension.GetBitmap(Decode_Gamecube.DecodeData(data, paletteData, width, height, Format, PaletteFormat), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); } switch (Format) { case TEX_FORMAT.R4G4_UNORM: return(BitmapExtension.GetBitmap(R4G4.Decompress(data, (int)width, (int)height, false), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); case TEX_FORMAT.BC5_SNORM: return(DDSCompressor.DecompressBC5(data, (int)width, (int)height, true)); case TEX_FORMAT.ETC1_UNORM: return(BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, false), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); case TEX_FORMAT.ETC1_A4: return(BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, true), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); case TEX_FORMAT.R5G5B5A1_UNORM: case TEX_FORMAT.LA8: case TEX_FORMAT.L8: return(BitmapExtension.GetBitmap(RGBAPixelDecoder.Decode(data, (int)width, (int)height, Format), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); } if (Runtime.UseDirectXTexDecoder) { return(BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format, new byte[0], Parameters), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); } else { return(DecodeNotDirectXTex(data, width, height, Format)); } } catch (Exception ex) { /* Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); * * try * { * return DecodeNotDirectXTex(data, width, height, Format); * } * catch * { * Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); * }*/ return(null); } }