mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.53k stars 541 forks source link

[BUG] Failed to decode png image #2874

Open MichaelLogutov opened 5 months ago

MichaelLogutov commented 5 months ago

Description

I've noticed that we have some decode issues in our app with some PNG images. For example this one: temp

It's loading fine in OS (Windows 11), but consistently failed to be loaded with SKBitmap.Decode (it returns null).

I've tried 3.0.0-preview.3.1 version and 2.88.8. This issue exists both on Windows 11 and in Linux containers with NET 8.

Code

using var bitmap = SKBitmap.Decode(@"c:\Temp\temp.png");
if (bitmap is null)
    Console.WriteLine("Failed to load image");

Expected Behavior

Image loaded successfully.

Actual Behavior

SKBitmap.Decode returns null.

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Other (Please indicate in the description)

Platform / Operating System

Linux, Windows

Platform / Operating System Version

Windows 11

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

MichaelLogutov commented 5 months ago

Is there any way I can diagnose that kind of problems and maybe direct bug to skia?

mattleibow commented 5 months ago

Skia is pretty secretive about the errors, but maybe you can try reading the file and properties using SKCodec. If that reads, then try reading the pixel data and see if it fails.

Also, is it possible to attach the image in a zip file? GitHub process images and usually changes metadata which may be important.

Can you also try SKImage? I wonder if there is something bad with bitmap.

MichaelLogutov commented 5 months ago

Tried with SKCodec with this:

using var codec = SKCodec.Create(@"c:\Temp\temp.png");
if (codec is null)
    Console.WriteLine("Failed to get codec for image");
else
    Console.WriteLine("GetPixels = {0}", codec.GetPixels(out _));

Result:

GetPixels = ErrorInInput

Here is image in zip: temp.zip

Can you also try SKImage? I wonder if there is something bad with bitmap.

You mean SKImage.FromBitmap ?

JimBobSquarePants commented 5 months ago

The PNG above contains a CRC mismatch in the IEND chunk. Does Skia expose options for determining whether validation is required?

MichaelLogutov commented 5 months ago

@JimBobSquarePants good question. It seems that skia in chrome browser somehow ignores CRC mismatch, so maybe there is a way.

Btw, how did you managed to find about CRC mismatch?

JimBobSquarePants commented 4 months ago

Btw, how did you managed to find about CRC mismatch?

I used ImageSharp 😉