saucecontrol / PhotoSauce

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

Native png encoder not working in 14.1 #155

Closed andreas-eriksson closed 4 months ago

andreas-eriksson commented 4 months ago

I have a small benchmark that stopped working after updating from 14.0 to 14.1/14.2 There seems to be a problem with the native png encoder.

using BenchmarkDotNet.Attributes;
using PhotoSauce.MagicScaler;
using PhotoSauce.NativeCodecs.Libjpeg;
using PhotoSauce.NativeCodecs.Libpng;

namespace Test.Benchmarks;

[MemoryDiagnoser]
public class MagicScalerBenchmarks
{    
    [Benchmark]
    public void Crash()
    {
        CodecManager.Configure(codecs =>
        {            
            codecs.UseLibpng();
        });

        var settings = new ProcessImageSettings
        {
            Width = 400
        };
        settings.TrySetEncoderFormat("image/png");

        MagicImageProcessor.ProcessImage("image.png", new MemoryStream(), settings);
    }
}
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.MissingMethodException: Method not found: 'System.Drawing.Rectangle PhotoSauce.MagicScaler.PixelArea.op_Implicit(PhotoSauce.MagicScaler.PixelArea ByRef)'.
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.writePixels(IPixelSource src, PixelArea area)
   at PhotoSauce.NativeCodecs.Libpng.PngEncoder.WriteFrame(IPixelSource source, IMetadataSource metadata, Rectangle sourceArea)
   at PhotoSauce.MagicScaler.MagicImageProcessor.WriteOutput(PipelineContext ctx, Stream ostm)
   at PhotoSauce.MagicScaler.MagicImageProcessor.ProcessImage(String imgPath, Stream outStream, ProcessImageSettings settings)
saucecontrol commented 4 months ago

That would be the result of using an older codec version. You need to update all codec plugins when you update the main library, as they use some internal APIs that are not stable between releases.

andreas-eriksson commented 4 months ago

Ahh, I forgot about them as they are available as preview versions. Sorry about that.