saucecontrol / PhotoSauce

MagicScaler high-performance, high-quality image processing pipeline for .NET
http://photosauce.net/
MIT License
569 stars 49 forks source link

GIF animations with mixed disposal methods not handled correctly #114

Closed kikokuo closed 9 months ago

kikokuo commented 1 year ago

Hi, I found some gif file leak image. I using below code to handle flip and mirror. It worked great, But some gif file leak image when using library to process save or transfrom. How can I fix it or I miss some step?

PhotoSauce.MagicScaler.ProcessImageSettings processImageSettings = new()
{
    Width = gifPixelWidth,
    Height = gifPixelHeight,
    ResizeMode = PhotoSauce.MagicScaler.CropScaleMode.Stretch,
    HybridMode = PhotoSauce.MagicScaler.HybridScaleMode.Turbo
};

//Build pipeline And add orientation
using (var pl = MagicImageProcessor.BuildPipeline(m_sResourceFilePath, processImageSettings))
{
    using (var outfile = File.Create(sNewSourceFilePath))
    {
        if (IsVFlip)
            pl.AddTransform(new OrientationTransform(Orientation.FlipVertical));
        if (IsHFlip)
            pl.AddTransform(new OrientationTransform(Orientation.FlipHorizontal));              
        pl.WriteOutput(outfile);
    }
}

VS_Originals_ad778d82-0272-422b-b9fe-96940fdb35a4_resource_download image

gif save test - 2023070701 image

saucecontrol commented 1 year ago

Thanks for the repro! The sample input you've provided has an unusual mix of frame disposal methods, which is not handled correctly in MagicScaler's animation optimizer. I'll get a fix pushed for that soon.

saucecontrol commented 9 months ago

Thanks again for the report. The issue was quite a bit more complicated than I expected (I had made some invalid assumptions in my initial implementation), but it's finally fixed in 11e96cc