Imagesharp: Image got pink blur after resize

Created on 4 Jul 2019  路  12Comments  路  Source: SixLabors/ImageSharp

Prerequisites

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

Description

When resize a screenshot from iPhone X or XS max, the resized image will get pink blur:

resized_image_got_pink_blur

This is the code I used to resize the image:

    public Stream CreateThumbnailForImage(Stream imageStream, int estimatedThumbnailWith)
    {
        try
        {
            Stream thumbnailStream = new MemoryStream((int)imageStream.Length);
            thumbnailStream.Position = 0;

            using (Image<Rgba32> image = Image.Load(imageStream))
            {
                var thumbnailRate = GetThumbnailRate(image.Width, estimatedThumbnailWith);

                image.Mutate(x => x
                     .Resize(image.Width / thumbnailRate, image.Height / thumbnailRate, true));

                imageStream.Position = 0;
                var imageFormat = Image.DetectFormat(imageStream);
                if (imageFormat != null)
                {
                    image.Save(thumbnailStream, imageFormat);
                }
                else
                {
                    image.Save(thumbnailStream, new JpegEncoder());
                }

            }

            thumbnailStream.Position = 0;
            return thumbnailStream;
        }
        catch (Exception ex)
        {

            return null;
        }


    }

    private  int GetThumbnailRate(int originailWidth, int estimatedThumbnailWith)
    {
        var thumbnailRate = originailWidth / estimatedThumbnailWith;
        if (thumbnailRate == 0)
        {
            thumbnailRate = 1;
        }

        return thumbnailRate;
    }

On the other hand, if resize a iPhone 6s's screenshot, the result will be okay.

Steps to Reproduce

  • Take a screen shot from iPhone X or (XS max)
  • Upload image to BlogStorage (use REST API)
  • Azure WebService will download image stream and resize image, then upload resized image to BlobStorage

System Configuration

  • ImageSharp version: 1.0.0-beta0006
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Azure WebService
  • .NET Framework version: ASP .Net Core 2.0.0
  • Additional information:

Most helpful comment

I think i have tracked down the commit which introduced the issue: [e2651e7]
Before that commit it works: [07ec6511]

Its hard to understand why this particular commit triggers this pink issue. My first thought was that maybe a different version of System.Runtime.CompilerServices.Unsafe could be the reason, but the mentioned commit does not change the version. Also i have tried version '4.5.2' and the latest preview version, both do not change the pink issue.

If any one has an idea what i could try to identify the cause of this, let me know.

All 12 comments

Try the latest dev builds. I think you are suffering from an obscure issue we found that was affecting certain chipsets

Yeah, might be a duplicate of #871. Let us know. @vuthainam let us know if the latest dev build works correctly!

@vuthainam How did you get on with the latest build?

@vuthainam How did you get on with the latest build?

Sorry for late response. I tried to get the latest dev version but the 'pink blur' issue sill happen when save an image by PNG encoder (image source from iPhone X or iphone XS max, running environment is Azure WebService)
The strange thing is: if running environment is local IIS, image that encoded by PNG encoder will be fine.
On the other hand, when use JPG encoder to save image, the result will be fine too (on both Azure or Local machine)

@antonfirsov I think there is a regression in the library.

Using the version 1.0.0-dev002709 (base on discussions in #871) I get correct images on a raspberry pi (resizing jpegs).

But the latest myget (1.0.0-dev002762) has the pink blur again.

i can confirm that, the pink thing is back in the master branch.

edit:
A little bit more info. Im using again the arm32 docker image to reproduce it. It is enough to load an image and then save it to reproduce it.
The issue seems to only happen with JPG. Saving as PNG or BMP works fine.

Some good news: I have tried .NET Core 3.0 Preview and this issue does not happen anymore.

I have used the following build image: mcr.microsoft.com/dotnet/core/sdk:3.0-bionic
And this runtime: mcr.microsoft.com/dotnet/core/runtime:3.0-bionic-arm32v7

The release of .net core 3.0 is just around the corner, i think it will be next month.

Some good news: I have tried .NET Core 3.0 Preview and this issue does not happen anymore.

Well that's a silver lining at least.

We'll have to see what has changed in between 1.0.0-dev002709 and 1.0.0-dev002762 within the jpeg encoding pipeline to figure out what has happened.

image

I think i have tracked down the commit which introduced the issue: [e2651e7]
Before that commit it works: [07ec6511]

Its hard to understand why this particular commit triggers this pink issue. My first thought was that maybe a different version of System.Runtime.CompilerServices.Unsafe could be the reason, but the mentioned commit does not change the version. Also i have tried version '4.5.2' and the latest preview version, both do not change the pink issue.

If any one has an idea what i could try to identify the cause of this, let me know.

Yeah but it's definitely rooted in a CLR bug. We probably won't be able to fix it, and will suggest updating to .NET Core 3.0 for ARM users.

@vuthainam I just realized, that I completely missed that you are running in Azure Web Service. You are not using ImageSharp in your iOS app, right? What is the ProcessorArchitecture within your service?

Since .NET Core 2.0 is now out of support and .NET Core 3.0 is released @brianpopow confirmed the problem to be gone there I'm going to close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JimBobSquarePants picture JimBobSquarePants  路  3Comments

FelixLeChat picture FelixLeChat  路  3Comments

marcpabst picture marcpabst  路  3Comments

jarroda picture jarroda  路  3Comments

Inumedia picture Inumedia  路  3Comments