Przeglądaj źródła

Un-deprecate AndroidBufferImageLoader (#1660)

* Un-deprecate AndroidBufferImageLoader.

* Android.cfg: registered AndroidBufferImageLoader to be used for loading WebP & HEIF images.
Ali-RS 3 lat temu
rodzic
commit
62cc918aac

+ 12 - 3
jme3-android/src/main/java/com/jme3/texture/plugins/AndroidBufferImageLoader.java

@@ -41,17 +41,18 @@ import com.jme3.texture.Image;
 import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.BufferedInputStream;
 import java.nio.ByteBuffer;
 
 /**
  * Loads textures using Android's Bitmap class, but does not have the 
  * RGBA8 alpha bug.
+ *
+ * See below link for supported image formats:
+ * https://developer.android.com/guide/topics/media/media-formats#image-formats
  * 
  * @author Kirill Vainer
  */
-@Deprecated
 public class AndroidBufferImageLoader implements AssetLoader {
     
     private final byte[] tempData = new byte[16 * 1024];
@@ -83,7 +84,15 @@ public class AndroidBufferImageLoader implements AssetLoader {
         options.inInputShareable = true;
         options.inPurgeable = true;
         options.inSampleSize = 1;
-        
+        // Do not premultiply alpha channel as it is not intended
+        // to be directly drawn by the android view system.
+        options.inPremultiplied = false;
+
+        // TODO: It is more GC friendly to reuse the Bitmap class instead of recycling
+        //  it on every image load. Android has introduced inBitmap option For this purpose.
+        //  However, there are certain restrictions with how inBitmap can be used.
+        //  See https://developer.android.com/topic/performance/graphics/manage-memory#inBitmap.
+
         try (final BufferedInputStream bin = new BufferedInputStream(assetInfo.openStream())) {
             bitmap = BitmapFactory.decodeStream(bin, null, options);
             if (bitmap == null) {

+ 0 - 2
jme3-android/src/main/java/com/jme3/texture/plugins/AndroidNativeImageLoader.java

@@ -40,8 +40,6 @@ import java.io.InputStream;
 
 /**
  * Native image loader to deal with filetypes that support alpha channels.
- * The Android Bitmap class premultiplies the channels by the alpha when
- * loading.  This loader does not.
  *
  * @author iwgeric
  * @author Kirill Vainer

+ 1 - 0
jme3-android/src/main/resources/com/jme3/asset/Android.cfg

@@ -5,4 +5,5 @@ LOCATOR / com.jme3.asset.plugins.AndroidLocator
 
 # Android specific loaders
 LOADER com.jme3.texture.plugins.AndroidNativeImageLoader : jpg, bmp, gif, png, jpeg
+LOADER com.jme3.texture.plugins.AndroidBufferImageLoader : webp, heic, heif
 LOADER com.jme3.audio.plugins.NativeVorbisLoader : ogg