JosePineiro / WebP-wrapper

Wrapper for libwebp in C#. The most complete wapper in pure managed C#. Exposes Simple Decoding API, Simple Encoding API, Advanced Encoding API (with stadistis of compresion), Get version library and WebPGetFeatures (info of any WebP file). In the future I´ll update for expose Advanced Decoding API. The wapper are in safe managed code in one class. No need external dll except libwebp.dll (included). The wapper work in 32 and 64 bit system.
MIT License
213 stars 48 forks source link

wrapper code for decoding animated webp #36

Open thomas694 opened 2 years ago

thomas694 commented 2 years ago

Hello,

I'd like to contribute wrapper code for the WebPAnimDecoder API to enable decoding of Animated WebP files.

For that to work it needs the WebP DLL libwebpdemux.dll that depends on libwebp.dll. But sticking to the current way the auto switch is done and naming the file libwebpdemux_x64.dll doesn't work, because it expects to find the dependency with its original file name. One solution is to move the files to subfolders and specify them in the DllImport attributes:

[DllImport(@"x64\libwebp.dll"]
[DllImport(@"x64\libwebpdemux.dll"]

It works and also the dependencies can be loaded. But maybe not the best solution.

The second solution uses the fact that DLLs aren't loaded into the process again if they have already been loaded before. So we can just preload the DLLs from the correct subfolder:

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), IntPtr.Size == 4 ? "x86" : "x64");
LoadLibrary(Path.Combine(path, "libwebp.dll"));
LoadLibrary(Path.Combine(path, "libwebpdemux.dll"));

Would that be okay for you?

So first I'd like to create a PR to rename and move the DLLs to the respective subfolders.

Besides, are there any special reasons why the 32- and 64-bit version of libwebp.dll aren't used in the same version (number)?

thomas694 commented 2 years ago

here is a preview: wrapper code for animated WebP files