public override ImageSet Cook(CookingContext context) { string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(Input)); Dictionary <string, Image> items = new Dictionary <string, Image>(); foreach (var item in Directory.GetFiles(actualPath)) { string name = Path.GetFileNameWithoutExtension(item); Bitmap bitmap = BitmapExtension.CreateOne(item); if (bitmap == null) { continue; } if (UniformSize.IsEmpty == false) { bitmap = bitmap.ResizeAndDispose(UniformSize.Width, UniformSize.Height); } items.Add(name, new Image(string.Empty, Rectangle.Empty) { Tag = new ImageCookingTag(bitmap) }); } return(new ImageSet(items)); }
public byte[] GenerateMips(STCompressionMode CompressionMode, bool multiThread, 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, multiThread, CompressionMode)); } Image.Dispose(); return(Utils.CombineByteArray(mipmaps.ToArray())); }
private void App_Frame(OpenCvSharp.Mat frame) { this.SourceFrameLock.WaitOne(); if (this.SourceFrame != null) { this.SourceFrame.Dispose(); } this.SourceFrame = frame; this.SourceFrameLock.ReleaseMutex(); this.ExecPython(this.OptionViewModel.Model.RenderScriptName, frame); this.Frame = BitmapExtension.Parse(frame); this._elapsedStopwatch.Stop(); this.ElapsedTime = this.ElapsedTime.Add(TimeSpan.FromMilliseconds(this._elapsedStopwatch.ElapsedMilliseconds)); this._elapsedStopwatch.Restart(); this._handleFrameThreadExecutableLock.WaitOne(); if (this._handleFrameThreadExecutable) { var thread = new Thread(new ThreadStart(this.FrameHandlerRoutine)); thread.Start(); } this._handleFrameThreadExecutableLock.ReleaseMutex(); }
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); 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 void LoadImage(Bitmap picBoxImg, ImageEditorBase editor) { imageEditor = editor; //Resize texture to hopefully prevent slow loading var image = BitmapExtension.Resize(picBoxImg, 65, 65); imgList.Images.Clear(); imgList.ImageSize = new Size(65, 65); imgList.ColorDepth = ColorDepth.Depth32Bit; Thread Thread = new Thread((ThreadStart)(() => { LoadImage(image); Bitmap red = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Red); LoadImage(red); Bitmap green = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Green); LoadImage(green); Bitmap blue = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Blue); LoadImage(blue); Bitmap alpha = BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Alpha); LoadImage(alpha); red.Dispose(); green.Dispose(); blue.Dispose(); alpha.Dispose(); })); Thread.Start(); channelListView.FullRowSelect = true; channelListView.SmallImageList = imgList; }
private Sprite CreateFromStrip(CookingContext context, string path) { var name = Path.GetFileNameWithoutExtension(path); var directory = Path.GetDirectoryName(path); var bitmapPath1 = Path.Combine(directory, string.Format("{0}.png", name)); var bitmapPath2 = Path.Combine(directory, string.Format("{0}.bmp", name)); var bitmapPath3 = Path.Combine(directory, string.Format("{0}.jpg", name)); Bitmap bitmap = BitmapExtension.CreateOne(bitmapPath1, bitmapPath2, bitmapPath3); if (bitmap == null) { return(null); } context.AddDependency(bitmapPath1); context.AddDependency(bitmapPath2); context.AddDependency(bitmapPath3); var data = JsonSerializer.DeserializeDataFromFile(path) as Dictionary <string, object>; var frames = data.Get("frames", 0); var size = data.Get("size", Size.Empty); var sprite = CreateSprite(EnumerateStrip(bitmap, frames, size), data); bitmap.Dispose(); return(sprite); }
public static Tuple <List <byte[]>, ushort[]> GenerateMipList(byte[] uncompressedData, uint TexWidth, uint TexHeight, uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat) { Bitmap Image = BitmapExtension.CreateBitmap(uncompressedData, (int)TexWidth, (int)TexHeight); return(GenerateMipList(Image, TexWidth, TexHeight, MipCount, Format, PaletteFormat)); }
public static Tuple <List <byte[]>, ushort[]> GenerateMipList(Bitmap Image, uint TexWidth, uint TexHeight, uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat) { 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)); }
private void LoadTextureIcon(int index, STGenericTexture texture) { Bitmap temp = texture.GetBitmap(); if (temp == null) { return; } temp = texture.GetComponentBitmap(temp, true); temp = BitmapExtension.CreateImageThumbnail(temp, 80, 80); if (listViewCustom1.InvokeRequired) { listViewCustom1.Invoke((MethodInvoker) delegate { var item = listViewCustom1.Items[index]; item.ImageIndex = imgListBig.Images.Count; item.SubItems.Add(texture.Format.ToString()); item.SubItems.Add(texture.Width.ToString()); item.SubItems.Add(texture.Height.ToString()); item.SubItems.Add(texture.DataSize); // Running on the UI thread imgListBig.Images.Add(temp); imgListSmall.Images.Add(temp); var dummy = imgListBig.Handle; var dummy2 = imgListSmall.Handle; }); } temp.Dispose(); }
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(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 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 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())); }
private void ReloadTexture(STGenericTexture tex, ListViewItem listItem) { Thread Thread = new Thread((ThreadStart)(() => { Bitmap temp = tex.GetBitmap(); if (temp == null) { return; } temp = BitmapExtension.Resize(temp, ImageList.ImageSize); if (listViewCustom1.InvokeRequired) { listViewCustom1.Invoke((MethodInvoker) delegate { ImageList.Images[listItem.ImageIndex] = temp; // Running on the UI thread var dummy = ImageList.Handle; }); } else { ListViewItem item = new ListViewItem(tex.Text, ImageList.Images.Count); item.Tag = tex; listViewCustom1.Items.Add(item); ImageList.Images.Add(temp); var dummy = ImageList.Handle; } temp.Dispose(); })); Thread.Start(); }
private void UpdateImage(STGenericTexture texture, int arrayLevel = 0) { ResetChannelEditor(); HasBeenEdited = false; if (texture.CanEdit) { imageToolStripMenuItem.Enabled = true; adjustmentsToolStripMenuItem.Enabled = true; } ActiveTexture = texture; if (ActiveTexture.CanEdit) { editBtn.Enabled = true; editToolStripMenuItem.Enabled = true; editBtn.BackgroundImage = Properties.Resources.Edit; } else { editBtn.BackgroundImage = BitmapExtension.GrayScale(Properties.Resources.Edit); } CurMipDisplayLevel = 0; CurArrayDisplayLevel = arrayLevel; hasBeenEdited = false; UpdateMipDisplay(); }
private void fillColorToolStripMenuItem_Click(object sender, EventArgs e) { Image Image = pictureBoxCustom1.Image; if (Image == null) { return; } ImageFillColor dialog = new ImageFillColor(); if (dialog.ShowDialog() == DialogResult.OK) { if (dialog.ResizeSmall) { ActiveTexture.Width = 1; ActiveTexture.Height = 1; } Bitmap newImage = BitmapExtension.FillColor((int)ActiveTexture.Width, (int)ActiveTexture.Height, dialog.FillColor); HasBeenEdited = true; UpdateEditCached(newImage); ApplyEdit(newImage); } }
public void LoadBitMap(string FileName, BntxFile bntxFile) { DecompressedData.Clear(); TexName = Path.GetFileNameWithoutExtension(FileName); bntx = bntxFile; Format = TEX_FORMAT.BC1; FormatType = TEX_FORMAT_TYPE.SRGB; GenerateMipmaps = true; Bitmap Image = new Bitmap(FileName); Image = STGenericTexture.SwapBlueRedChannels(Image); TexWidth = (uint)Image.Width; TexHeight = (uint)Image.Height; MipCount = (uint)GetTotalMipCount(); DecompressedData.Add(BitmapExtension.ImageToByte(Image)); Image.Dispose(); if (DecompressedData.Count == 0) { throw new Exception("Failed to load " + Format); } }
public void ConvetToTest() { foreach (Bitmap a in testImages) { Bitmap b = BitmapExtension.ConvetTo(a, PixelFormat.Format32bppArgb); AssertEquivilantImages(a, b); } }
public void GetUnFuckedVersionTest() { foreach (Bitmap a in testImages) { Bitmap b = BitmapExtension.GetUnFuckedVersion(a); AssertEquivilantImages(a, b); } }
private void colorSelector1_ColorChanged(object sender, EventArgs e) { pictureBox1.BackColor = colorSelector1.Color; pictureBox2.BackColor = colorSelector1.AlphaColor; var fullColor = Color.FromArgb(colorSelector1.Alpha, colorSelector1.Color); pictureBoxCustom1.Image = BitmapExtension.FillColor(30, 30, fullColor); }
private void gammaFixToolStripMenuItem_Click(object sender, EventArgs e) { Image Image = pictureBoxCustom1.Image; if (Image != null) { UpdateEditCached(BitmapExtension.AdjustGamma(Image, 2.2f)); } }
public ImageEditorBase() { InitializeComponent(); backgroundPB.BackColor = Runtime.CustomPicureBoxBGColor; backgroundPB.Visible = false; useComponentSelectorToolStripMenuItem.Checked = Runtime.ImageEditor.UseComponetSelector; enableZoomToolStripMenuItem.Checked = Runtime.ImageEditor.EnableImageZoom; displayAlphaToolStripMenuItem.Checked = Runtime.ImageEditor.DisplayAlpha; SetAlphaEnableUI(Runtime.ImageEditor.DisplayAlpha); propertiesEditor = new ImagePropertiesEditor(); propertiesEditor.Dock = DockStyle.Fill; saveBtn.Enabled = HasBeenEdited; imageToolStripMenuItem.Enabled = false; adjustmentsToolStripMenuItem.Enabled = false; editBtn.BackgroundImage = BitmapExtension.GrayScale(Properties.Resources.Edit); foreach (var type in Enum.GetValues(typeof(Runtime.PictureBoxBG)).Cast <Runtime.PictureBoxBG>()) { imageBGComboBox.Items.Add(type); } imageBGComboBox.SelectedItem = Runtime.pictureBoxStyle; UpdateBackgroundImage(); SetZoomSetting(); SetEditorOrientation(Runtime.ImageEditor.DisplayVertical, true); previewGammaFixSmashUltimateToolStripMenuItem.Checked = Runtime.ImageEditor.PreviewGammaFix; UpdateLabel(); propertyGridToolStripMenuItem.Checked = Runtime.ImageEditor.ShowPropertiesPanel; if (!propertyGridToolStripMenuItem.Checked) { HidePropertyGrid(true); } else { HidePropertyGrid(false); } OnDataAcquiredEvent += new DataAcquired(ThreadReportsDataAquiredEvent); SetUpFileSystemWatcher(); undoToolStripMenuItem.Enabled = false; redoToolStripMenuItem.Enabled = false; }
private IEnumerable <Bitmap> EnumerateCels(string directory) { var q = Directory.EnumerateFiles(directory, "*.*", SearchOption.TopDirectoryOnly); foreach (var item in q.OrderBy(x => x)) { var bitmap = BitmapExtension.CreateOne(item); if (bitmap != null) { yield return(bitmap); } } }
private void UpdateImage() { if (activeImage == null) { return; } newImage = BitmapExtension.ResizeImage( activeImage, (int)widthUD.Value, (int)heightUD.Value, (InterpolationMode)resampleCB.SelectedItem); pictureBoxCustom1.Image = newImage; }
public MainWindow() { try { InitializeComponent(); var bitmap = BitmapExtension.SourceFromBitmap(BitmapExtension.GetBitmapFromDataAndPallette(1000, 1000, GenerateDummyArray(), new RainbowGradation().GetGradation(256, false))); img.Source = bitmap; } catch (Exception except) { throw except; } }
private void LoadImage(Bitmap Image) { TexWidth = (uint)Image.Width; TexHeight = (uint)Image.Height; MipCount = (uint)STGenericTexture.GenerateTotalMipCount(TexWidth, TexHeight); DecompressedData.Add(BitmapExtension.ImageToByte(Image)); Image.Dispose(); if (DecompressedData.Count == 0) { throw new Exception("Failed to load " + Format); } }
private void UpdateImage() { Console.WriteLine(hue); Console.WriteLine(saturation); Console.WriteLine(brightness); Thread = new Thread((ThreadStart)(() => { NewImage = BitmapExtension.HueStaturationBrightnessScale( ActiveImage, true, true, true, hue * 2, saturation, brightness); pictureBox.Image = NewImage; })); Thread.Start(); }
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(); }