Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddf9bc76 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 4501

* changes:
  Add support to BitmapFactory for decoding a bitmap from a MemoryFile FileDescriptor.
parents 2aa30ffd 984b5df3
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.graphics;

import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.MemoryFile;
import android.util.DisplayMetrics;
import android.util.TypedValue;

@@ -435,6 +436,17 @@ public class BitmapFactory {
     * @return the decoded bitmap, or null
     */
    public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) {
        try {
            if (MemoryFile.isMemoryFile(fd)) {
                int mappedlength = MemoryFile.getMappedSize(fd);
                MemoryFile file = new MemoryFile(fd, mappedlength, "r");
                InputStream is = file.getInputStream();
                return decodeStream(is, outPadding, opts);
            }
        } catch (IOException ex) {
            // invalid filedescriptor, no need to call nativeDecodeFileDescriptor()
            return null;
        }
        return nativeDecodeFileDescriptor(fd, outPadding, opts);
    }

@@ -447,7 +459,7 @@ public class BitmapFactory {
     * @return the decoded bitmap, or null
     */
    public static Bitmap decodeFileDescriptor(FileDescriptor fd) {
        return nativeDecodeFileDescriptor(fd, null, null);
        return decodeFileDescriptor(fd, null, null);
    }

    private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,