mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Matrix memory optimisations
This commit is contained in:
@@ -26,8 +26,6 @@ namespace GHelper.AnimeMatrix
|
||||
private long lastPresent;
|
||||
private List<double> maxes = new List<double>();
|
||||
|
||||
private MemoryStream ms = new MemoryStream();
|
||||
|
||||
public AniMatrixControl(SettingsForm settingsForm)
|
||||
{
|
||||
settings = settingsForm;
|
||||
@@ -317,18 +315,21 @@ namespace GHelper.AnimeMatrix
|
||||
try
|
||||
{
|
||||
using (var fs = new FileStream(fileName, FileMode.Open))
|
||||
//using (var ms = new MemoryStream())
|
||||
{
|
||||
/*
|
||||
ms.SetLength(0);
|
||||
fs.CopyTo(ms);
|
||||
ms.Position = 0;
|
||||
|
||||
using (Image image = Image.FromStream(ms))
|
||||
*/
|
||||
using (Image image = Image.FromStream(fs))
|
||||
{
|
||||
ProcessPicture(image);
|
||||
Logger.WriteLine("Matrix " + fileName);
|
||||
if (visualise) settings.VisualiseMatrix(image);
|
||||
}
|
||||
|
||||
fs.Close();
|
||||
if (visualise) settings.VisualiseMatrix(fileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -347,6 +348,8 @@ namespace GHelper.AnimeMatrix
|
||||
int matrixX = AppConfig.Get("matrix_x", 0);
|
||||
int matrixY = AppConfig.Get("matrix_y", 0);
|
||||
int matrixZoom = AppConfig.Get("matrix_zoom", 100);
|
||||
int matrixSpeed = AppConfig.Get("matrix_speed", 50);
|
||||
|
||||
InterpolationMode matrixQuality = (InterpolationMode)AppConfig.Get("matrix_quality", 0);
|
||||
|
||||
|
||||
@@ -367,7 +370,7 @@ namespace GHelper.AnimeMatrix
|
||||
|
||||
|
||||
Logger.WriteLine("GIF Delay:" + frameDelay);
|
||||
StartMatrixTimer(Math.Max(50, frameDelay));
|
||||
StartMatrixTimer(Math.Max(matrixSpeed, frameDelay));
|
||||
|
||||
//image.SelectActiveFrame(dimension, 0);
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace GHelper
|
||||
|
||||
private float uiScale;
|
||||
|
||||
Image picture;
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
public Matrix()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -55,9 +58,11 @@ namespace GHelper
|
||||
|
||||
private void Matrix_FormClosed(object? sender, FormClosingEventArgs e)
|
||||
{
|
||||
if (pictureMatrix.Image is not null) pictureMatrix.Image.Dispose();
|
||||
if (picture is not null) picture.Dispose();
|
||||
if (ms is not null) ms.Dispose();
|
||||
|
||||
pictureMatrix.Dispose();
|
||||
Dispose();
|
||||
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
|
||||
}
|
||||
|
||||
@@ -157,10 +162,20 @@ namespace GHelper
|
||||
Left = Program.settingsForm.Left - Width - 5;
|
||||
}
|
||||
|
||||
public void VisualiseMatrix(Image picture)
|
||||
public void VisualiseMatrix(string fileName)
|
||||
{
|
||||
|
||||
if (pictureMatrix.Image is not null) pictureMatrix.Image.Dispose();
|
||||
if (picture is not null) picture.Dispose();
|
||||
|
||||
using (var fs = new FileStream(fileName, FileMode.Open))
|
||||
{
|
||||
|
||||
ms.SetLength(0);
|
||||
fs.CopyTo(ms);
|
||||
ms.Position = 0;
|
||||
fs.Close();
|
||||
|
||||
picture = Image.FromStream(ms);
|
||||
|
||||
int width = picture.Width;
|
||||
int height = picture.Height;
|
||||
@@ -182,7 +197,13 @@ namespace GHelper
|
||||
pictureMatrix.Top = baseY - (int)(matrixY * uiScale);
|
||||
|
||||
pictureMatrix.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
pictureMatrix.Image = (Image)picture.Clone();
|
||||
pictureMatrix.Image = picture;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace GHelper
|
||||
}
|
||||
}
|
||||
|
||||
public void VisualiseMatrix(Image image)
|
||||
public void VisualiseMatrix(string image)
|
||||
{
|
||||
if (matrix == null || matrix.Text == "") return;
|
||||
matrix.VisualiseMatrix(image);
|
||||
|
||||
Reference in New Issue
Block a user