SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.24k stars 842 forks source link

Webp encoding produces completely transparent images #2763

Open Lovrenc opened 4 days ago

Lovrenc commented 4 days ago

Prerequisites

ImageSharp version

3.1.4

Other ImageSharp packages and versions

Not using

Environment (Operating system, version and so on)

Windows 11/Ubuntu 22.04

.NET Framework version

.net 7.0

Description

Webp encoder in some instances produces a completely transparent image (the image still has 262KB tho, so I guess the data is in there.

Attached you have a code to reproduce the issue and a sample image.

Important notes: Changing encoding quality produces a valid image. Changing the encoding method also produces a valid image (however, I found faster encoding levels tend to produce artifacts on fade-out transparencies)

Steps to Reproduce

// See https://aka.ms/new-console-template for more information

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Webp;

var path = "d:\\";
var img = Image.Load($"{path}bugged_image.png");
var encoder = new WebpEncoder()
{
    Quality = 85,
    Method = WebpEncodingMethod.Level4
};
await img.SaveAsync($"{path}bugged_image_result_direct.webp", encoder);

Images

bugged_image

JimBobSquarePants commented 3 days ago

Important notes: Changing encoding quality produces a valid image. Changing the encoding method also produces a valid image (however, I found faster encoding levels tend to produce artifacts on fade-out transparencies)

@Lovrenc Can you please give examples at which the quality works?

JimBobSquarePants commented 3 days ago

OK. This is odd...

I can replicate the issue with the v3.1.4 release NuGet package but I cannot replicate it with the release/3.1.x branch without explicitly setting the encoder to use Lossless encoding (though there are no commits changing behavior).

It appears quality between greater than 83 and less than 88 causes the issue. It's something to do with symbol generation in the VP8LEncoder but I'm not sure what is happening. @brianpopow I likely need your experience here if you have time.

Lovrenc commented 3 days ago

Important notes: Changing encoding quality produces a valid image. Changing the encoding method also produces a valid image (however, I found faster encoding levels tend to produce artifacts on fade-out transparencies)

@Lovrenc Can you please give examples at which the quality works?

Sorry I was not around.

I see you found a range.

I can confirm that values 60, 70, and 75 work, and 85 does not work; I did not test other values.

brianpopow commented 3 days ago

It appears quality between greater than 83 and less than 88 causes the issue. It's something to do with symbol generation in the VP8LEncoder but I'm not sure what is happening. @brianpopow I likely need your experience here if you have time.

@JimBobSquarePants I will take a look into this on the weekend.

JimBobSquarePants commented 1 day ago

It appears quality between greater than 83 and less than 88 causes the issue. It's something to do with symbol generation in the VP8LEncoder but I'm not sure what is happening. @brianpopow I likely need your experience here if you have time.

@JimBobSquarePants I will take a look into this on the weekend.

Thanks. I spent a few hours comparing our code to libwebp and couldn’t spot an issue.