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

[ME] WebP support #261

Merged
merged 10 commits into from
Jun 5, 2024
Merged

Conversation

RikkiBalboa
Copy link
Contributor

Reads the file signature from the bytes to determine the file format, and thus which loading method to use.
Uses code from this repo to read and convert WebP to a Texture2D

@takahiro0327
Copy link
Collaborator

@RikkiBalboa
Sorry, Can you give me the webp dll?

@RikkiBalboa
Copy link
Contributor Author

@takahiro0327 I didn't link to any external dll files. But I use the code from webp-unity3d to load them, which uses libwebp-net.

@takahiro0327
Copy link
Collaborator

@RikkiBalboa
DllNotFoundException until I added libwebp.dll.
I think I need to include this DLL somewhere?

[Error  :Modding API] System.DllNotFoundException: webp
  at (wrapper managed-to-native) WebP.Extern.NativeBindings+External.WebPGetInfo(intptr,uintptr,int&,int&)
  at WebP.Extern.NativeBindings.WebPGetInfo (System.IntPtr data, System.UIntPtr data_size, System.Int32& width, System.Int32& height) [0x00008] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at WebP.Texture2DExt.GetWebPDimensions (System.Byte[] lData, System.Int32& lWidth, System.Int32& lHeight) [0x0002d] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at WebP.Texture2DExt.CreateTexture2DFromWebP (System.Byte[] lData, System.Boolean lMipmaps, System.Boolean lLinear, WebP.Error& lError, WebP.Texture2DExt+ScalingFunction scalingFunction) [0x00013] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at KK_Plugins.TextureContainerManager.TextureFromBytes (System.Byte[] texBytes, UnityEngine.TextureFormat format, System.Boolean mipmaps) [0x000a5] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at KK_Plugins.TextureContainerManager+Token.get_Texture () [0x0001b] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at KK_Plugins.TextureContainer.get_Texture () [0x00000] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at KK_Plugins.MaterialEditor.SceneController.SetTextureWithProperty (UnityEngine.GameObject go, KK_Plugins.MaterialEditor.SceneController+MaterialTextureProperty textureProperty) [0x00041] in <9ed7f14417ec4d7ba98a8a8163adeeb6>:0 
  at (wrapper dynamic-method) KK_Plugins.MaterialEditor.SceneController.DMD<KK_Plugins.MaterialEditor.SceneController::OnSceneLoad>(KK_Plugins.MaterialEditor.SceneController,KKAPI.Studio.SaveLoad.SceneOperationKind,KKAPI.Utilities.ReadOnlyDictionary`2<int, Studio.ObjectCtrlInfo>)
  at KKAPI.Studio.SaveLoad.StudioSaveLoadApi.OnSceneBeingLoaded (KKAPI.Studio.SaveLoad.SceneOperationKind operation) [0x00053] in <6aa6736edae14b6084714249f4273e73>:0 

@RikkiBalboa
Copy link
Contributor Author

@takahiro0327 Most people I've tested it with seem to load it just fine. But from your situation it seems that isn't any sort of guarantee. So I'll look into something so it gets included (or at least fails more gracefully)

@takahiro0327
Copy link
Collaborator

Please do.

I was in the minority.
I wonder if it is included in the DLL of some famous tool.

@ManlyMarco
Copy link
Contributor

ManlyMarco commented Jun 3, 2024

I wonder if it is included in the DLL of some famous tool.

It might be included in codec packs or in certain C++ redistributables.

Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
@RikkiBalboa
Copy link
Contributor Author

@takahiro0327 Could you test if it now works for you? You need to put the newly included libwebp.lib next to where you install material editor

@takahiro0327
Copy link
Collaborator

takahiro0327 commented Jun 5, 2024

@RikkiBalboa
I made a few modifications and it worked. By the way, my environment is Windows 10.

If I had left it as it is, it would not work because the following two things did not match.

  • DllName of mono_dllmap_insert argument is “libwebp”.
  • The argument of DllImport in NativeBindings.cs is “webp”.

I changed the argument of mono_dllmap_insert to “webp” and it works.

mono_dllmap_insert(IntPtr.Zero, dllName, null, nativeLibFileName, null);
[DllImportAttribute("webp", EntryPoint = "WebPGetDecoderVersion")]
public static extern int WebPGetDecoderVersion();

How about putting this message in the log?

                throw new IOException($“Failed to load {nativeDllPath}, verify that the file exists and is not corrupted.”);

I don't know how to recover from just “failed to load libwebp”.
I don't know how many people read output_log.txt, but it would be easier to understand if the specific path to the file is shown.

@RikkiBalboa
Copy link
Contributor Author

@takahiro0327 Thanks! I missed that. It should now use the proper names, while still allowing easy extension for any other file formats in the future

@ManlyMarco ManlyMarco merged commit 298ccc6 into IllusionMods:master Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants