ImageLoader - native extension for JPG and PNG

I’ve made a new extension!

There is png extension by @britzl and image.load() function available in Defold, but they don’t provide what I need.

image.load() is not suitable for game objects, because it’s not using a buffer object, required by resource.set_texture(). png extension can’t load jpg files and can’t load in async mode.

My new extension can load JPG, PNG and a bunch of other formats. It’s based on stb_image.h and they state they support

  JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
  PNG 1/2/4/8/16-bit-per-channel
  TGA (not sure what subset, if a subset)
  BMP non-1bpp, non-RLE
  PSD (composited view only, no extra channels, 8/16 bit-per-channel)
  GIF (*comp always reports as 4-channel)
  HDR (radiance rgbE format)
  PIC (Softimage PIC)
  PNM (PPM and PGM binary only)

And it can process image files on a separate thread, improving overall performance.

The project on GitHub is also a sample project.

Why would you need such extension? To load and display images downloaded from the Internet. Remember that you have to place redownloadable items such as web images into Caches directory on mobile devices. To access this directory you can use my directories extension https://defold.com/assets/extensiondirectories/

20 Likes

There is an issue has been discovered. When async mode is used, it could crash the app. Hopefully, a fix in the engine is coming soon - DEF-3761.

In the meantime, you can use no_async = true when invoking the extension with a listener.

1 Like

Now that we can make UVs at runtime, I want to be able to dynamically download a list of images and put them into a texture atlas and generate the UVs for them too so that they can be used as sprites. Will post any progress.

@sergey.lerg do you have any thoughts on this? Has anyone already made a helper module to do this?

In the past I got this working by abusing tile sheets since they all had the same size, and it was only useful for GUIs to reduce drawcalls of user pfps at the time.

1 Like

Something like this one? Packing an atlas at runtime

3 Likes

Exactly what I was hoping for thank you!

1 Like