looooong / unityasyncimageloader Goto Github PK
View Code? Open in Web Editor NEWAsynchronous Image Loader for Unity
License: MIT License
Asynchronous Image Loader for Unity
License: MIT License
Could you add performance tests?
See here : https://github.com/studentutu/AsyncLoadTexture
It is based on Unity WebRequest - texture loading via request, where you can pass local file instead of the URL.
It works for all kinds of images and resolutions. Tested on 2K, 512512, 6464
I am a bit confused about how to load OpenEXR Images or if it is supported. Currently I used either LoadImage
or CreateFromImage
either with automatic loader settings or specific, but the returned data is all white.
Texture size seem correct.
Also, I'm wondering about reading these values as RGBAFloat or RGBAHalf. Is it supported?
Here is the same thing with all the tests but using pure Unity methods - https://github.com/studentutu/AsyncLoadTexture
We have used it extensively - it works on all platforms, regardless of content.
For some reason after using this image loader into a texture when applied to a sprite has a little transparency across the entire image. I'm not sure if its the texture itself or the way unity utilizes it differently than using the built in editor texture importer. I don't know how to configure it in a way that stops this from happening.
![Updow
When trying to load an image using AsyncImageLoader.LoadImageAsync with default LoaderSettings, I get the following error:
"InvalidOperationException: The writeable UNKNOWN_OBJECT_TYPE FilterMipmapJob.outputMipmap is the same UNKNOWN_OBJECT_TYPE as FilterMipmapJob.inputMipmap, two containers may not be the same (aliasing)."
It seems to be related to the jobs that are creating the mipmaps.
I can workaround the issue by disabling mipmap generation.
Unity Version: 2021.2.0b4.3123 Personal
@Looooong I get the following error when calling CreateFromImageAsync from a thread:
UnityException: SupportsTextureFormatNative can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Unity 2020.3.1. AFAIK it's impossible to create a new Texture2D on anything but the main thread? Though that seems to render this whole repo useless, which I hope isn't the case cuz it looks GREAT otherwise!
Here's the full stack trace:
UnityException: SupportsTextureFormatNative can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.EditorSystemInfo.SupportsTextureFormat (UnityEngine.TextureFormat format) (at <10564ed154d647e194bef4aef8878649>:0)
UnityEngine.SystemInfoShimBase.SupportsTextureFormat (UnityEngine.TextureFormat format) (at <10564ed154d647e194bef4aef8878649>:0)
UnityEngine.SystemInfo.SupportsTextureFormat (UnityEngine.TextureFormat format) (at <10564ed154d647e194bef4aef8878649>:0)
UnityEngine.Texture.ValidateFormat (UnityEngine.TextureFormat format) (at <10564ed154d647e194bef4aef8878649>:0)
UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Int32 mipCount, System.Boolean linear, System.IntPtr nativeTex) (at <10564ed154d647e194bef4aef8878649>:0)
UnityEngine.Texture2D..ctor (System.Int32 width, System.Int32 height, UnityEngine.TextureFormat textureFormat, System.Int32 mipCount, System.Boolean linear) (at <10564ed154d647e194bef4aef8878649>:0)
AsyncImageLoader+ImageImporter+<CreateNewTextureAsync>d__17.MoveNext () (at Assets/UnityAsyncImageLoader/Runtime/ImageImporter.cs:100)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <eae584ce26bc40229c1b1aa476bfa589>:0)
AsyncImageLoader+<CreateFromImageAsync>d__9.MoveNext () (at Assets/UnityAsyncImageLoader/Runtime/AsyncImageLoader.cs:105)
UnityEngine.Debug:LogException(Exception)
<CreateFromImageAsync>d__9:MoveNext() (at Assets/UnityAsyncImageLoader/Runtime/AsyncImageLoader.cs:108)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()
and the method I'm calling it from:
private static async Task<Texture2D> ByteArrayToTexture2D(byte[] bytes)
{
return await AsyncImageLoader.CreateFromImageAsync(bytes);
}
In your library, you implemented a solution to load image asynchronously from byte array.
Could you suggest a way for asynchronous encoding a texture to PNG or other formats?
I get this error running your example script code.
I'm testing with 8192 png and jpg textures.
The error happens in TransferBGR24ImageToRGB24TextureJob -> Execute
Unity 2022.2.14
It would be great if the interface didn't take plain byte arrays. The reason being that you can't really allocate those easily from a block based system. Memory on the other hand is wrapper (like Span<>) around parts of memory that can be passed around between functions and stored in fields/properties. It supports pinning just like basic arrays do and byte[] should just be convertible to Memory so users of your library shouldn't be impacted by the API change.
I'm using, await AsyncImageLoader.LoadImageAsync(tex, byteArray); and it loads the correct texture and is greatly increasing performance but the main issue is sometimes the texture loads as completely black for 1 frame and it happens multiple times every second causing the texture to blink. I'm not simply loading a static texture but instead loading a series of textures that play a video. Any thoughts on what might be causing this?
video of the issue:
https://user-images.githubusercontent.com/91104156/204570541-7a66809b-432d-443b-95a1-705793665cbe.mp4
Missing libraries for MacOS. Using the precompiled ones from homebrew doesn't seem to work. Any guidance on where to obtain them and how to modify the scripts to get it to work?
i am running webgl, and found this error
DllNotFoundException: FreeImage assembly: type: member:(null)
does it work on webgl?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.