WebP-wrapper icon indicating copy to clipboard operation
WebP-wrapper copied to clipboard

wrapper code for decoding animated webp

Open thomas694 opened this issue 2 years ago • 1 comments

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 avatar Oct 17 '22 18:10 thomas694

here is a preview: wrapper code for animated WebP files

thomas694 avatar Oct 23 '22 17:10 thomas694