Update the channel view properly on another thread after process is finished
This commit is contained in:
parent
c8b77411fa
commit
470b0ead75
.vs/Switch_Toolbox/v15
Switch_FileFormatsMain/obj/Release
Switch_Toolbox_Library/Forms/Editors/ImageEditor
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -212,7 +212,7 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
{
|
{
|
||||||
isFinished = value;
|
isFinished = value;
|
||||||
|
|
||||||
if (isFinished == true)
|
if (isFinished == true && CurrentChannelIndex == 0)
|
||||||
{
|
{
|
||||||
LoadChannelEditor(pictureBoxCustom1.Image);
|
LoadChannelEditor(pictureBoxCustom1.Image);
|
||||||
}
|
}
|
||||||
@ -239,8 +239,12 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
|
|
||||||
public event DataAcquired OnDataAcquiredEvent;
|
public event DataAcquired OnDataAcquiredEvent;
|
||||||
|
|
||||||
|
private bool DecodeProcessFinished = false; //Used to determine when the decode process is done
|
||||||
|
|
||||||
private void UpdatePictureBox(int ChannelIndex = 0)
|
private void UpdatePictureBox(int ChannelIndex = 0)
|
||||||
{
|
{
|
||||||
|
DecodeProcessFinished = false;
|
||||||
|
|
||||||
PushImage(Properties.Resources.LoadingImage);
|
PushImage(Properties.Resources.LoadingImage);
|
||||||
|
|
||||||
var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel);
|
var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel);
|
||||||
@ -263,6 +267,7 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DecodeProcessFinished = true;
|
||||||
|
|
||||||
// BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel);
|
// BitmapExtension.SetChannels(image, HasRedChannel, HasBlueChannel, HasGreenChannel, HasAlphaChannel);
|
||||||
PushImage(image);
|
PushImage(image);
|
||||||
@ -280,6 +285,10 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
pictureBoxCustom1.Image = image;
|
pictureBoxCustom1.Image = image;
|
||||||
|
pictureBoxCustom1.Refresh();
|
||||||
|
|
||||||
|
if (DecodeProcessFinished)
|
||||||
|
IsFinished = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,8 +296,12 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
{
|
{
|
||||||
pictureBoxCustom1.Image = (Image)sender;
|
pictureBoxCustom1.Image = (Image)sender;
|
||||||
pictureBoxCustom1.Refresh();
|
pictureBoxCustom1.Refresh();
|
||||||
|
|
||||||
|
if (DecodeProcessFinished)
|
||||||
|
IsFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CurrentChannelIndex;
|
||||||
|
|
||||||
bool IsCancelled = false;
|
bool IsCancelled = false;
|
||||||
public void UpdateMipDisplay()
|
public void UpdateMipDisplay()
|
||||||
@ -313,10 +326,10 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
TotalArrayCount = ActiveTexture.ArrayCount - 1;
|
TotalArrayCount = ActiveTexture.ArrayCount - 1;
|
||||||
|
|
||||||
|
|
||||||
int ChannelIndex = 0;
|
CurrentChannelIndex = 0;
|
||||||
|
|
||||||
if (propertiesEditor != null && propertiesEditor.channelListView.SelectedIndices.Count > 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")
|
if (this.Thread != null && this.Thread.IsAlive && Thread.ThreadState.ToString() != "AbortRequested")
|
||||||
{
|
{
|
||||||
@ -325,7 +338,7 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
|
|
||||||
Thread = new Thread((ThreadStart)(() =>
|
Thread = new Thread((ThreadStart)(() =>
|
||||||
{
|
{
|
||||||
UpdatePictureBox(ChannelIndex);
|
UpdatePictureBox(CurrentChannelIndex);
|
||||||
}));
|
}));
|
||||||
Thread.Start();
|
Thread.Start();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ using System.Drawing.Imaging;
|
|||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Switch_Toolbox.Library.Forms
|
namespace Switch_Toolbox.Library.Forms
|
||||||
@ -25,6 +25,12 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
channelListView.BackColor = FormThemes.BaseTheme.FormBackColor;
|
channelListView.BackColor = FormThemes.BaseTheme.FormBackColor;
|
||||||
channelListView.ForeColor = FormThemes.BaseTheme.FormForeColor;
|
channelListView.ForeColor = FormThemes.BaseTheme.FormForeColor;
|
||||||
channelListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
|
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 List<TabPage> tempPages = new List<TabPage>();
|
||||||
public void AddTabPage(UserControl control, Type type)
|
public void AddTabPage(UserControl control, Type type)
|
||||||
@ -80,25 +86,48 @@ namespace Switch_Toolbox.Library.Forms
|
|||||||
{
|
{
|
||||||
imageEditor = editor;
|
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.Clear();
|
||||||
imgList.Images.Add(image);
|
imgList.ImageSize = new Size(65, 65);
|
||||||
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.ColorDepth = ColorDepth.Depth32Bit;
|
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.FullRowSelect = true;
|
||||||
channelListView.SmallImageList = imgList;
|
channelListView.SmallImageList = imgList;
|
||||||
channelListView.Items.Add("RGBA", 0);
|
}
|
||||||
channelListView.Items.Add("Red", 1);
|
|
||||||
channelListView.Items.Add("Green", 2);
|
private void LoadImage(Bitmap image)
|
||||||
channelListView.Items.Add("Blue", 3);
|
{
|
||||||
channelListView.Items.Add("Alpha", 4);
|
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)
|
private void redPB_Click(object sender, EventArgs e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user