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 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 void gammaFixToolStripMenuItem_Click(object sender, EventArgs e) { Image Image = pictureBoxCustom1.Image; if (Image != null) { UpdateEditCached(BitmapExtension.AdjustGamma(Image, 2.2f)); } }
private void UpdateGamma() { if (Runtime.ImageEditor.PreviewGammaFix) { pictureBoxCustom1.Image = BitmapExtension.AdjustGamma(pictureBoxCustom1.Image, 1.0f / 2.2f); } else { if (ActiveTexture != null) { UpdateImage(ActiveTexture, CurArrayDisplayLevel); } } UpdateLabel(); }
public void SaveAndApplyImage(Bitmap image, bool DecodeBack, bool isDDS) { if (image == null) { return; } if (Runtime.ImageEditor.PreviewGammaFix && !isDDS) { image = BitmapExtension.AdjustGamma(image, 2.2f); DecodeBack = true; } if (saveBtn.InvokeRequired) { saveBtn.Invoke(new MethodInvoker( delegate() { UpdateEditCached(image); ApplyEdit(image); //Update the image with decoding as format could change if (DecodeBack) { UpdateImage(ActiveTexture); } })); } else { UpdateEditCached(image); ApplyEdit(image); //Update the image with decoding as format could change if (DecodeBack) { UpdateImage(ActiveTexture); } } propertiesEditor.UpdateProperties(); }
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); } } }