Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebP Format Support #1552

Merged
merged 424 commits into from
Oct 23, 2021
Merged

Add WebP Format Support #1552

merged 424 commits into from
Oct 23, 2021

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Note: This Replaces #1271 which cannot be reopened following a force push.

This is a port of libweb for decoding and encoding webp images with ImageSharp.
It is based on libwebp

The specification for the lossless webp format can be found here lossless

The specification for the lossy format can be found here lossy

brianpopow and others added 30 commits July 25, 2020 07:49
Also looked at some TODOs in Vp8LEncoder
Added Clone and Resize to Vp8LBitWriter
Start threading the configs through the encoding and comparing results
Work out the crunch configs for lossless webp
- Distance was not copied in histogram DeepClone
- Do not remove entries from the histogram: instead set them to null like the original code
- Fix invalid upper bound in for loop of HistogramRemap
- Fix wrong palette code bits init in CalculateBestCacheSize
- Fix wrong slice start index in PrepareMapToPalette
- PixOrCopy: Change len from short to ushort
@ahysing
Copy link

ahysing commented Oct 23, 2021

Hi. It is me again

I am running this code on my (intel x86 mac) for my own projects.
At the moment this only works half way. When I compile for debug everything works as expected. However When I compile for release I get this error message.

I do dotnet build --configuration Release
and I get

CENSORED/ImageSharp/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs(78,35): error SA1000: The keyword 'new' should be followed by a space. [/Users/andreas.hysing/Mirror/code/ImageSharp/src/ImageSharp/ImageSharp.csproj]
...
    0 Warning(s)
    6 Error(s)

All the 6 messages are the same error on the same line 78 in file WebpDecoderCore.cs .

My current version the latests commit on branch webp

commit 569ad469d14b62d6960940d9894b159b4c84a893 (HEAD -> webp, origin/webp)
Merge: bc4e2f723 08f2d45a9
Author: TAKEN OUT
Date:   Fri Oct 22 18:28:22 2021 +0200

    Merge branch 'master' into webp

More context

dotnet  --list-sdks
2.2.401 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.0.101 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]
3.1.101 [/usr/local/share/dotnet/sdk]
3.1.200 [/usr/local/share/dotnet/sdk]
3.1.413 [/usr/local/share/dotnet/sdk]
3.1.414 [/usr/local/share/dotnet/sdk]
5.0.300 [/usr/local/share/dotnet/sdk]
5.0.401 [/usr/local/share/dotnet/sdk]
5.0.402 [/usr/local/share/dotnet/sdk]
dotnet --version
5.0.402
 dotnet   --list-runtimes
Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.19 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.20 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@JimBobSquarePants
Copy link
Member Author

Are your submodules set up correctly? Our CI runs on a fresh install in release mode on multiple OS without issue

@ahysing
Copy link

ahysing commented Oct 23, 2021

No. my submodules were not correctly set up.
I did as stated int the readme

git submodule update --init --recursive
Submodule path 'shared-infrastructure': checked out 'a042aba176cdb840d800c6ed4cfe41a54fb7b1e3'
mac-c02nk5cng3qd:ImageSharp andreas.hysing$ git config --system core.longpaths true
error: could not lock config file /etc/gitconfig: Permission denied
mac-c02nk5cng3qd:ImageSharp andreas.hysing$ sudo git config --system core.longpaths true
Password:

Now the same build passes through with 16 warnings 0 errors.

Thanks!

@JimBobSquarePants
Copy link
Member Author

Ace. I’ve no idea why it requires additional instruction on some machines and not others. Seems to depend on the version of git installed and the mechanism it has been installed by.

@JimBobSquarePants
Copy link
Member Author

I made a final tweak to the metadata/encoder process to ensure the same property was used for determine whether lossy or lossless encoding was to be used (and tweaked the name slightly to closer match the container spec.)

So.... Drumroll.... 🥁🥁🥁

I see no reason why we cannot merge this into master to continue to allow public testing and continue work on performance before we release V2.

Incredible work @brianpopow !! WebP is a monster of complexity but you did what you do so well and provided us with a first class port. I most definitely could not have done this.

WeAreNotWorthyGIF

@lofcz
Copy link
Contributor

lofcz commented Oct 23, 2021

Cheers on completing this @brianpopow. I've been watching this issue for a long time and the amount of work done here is beyond my understanding. This is a perfect addition to ImageSharp and I'm eager to start toying with the new features.
Thank you for all of this!
80ea13144e3f959a7a78bf222af0d35b

@brianpopow
Copy link
Collaborator

... WebP is a monster of complexity but you did what you do so well and provided us with a first class port. I most definitely could not have done this.

It really was a monster of a PR and a lot of work. I am very happy, that its merged now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebP Support
10 participants