1
0
mirror of synced 2025-01-31 04:13:51 +01:00

Update the channel view properly on another thread after process is finished

This commit is contained in:
KillzXGaming 2019-03-24 12:51:26 -04:00
parent c8b77411fa
commit 470b0ead75
6 changed files with 60 additions and 18 deletions

Binary file not shown.

View File

@ -212,7 +212,7 @@ namespace Switch_Toolbox.Library.Forms
{
isFinished = value;
if (isFinished == true)
if (isFinished == true && CurrentChannelIndex == 0)
{
LoadChannelEditor(pictureBoxCustom1.Image);
}
@ -239,8 +239,12 @@ namespace Switch_Toolbox.Library.Forms
public event DataAcquired OnDataAcquiredEvent;
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);
@ -263,6 +267,7 @@ namespace Switch_Toolbox.Library.Forms
}
}
DecodeProcessFinished = true;
// BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel);
PushImage(image);
@ -280,6 +285,10 @@ namespace Switch_Toolbox.Library.Forms
else
{
pictureBoxCustom1.Image = image;
pictureBoxCustom1.Refresh();
if (DecodeProcessFinished)
IsFinished = true;
}
}
@ -287,8 +296,12 @@ namespace Switch_Toolbox.Library.Forms
{
pictureBoxCustom1.Image = (Image)sender;
pictureBoxCustom1.Refresh();
if (DecodeProcessFinished)
IsFinished = true;
}
public int CurrentChannelIndex;
bool IsCancelled = false;
public void UpdateMipDisplay()
@ -313,10 +326,10 @@ namespace Switch_Toolbox.Library.Forms
TotalArrayCount = ActiveTexture.ArrayCount - 1;
int ChannelIndex = 0;
CurrentChannelIndex = 0;
if (propertiesEditor != null && propertiesEditor.channelListView.SelectedIndices.Count > 0)
ChannelIndex = propertiesEditor.channelListView.SelectedIndices[0];
CurrentChannelIndex = propertiesEditor.channelListView.SelectedIndices[0];
if (this.Thread != null && this.Thread.IsAlive && Thread.ThreadState.ToString() != "AbortRequested")
{
@ -325,7 +338,7 @@ namespace Switch_Toolbox.Library.Forms
Thread = new Thread((ThreadStart)(() =>
{
UpdatePictureBox(ChannelIndex);
UpdatePictureBox(CurrentChannelIndex);
}));
Thread.Start();

View File

@ -7,7 +7,7 @@ using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
namespace Switch_Toolbox.Library.Forms
@ -25,6 +25,12 @@ namespace Switch_Toolbox.Library.Forms
channelListView.BackColor = FormThemes.BaseTheme.FormBackColor;
channelListView.ForeColor = FormThemes.BaseTheme.FormForeColor;
channelListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
channelListView.Items.Add("RGBA", 0);
channelListView.Items.Add("Red", 1);
channelListView.Items.Add("Green", 2);
channelListView.Items.Add("Blue", 3);
channelListView.Items.Add("Alpha", 4);
}
public List<TabPage> tempPages = new List<TabPage>();
public void AddTabPage(UserControl control, Type type)
@ -80,25 +86,48 @@ namespace Switch_Toolbox.Library.Forms
{
imageEditor = editor;
var image = picBoxImg;
//Resize texture to hopefully prevent slow loading
var image = BitmapExtension.Resize(picBoxImg, 65, 65);
channelListView.Items.Clear();
imgList.Images.Clear();
imgList.Images.Add(image);
imgList.Images.Add(BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Red));
imgList.Images.Add(BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Green));
imgList.Images.Add(BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Blue));
imgList.Images.Add(BitmapExtension.ShowChannel(new Bitmap(image), STChannelType.Alpha));
imgList.ImageSize = new Size(65,65);
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;
channelListView.Items.Add("RGBA", 0);
channelListView.Items.Add("Red", 1);
channelListView.Items.Add("Green", 2);
channelListView.Items.Add("Blue", 3);
channelListView.Items.Add("Alpha", 4);
}
private void LoadImage(Bitmap image)
{
if (channelListView.InvokeRequired)
{
channelListView.Invoke((MethodInvoker)delegate {
// Running on the UI thread
imgList.Images.Add(image);
var dummy = imgList.Handle;
channelListView.Refresh();
});
}
}
private void redPB_Click(object sender, EventArgs e)