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); }
private bool DecodeProcessFinished = false; //Used to determine when the decode process is done private void UpdatePictureBox(int ChannelIndex = 0) { DecodeProcessFinished = false; PushImage(Properties.Resources.LoadingImage); var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel); if (image != null) { if (ChannelIndex == 1) { BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.One); } else if (ChannelIndex == 2) { BitmapExtension.SetChannel(image, STChannelType.Green, STChannelType.Green, STChannelType.Green, STChannelType.One); } else if (ChannelIndex == 3) { BitmapExtension.SetChannel(image, STChannelType.Blue, STChannelType.Blue, STChannelType.Blue, STChannelType.One); } else if (ChannelIndex == 4) { BitmapExtension.SetChannel(image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One); } else { if (!toggleAlphaChk.Checked) { BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, STChannelType.One); } } DecodeProcessFinished = true; // BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel); PushImage(image); } }
public void SaveBitMap(string FileName, bool ExportSurfaceLevel = false, bool ExportMipMapLevel = false, int SurfaceLevel = 0, int MipLevel = 0) { if (ArrayCount > 1 && !ExportSurfaceLevel) { string ext = Path.GetExtension(FileName); int index = FileName.LastIndexOf('.'); string name = index == -1 ? FileName : FileName.Substring(0, index); for (int i = 0; i < ArrayCount; i++) { Bitmap arrayBitMap = GetBitmap(i, 0); arrayBitMap.Save($"{name}_Slice_{i}_{ext}"); arrayBitMap.Dispose(); } return; } Bitmap bitMap = GetBitmap(SurfaceLevel, MipLevel); if (Runtime.ImageEditor.UseComponetSelector) { bitMap = BitmapExtension.SetChannel(bitMap, RedChannel, GreenChannel, BlueChannel, AlphaChannel); } if (Runtime.ImageEditor.PreviewGammaFix) { bitMap = BitmapExtension.AdjustGamma(bitMap, 1.0f / 2.2f); } if (Parameters.FlipY) { bitMap.RotateFlip(RotateFlipType.RotateNoneFlipY); } bitMap.Save(FileName); bitMap.Dispose(); }
private void UpdatePictureBox(int ChannelIndex = 0) { if (ActiveTexture == null) { return; } DecodeProcessFinished = false; PushImage(Properties.Resources.LoadingImage); var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel); //Keep base image for channel viewer updating/editing if (image != null) { BaseImage = new Bitmap(image); } else { BaseImage = null; } if (propertiesEditor.InvokeRequired) { propertiesEditor.Invoke(new MethodInvoker( delegate() { LoadChannelEditor(image); })); } else { LoadChannelEditor(image); } if (image != null) { if (ActiveTexture.Parameters.FlipY) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); } if (ChannelIndex == 1) { BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.One); } else if (ChannelIndex == 2) { BitmapExtension.SetChannel(image, STChannelType.Green, STChannelType.Green, STChannelType.Green, STChannelType.One); } else if (ChannelIndex == 3) { BitmapExtension.SetChannel(image, STChannelType.Blue, STChannelType.Blue, STChannelType.Blue, STChannelType.One); } else if (ChannelIndex == 4) { BitmapExtension.SetChannel(image, STChannelType.Alpha, STChannelType.Alpha, STChannelType.Alpha, STChannelType.One); } else { STChannelType AlphaDisplay = ActiveTexture.AlphaChannel; if (!Runtime.ImageEditor.DisplayAlpha || HasZeroAlpha()) { AlphaDisplay = STChannelType.One; } //For RGBA types try to only load the alpha toggle to load quicker //Loading components would not be necessary as it is default to RGBA if (UseRGBA()) { if (!Runtime.ImageEditor.DisplayAlpha) { BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, AlphaDisplay); } } else { //Check components for the channels if (Runtime.ImageEditor.UseComponetSelector) { BitmapExtension.SetChannel(image, ActiveTexture.RedChannel, ActiveTexture.GreenChannel, ActiveTexture.BlueChannel, AlphaDisplay); } else { if (!Runtime.ImageEditor.DisplayAlpha) { BitmapExtension.SetChannel(image, STChannelType.Red, STChannelType.Green, STChannelType.Blue, AlphaDisplay); } } } } DecodeProcessFinished = true; if (Runtime.ImageEditor.PreviewGammaFix && image != null) { image = BitmapExtension.AdjustGamma(image, 1.0f / 2.2f); } // BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel); PushImage(image); if (image != null) { UpdateTreeIcon(ActiveTexture, image); } } }
private void UpdateArrayLevel() { if (ActiveTexture == null) { return; } TotalArrayCount = (int)(ActiveTexture.ArrayCount / 6) - 1; arrayLevelCounterLabel.Text = $"Array Level: {CurArrayDisplayLevel} / {TotalArrayCount}"; for (int i = 0; i < 6; i++) { var CubeFaceBitmap = ActiveTexture.GetBitmap(i + (CurArrayDisplayLevel * 6)); if (!DisplayAlpha) { BitmapExtension.SetChannel(CubeFaceBitmap, ActiveTexture.RedChannel, ActiveTexture.GreenChannel, ActiveTexture.BlueChannel, STChannelType.One); } if (i == FRONT_FACE) { pbFrontFace.Image = CubeFaceBitmap; } else if (i == BACK_FACE) { pbBackFace.Image = CubeFaceBitmap; } else if (i == BOTTOM_FACE) { pbBottomFace.Image = CubeFaceBitmap; } else if (i == TOP_FACE) { pbTopFace.Image = CubeFaceBitmap; } else if (i == LEFT_FACE) { pbLeftFace.Image = CubeFaceBitmap; } else if (i == RIGHT_FACE) { pbRightFace.Image = CubeFaceBitmap; } } if (CurArrayDisplayLevel != TotalArrayCount) { btnRightArray.Enabled = true; } else { btnRightArray.Enabled = false; } if (CurArrayDisplayLevel != 0) { btnLeftArray.Enabled = true; } else { btnLeftArray.Enabled = false; } }
public void SetupSettings(GTXImporterSettings setting) { if (setting.Format == GX2.GX2SurfaceFormat.INVALID || SelectedIndex == -1) { return; } if (Thread != null && Thread.IsAlive) { Thread.Abort(); } if (formatComboBox.SelectedItem is GX2.GX2SurfaceFormat) { setting.Format = (GX2.GX2SurfaceFormat)formatComboBox.SelectedItem; if (setting.Format == GX2.GX2SurfaceFormat.T_BC4_UNORM && DisplayBC4Alpha || setting.Format == GX2.GX2SurfaceFormat.T_BC4_SNORM && DisplayBC4Alpha) { chkBc4Alpha.Visible = true; } else { chkBc4Alpha.Visible = false; } listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString(); } HeightLabel.Text = $"Height: {setting.TexHeight}"; WidthLabel.Text = $"Width: {setting.TexWidth}"; Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage(); pictureBox1.Image = bitmap; Thread = new Thread((ThreadStart)(() => { setting.IsFinishedCompressing = false; ToggleOkButton(false); var mips = setting.GenerateMipList(); setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray())); ToggleOkButton(true); setting.Compress(); bitmap = FTEX.DecodeBlockGetBitmap(mips[0], setting. TexWidth, setting.TexHeight, FTEX.ConvertFromGx2Format( (Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)setting.Format), new byte[0]); if (setting.UseBc4Alpha) { bitmap = BitmapExtension.SetChannel(bitmap, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red); } if (pictureBox1.InvokeRequired) { pictureBox1.Invoke((MethodInvoker) delegate { pictureBox1.Image = bitmap; pictureBox1.Refresh(); int size = Utils.GetSizeInBytes(mips); dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}"; }); } mips.Clear(); })); Thread.Start(); }
public void SetupSettings(TextureImporterSettings setting, bool setFormat = true) { if (setting.Format == SurfaceFormat.Invalid || SelectedIndex == -1) { return; } WidthLabel.Text = $"Width: {setting.TexWidth}"; HeightLabel.Text = $"Height: {setting.TexHeight}"; if (Thread != null && Thread.IsAlive) { Thread.Abort(); } if (formatComboBox.SelectedItem is SurfaceDim && setFormat) { setting.SurfaceDim = (SurfaceDim)formatComboBox.SelectedItem; } if (formatComboBox.SelectedItem is SurfaceFormat && setFormat) { setting.Format = (SurfaceFormat)formatComboBox.SelectedItem; listViewCustom1.Items[SelectedIndex].SubItems[1].Text = setting.Format.ToString(); } if (setting.Format == SurfaceFormat.BC7_UNORM || setting.Format == SurfaceFormat.BC7_SRGB) { compressionModeCB.Visible = true; compModeLbl.Visible = true; } else { compressionModeCB.Visible = false; compModeLbl.Visible = false; } if (setting.Format == SurfaceFormat.BC4_UNORM || setting.Format == SurfaceFormat.BC4_SNORM) { chkBC4Alpha.Enabled = true; } else { chkBC4Alpha.Enabled = false; } Bitmap bitmap = Toolbox.Library.Imaging.GetLoadingImage(); if (compressionModeCB.SelectedIndex == 0) { CompressionMode = STCompressionMode.Fast; } else { CompressionMode = STCompressionMode.Normal; } Thread = new Thread((ThreadStart)(() => { setting.IsFinishedCompressing = false; ToggleOkButton(false); pictureBox1.Image = bitmap; var mips = setting.GenerateMipList(CompressionMode, MultiThreading, chkBC4Alpha.Checked); setting.DataBlockOutput.Clear(); setting.DataBlockOutput.Add(Utils.CombineByteArray(mips.ToArray())); ToggleOkButton(true); setting.IsFinishedCompressing = true; if (setting.DataBlockOutput.Count > 0) { if (setting.Format == SurfaceFormat.BC5_SNORM) { bitmap = DDSCompressor.DecompressBC5(mips[0], (int)setting.TexWidth, (int)setting.TexHeight, true); } else { bitmap = STGenericTexture.DecodeBlockGetBitmap(mips[0], setting.TexWidth, setting.TexHeight, TextureData.ConvertFormat(setting.Format), new byte[0]); } if (chkBC4Alpha.Checked) { bitmap = BitmapExtension.SetChannel(bitmap, STChannelType.Red, STChannelType.Red, STChannelType.Red, STChannelType.Red); } } if (pictureBox1.InvokeRequired) { pictureBox1.Invoke((MethodInvoker) delegate { pictureBox1.Image = bitmap; pictureBox1.Refresh(); int size = Utils.GetSizeInBytes(mips); dataSizeLbl.Text = $"Data Size: {STMath.GetFileSize(size, 5)}"; }); } mips.Clear(); })); Thread.Start(); }