Skip to content

PlatformNotSupportedException thrown when resizing an image on Ubuntu #1546

Description

@QuantumToasted

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

When attempting to call the IImageProcessingContext#Resize() extension method, the following exception is thrown:

SixLabors.ImageSharp.ImageProcessingException: An error occurred when processing the image using ResizeProcessor`1. See the inner exception for more detail.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Runtime.Intrinsics.X86.Avx2.PermuteVar8x32(Vector256`1 left, Vector256`1 control)
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeWorker`1.CalculateFirstPassValues(RowInterval calculationInterval)
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeWorker`1.Initialize()
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeProcessor`1.ApplyResizeFrameTransform(Configuration configuration, ImageFrame`1 source, ImageFrame`1 destination, ResizeKernelMap horizontalKernelMap, ResizeKernelMap verticalKernelMap, Rectangle sourceRectangle, Rectangle destinationRectangle, Rectangle interest, Boolean compand, Boolean premultiplyAlpha)
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeProcessor`1.ApplyTransform[TResampler](TResampler& sampler)
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeProcessor`1.SixLabors.ImageSharp.Processing.Processors.Transforms.IResamplingTransformImageProcessor<TPixel>.ApplyTransform[TResampler](TResampler& sampler)
   at SixLabors.ImageSharp.Processing.Processors.Transforms.ResizeProcessor`1.BeforeImageApply(Image`1 destination)
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.ICloningImageProcessor<TPixel>.CloneAndExecute()
   --- End of inner exception stack trace ---
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.ICloningImageProcessor<TPixel>.CloneAndExecute()
   at SixLabors.ImageSharp.Processing.Processors.CloningImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.IImageProcessor<TPixel>.Execute()
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
   at SixLabors.ImageSharp.Processing.DefaultImageProcessorContext`1.ApplyProcessor(IImageProcessor processor)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, ResizeOptions options)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height, IResampler sampler, Rectangle targetRectangle, Boolean compand)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height, IResampler sampler, Boolean compand)
   at SixLabors.ImageSharp.Processing.ResizeExtensions.Resize(IImageProcessingContext source, Int32 width, Int32 height)
   at Administrator.Services.LevelService.<>c__DisplayClass6_1.<CreateXpImageAsync>b__5(IImageProcessingContext x) in C:\Users\Daniel Jarski\source\repos\Administrator\Administrator\Services\LevelService.cs:line 102
   at SixLabors.ImageSharp.Processing.ProcessingExtensions.Mutate[TPixel](Image`1 source, Configuration configuration, Action`1 operation)
   at SixLabors.ImageSharp.Processing.ProcessingExtensions.Mutate[TPixel](Image`1 source, Action`1 operation)

This exception is not thrown on Windows in Debug mode, but is thrown on Linux in Release mode. I have not checked Windows/Release and Linux/Debug. See the System Configuration section for details regarding my system information.

Steps to Reproduce

The code which throws this error can be found starting here. Lines 82, 132, 189, 244, and 252 contain a .Resize() call. Please do note that I have not pushed my current working code to github in a long time, so line numbers in the exception may not match the line numbers on github, and neither will the versions installed in the .csproj; but I can assure you the method itself has not changed.

System Configuration

  • ImageSharp version: 1.0.3-alpha.0.35
  • Other ImageSharp packages and versions: ImageSharp.Drawing 1.0.0-beta11.4
  • Environment (Operating system, version and so on): Ubuntu 20.04 x64
  • .NET Framework version: 5.0
  • Additional information: CPU: AMD FX-4350

Activity

  1. brianpopow commented on Feb 13, 2021

    @brianpopow
    Collaborator

    It seems the AMD FX-4350 has only support for FMA, but not for AVX2. We only check for FMA in the resize kernel. We should also check for AVX2 there.

  2. JimBobSquarePants commented on Feb 13, 2021

    @JimBobSquarePants
    Member

    @QuantumToasted fancy raising a PR?

  3. added a commit that references this issue on Feb 13, 2021
    86112ff
  4. brianpopow commented on Feb 13, 2021

    @brianpopow
    Collaborator

    @QuantumToasted fancy raising a PR?

    Im already on it. Seems the ResizeKernel it is the only place where FMA and AVX are needed together.

  5. JimBobSquarePants commented on Feb 13, 2021

    @JimBobSquarePants
    Member
  6. QuantumToasted commented on Feb 13, 2021

    @QuantumToasted
    Author

    I had a strange feeling it had something to do with my CPU, iI'm glad I included it. When googling related exceptions and the method which is throwing the exception, I came across stuff mentioning that the method was somehow related to CPU vender-specific optimizations...whether or not that is actually the case, it made me think it had more to do with my CPU than the fact I was on Linux.

  7. antonfirsov commented on Feb 13, 2021

    @antonfirsov
    Member

    @QuantumToasted I'm very happy you found this in the alpha, and the bug did not go out to NuGet!

  8. added a commit that references this issue on Mar 13, 2021
    de19199
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions