From a57936c01c12ec0eadd12e0d5d57cc9ff0ff0d68 Mon Sep 17 00:00:00 2001 From: n00mkrad <61149547+n00mkrad@users.noreply.github.com> Date: Sun, 14 Dec 2025 15:27:46 +0100 Subject: [PATCH] Update pkgs with vulnerabilities, remove some unused code --- CodeLegacy/App.config | 4 + CodeLegacy/Flowframes.csproj | 17 ++- CodeLegacy/IO/IoUtils.cs | 13 ++- CodeLegacy/Magick/Converter.cs | 145 -------------------------- CodeLegacy/Magick/MagickExtensions.cs | 52 --------- CodeLegacy/Magick/SceneDetect.cs | 94 ----------------- CodeLegacy/packages.config | 6 +- 7 files changed, 24 insertions(+), 307 deletions(-) delete mode 100644 CodeLegacy/Magick/Converter.cs delete mode 100644 CodeLegacy/Magick/SceneDetect.cs diff --git a/CodeLegacy/App.config b/CodeLegacy/App.config index a6f4ff3..9a6587c 100644 --- a/CodeLegacy/App.config +++ b/CodeLegacy/App.config @@ -32,6 +32,10 @@ + + + + diff --git a/CodeLegacy/Flowframes.csproj b/CodeLegacy/Flowframes.csproj index 594e049..37bbf4e 100644 --- a/CodeLegacy/Flowframes.csproj +++ b/CodeLegacy/Flowframes.csproj @@ -122,11 +122,11 @@ packages\HTAlt.Standart.0.1.6\lib\netstandard2.0\HTAlt.Standart.dll - - packages\Magick.NET-Q8-x64.13.10.0\lib\netstandard20\Magick.NET-Q8-x64.dll + + packages\Magick.NET-Q8-x64.14.10.0\lib\netstandard20\Magick.NET-Q8-x64.dll - - packages\Magick.NET.Core.13.10.0\lib\netstandard20\Magick.NET.Core.dll + + packages\Magick.NET.Core.14.10.0\lib\netstandard20\Magick.NET.Core.dll packages\Microsoft.Build.Framework.15.9.20\lib\net46\Microsoft.Build.Framework.dll @@ -154,7 +154,7 @@ packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll - packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll packages\NvAPIWrapper.Net.0.8.1.101\lib\net45\NvAPIWrapper.dll @@ -473,7 +473,6 @@ - @@ -518,7 +517,6 @@ - @@ -547,6 +545,7 @@ BatchForm.cs + Designer BigPreviewForm.cs @@ -665,7 +664,7 @@ - + @@ -677,5 +676,5 @@ - + \ No newline at end of file diff --git a/CodeLegacy/IO/IoUtils.cs b/CodeLegacy/IO/IoUtils.cs index 5cc4860..94b4fbd 100644 --- a/CodeLegacy/IO/IoUtils.cs +++ b/CodeLegacy/IO/IoUtils.cs @@ -39,13 +39,18 @@ namespace Flowframes.IO { try { - MagickImage img = new MagickImage(path); - Bitmap bitmap = img.ToBitmap(); - if (log) Logger.Log($"GetImage: Native image reading for '{Path.GetFileName(path)}' failed - Using Magick.NET fallback instead.", true); - return bitmap; + MagickImage img = new MagickImage(path); + // Bitmap bitmap = img.ToBitmap(); + img.Format = MagickFormat.Bmp; + + using (var memStream = new MemoryStream()) + { + img.Write(memStream); + return new Bitmap(memStream); + } } catch (Exception e) { diff --git a/CodeLegacy/Magick/Converter.cs b/CodeLegacy/Magick/Converter.cs deleted file mode 100644 index 409e918..0000000 --- a/CodeLegacy/Magick/Converter.cs +++ /dev/null @@ -1,145 +0,0 @@ -using Flowframes; -using Flowframes.IO; -using Flowframes.Ui; -using ImageMagick; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Flowframes.Magick -{ - - class Converter - { - public static async Task Convert (string dir, MagickFormat format, int quality, string ext = "", bool print = true, bool setProgress = true) - { - var files = IoUtils.GetFilesSorted(dir); - if(print) Logger.Log($"Converting {files.Length} files in {dir}"); - int counter = 0; - foreach (string file in files) - { - if (print) Logger.Log("Converting " + Path.GetFileName(file) + " to " + format.ToString().StripNumbers().Upper(), false, true); - MagickImage img = new MagickImage(file); - img.Format = format; - img.Quality = quality; - string outpath = file; - if (!string.IsNullOrWhiteSpace(ext)) outpath = Path.ChangeExtension(outpath, ext); - img.Write(outpath); - counter++; - if(setProgress) - Program.mainForm.SetProgress((int)Math.Round(((float)counter / files.Length) * 100f)); - await Task.Delay(1); - } - } - - public static async Task MakeBinary (string inputDir, string outputDir, bool print = true, bool setProgress = true) - { - try - { - var files = IoUtils.GetFilesSorted(inputDir); - if (print) Logger.Log($"Processing alpha channel..."); - Directory.CreateDirectory(outputDir); - Stopwatch sw = new Stopwatch(); - sw.Restart(); - int counter = 0; - foreach (string file in files) - { - MagickImage img = new MagickImage(file); - img.Format = MagickFormat.Png24; - img.Quality = 10; - img.Threshold(new Percentage(75)); - - string outPath = Path.Combine(outputDir, Path.GetFileName(file)); - img.Write(outPath); - counter++; - if (sw.ElapsedMilliseconds > 250) - { - if (setProgress) - Program.mainForm.SetProgress((int)Math.Round(((float)counter / files.Length) * 100f)); - await Task.Delay(1); - sw.Restart(); - } - } - } - catch (Exception e) - { - Logger.Log("MakeBinary Error: " + e.Message); - } - } - - public static async Task ExtractAlpha (string inputDir, string outputDir, bool print = true, bool setProgress = true, bool removeInputAlpha = true) - { - try - { - var files = IoUtils.GetFilesSorted(inputDir); - if (print) Logger.Log($"Extracting alpha channel from images..."); - Directory.CreateDirectory(outputDir); - Stopwatch sw = new Stopwatch(); - sw.Restart(); - int counter = 0; - foreach (string file in files) - { - MagickImage alphaImg = new MagickImage(file); - - if (removeInputAlpha) - { - MagickImage rgbImg = alphaImg; - rgbImg.Format = MagickFormat.Png24; - rgbImg.Quality = 10; - MagickImage bg = new MagickImage(MagickColors.Black, rgbImg.Width, rgbImg.Height); - bg.Composite(rgbImg, CompositeOperator.Over); - rgbImg = bg; - rgbImg.Write(file); - } - - alphaImg.Format = MagickFormat.Png24; - alphaImg.Quality = 10; - - alphaImg.FloodFill(MagickColors.None, 0, 0); // Fill the image with a transparent background - alphaImg.InverseOpaque(MagickColors.None, MagickColors.White); // Change all the pixels that are not transparent to white. - alphaImg.ColorAlpha(MagickColors.Black); // Change the transparent pixels to black. - - string outPath = Path.Combine(outputDir, Path.GetFileName(file)); - alphaImg.Write(outPath); - counter++; - if (sw.ElapsedMilliseconds > 250) - { - if (setProgress) - Program.mainForm.SetProgress((int)Math.Round(((float)counter / files.Length) * 100f)); - await Task.Delay(1); - sw.Restart(); - } - } - } - catch (Exception e) - { - Logger.Log("ExtractAlpha Error: " + e.Message); - } - } - - public static async Task Preprocess (string dir, bool setProgress = true) - { - var files = IoUtils.GetFilesSorted(dir); - Logger.Log($"Preprocessing {files} files in {dir}"); - int counter = 0; - foreach (string file in files) - { - //Logger.Log("Converting " + Path.GetFileName(file) + " to " + format, false, true); - MagickImage img = new MagickImage(file); - //img.Format = MagickFormat.Bmp; - //img.Write(file); - //img = new MagickImage(file); - img.Format = MagickFormat.Png24; - img.Quality = 10; - counter++; - if (setProgress) - Program.mainForm.SetProgress((int)Math.Round(((float)counter / files.Length) * 100f)); - await Task.Delay(1); - } - } - } -} diff --git a/CodeLegacy/Magick/MagickExtensions.cs b/CodeLegacy/Magick/MagickExtensions.cs index 3f52783..cfcac69 100644 --- a/CodeLegacy/Magick/MagickExtensions.cs +++ b/CodeLegacy/Magick/MagickExtensions.cs @@ -30,58 +30,6 @@ namespace Flowframes.Magick public static class MagickExtensions { [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "False positive.")] - public static Bitmap ToBitmap(this MagickImage magickImg, BitmapDensity density) - { - string mapping = "BGR"; - var format = PixelFormat.Format24bppRgb; - - var image = magickImg; - - try - { - if (image.ColorSpace != ColorSpace.sRGB) - { - image = (MagickImage)magickImg.Clone(); - image.ColorSpace = ColorSpace.sRGB; - } - - if (image.HasAlpha) - { - mapping = "BGRA"; - format = PixelFormat.Format32bppArgb; - } - - using (var pixels = image.GetPixelsUnsafe()) - { - var bitmap = new Bitmap(image.Width, image.Height, format); - var data = bitmap.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, format); - var destination = data.Scan0; - - for (int y = 0; y < image.Height; y++) - { - byte[] bytes = pixels.ToByteArray(0, y, image.Width, 1, mapping); - Marshal.Copy(bytes, 0, destination, bytes.Length); - - destination = new IntPtr(destination.ToInt64() + data.Stride); - } - - bitmap.UnlockBits(data); - SetBitmapDensity(magickImg, bitmap, density); - - return bitmap; - } - } - finally - { - if (!ReferenceEquals(image, magickImg)) - image.Dispose(); - } - } - - public static Bitmap ToBitmap(this MagickImage imageMagick) => ToBitmap(imageMagick, BitmapDensity.Ignore); - - public static Bitmap ToBitmap(this MagickImage imageMagick, ImageFormat imageFormat) => ToBitmap(imageMagick, imageFormat, BitmapDensity.Ignore); - public static Bitmap ToBitmap(this MagickImage imageMagick, ImageFormat imageFormat, BitmapDensity bitmapDensity) { imageMagick.Format = InternalMagickFormatInfo.GetFormat(imageFormat); diff --git a/CodeLegacy/Magick/SceneDetect.cs b/CodeLegacy/Magick/SceneDetect.cs deleted file mode 100644 index a90d069..0000000 --- a/CodeLegacy/Magick/SceneDetect.cs +++ /dev/null @@ -1,94 +0,0 @@ -using Flowframes.IO; -using ImageMagick; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Flowframes.Magick -{ - class SceneDetect - { - public static async Task RunSceneDetection (string path) - { - string outFolder = path + "-analyzed"; - Directory.CreateDirectory(outFolder); - string ext = "png"; - FileInfo[] frames = IoUtils.GetFileInfosSorted(path, false, "*." + ext); - - for (int i = 1; i < frames.Length; i++) - { - FileInfo frame = frames[i]; - FileInfo lastFrame = frames[i - 1]; - Task.Run(() => ProcessFrame(frame, lastFrame, outFolder)); - } - } - - public static Dictionary imageCache = new Dictionary(); - static MagickImage GetImage(string path, bool allowCaching = true) - { - if (!allowCaching) - return new MagickImage(path); - - if (imageCache.Count >= 30) - ClearCache(); - - if (!imageCache.ContainsKey(path)) - imageCache.Add(path, new MagickImage(path)); - - return imageCache[path]; - } - - public static void ClearCache() - { - imageCache.Clear(); - } - - static async Task ProcessFrame (FileInfo frame, FileInfo lastFrame, string outFolder) - { - MagickImage prevFrame = GetImage(lastFrame.FullName, false); - MagickImage currFrame = GetImage(frame.FullName, false); - - Size originalSize = new Size(currFrame.Width, currFrame.Height); - int downscaleHeight = 144; - prevFrame.Scale(currFrame.Width / (currFrame.Height / downscaleHeight), downscaleHeight); - currFrame.Scale(currFrame.Width / (currFrame.Height / downscaleHeight), downscaleHeight); - - double errNormalizedCrossCorrelation = currFrame.Compare(prevFrame, ErrorMetric.NormalizedCrossCorrelation); - double errRootMeanSquared = currFrame.Compare(prevFrame, ErrorMetric.RootMeanSquared); - - string str = $"\nMetrics of {frame.Name.Split('.')[0]} against {lastFrame.Name.Split('.')[0]}:\n"; - str += $"NormalizedCrossCorrelation: {errNormalizedCrossCorrelation.ToString("0.000")}\n"; - str += $"RootMeanSquared: {errRootMeanSquared.ToString("0.000")}\n"; - str += "\n\n"; - - bool nccTrigger = errNormalizedCrossCorrelation < 0.45f; - bool rMeanSqrTrigger = errRootMeanSquared > 0.18f; - bool rmsNccTrigger = errRootMeanSquared > 0.18f && errNormalizedCrossCorrelation < 0.6f; - bool nccRmsTrigger = errNormalizedCrossCorrelation < 0.45f && errRootMeanSquared > 0.11f; - - if (rmsNccTrigger) str += "\n\nRMS -> NCC DOUBLE SCENE CHANGE TRIGGER!"; - if (nccRmsTrigger) str += "\n\nNCC -> RMS DOUBLE SCENE CHANGE TRIGGER!"; - - currFrame.Scale(originalSize.Width / 2, originalSize.Height / 2); - - new Drawables() - .FontPointSize(12) - .Font("Consolas", FontStyleType.Normal, FontWeight.Bold, FontStretch.Normal) - .FillColor(MagickColors.Red) - .TextAlignment(TextAlignment.Left) - .Text(1, 10, str) - .Draw(currFrame); - - currFrame.Write(Path.Combine(outFolder, frame.Name)); - - prevFrame.Dispose(); - currFrame.Dispose(); - - await Task.Delay(1); - } - } -} diff --git a/CodeLegacy/packages.config b/CodeLegacy/packages.config index 6db76b2..818ffe8 100644 --- a/CodeLegacy/packages.config +++ b/CodeLegacy/packages.config @@ -10,8 +10,8 @@ - - + + @@ -21,7 +21,7 @@ - +