Skip to content

Commit

Permalink
Fix leak and transfer fix from Slimviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Nov 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2cbbbf8 commit 1414096
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions Imaging/ImageGifHandler.cs
Original file line number Diff line number Diff line change
@@ -31,33 +31,47 @@ public static ImageGifInfo GetImageInfo(string path)
{
var info = new ImageGifInfo();

using var image = Image.FromFile(path);
info.Height = image.Height;
info.Width = image.Width;
info.Name = Path.GetFileName(path);
info.Size = image.Size;

if (!image.RawFormat.Equals(ImageFormat.Gif))
try
{
return null;
}
using var image = Image.FromFile(path);
info.Height = image.Height;
info.Width = image.Width;
info.Name = Path.GetFileName(path);
info.Size = image.Size;

if (!ImageAnimator.CanAnimate(image))
{
return info;
}
if (!image.RawFormat.Equals(ImageFormat.Gif))
{
return null;
}

if (!ImageAnimator.CanAnimate(image))
{
return info;
}

var frameDimension = new FrameDimension(image.FrameDimensionsList[0]);
var frameDimension = new FrameDimension(image.FrameDimensionsList[0]);

var frameCount = image.GetFrameCount(frameDimension);
var frameCount = image.GetFrameCount(frameDimension);

info.AnimationLength = frameCount / 10 * frameCount;
info.AnimationLength = frameCount / 10 * frameCount;

info.IsAnimated = true;
info.IsAnimated = true;

info.IsLooped = BitConverter.ToInt16(image.GetPropertyItem(20737)?.Value!, 0) != 1;
info.IsLooped = BitConverter.ToInt16(image.GetPropertyItem(20737)?.Value!, 0) != 1;

info.Frames = frameCount;
info.Frames = frameCount;
}
catch (OutOfMemoryException ex)
{
var currentProcess = Process.GetCurrentProcess();
var memorySize = currentProcess.PrivateMemorySize64;

Trace.WriteLine(string.Concat(ex, ImagingResources.Separator, ImagingResources.ErrorMemory,
memorySize));

//enforce clean up and hope for the best
GC.Collect();
}

return info;
}

0 comments on commit 1414096

Please sign in to comment.