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

Commit ae4bd059 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

ADT/Layoutlib: Reimplement parts of BitmapFactory

The original bitmap factory is mostly done in native and deals
with the normal android Bitmap class which has been replaced
in the layoutlib by a bitmap that is merely a wrapper around
an AWT BufferedImage.

This new BitmapFactory creates the layoutlib version of
Bitmap all in Java.

Change-Id: Ice8b5d19141a9a43f83349c159201bf85604b3b0
parent 1193ae4e
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package android.graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

@@ -33,6 +34,12 @@ public final class Bitmap extends _Original_Bitmap {
        mImage = ImageIO.read(input);
    }

    public Bitmap(InputStream is) throws IOException {
        super(1, true, null, -1);

        mImage = ImageIO.read(is);
    }

    Bitmap(BufferedImage image) {
        super(1, true, null, -1);
        mImage = image;
@@ -237,4 +244,35 @@ public final class Bitmap extends _Original_Bitmap {
        return createBitmap(colors, 0, width, width, height, config);
    }

    public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,
            int dstHeight, boolean filter) {
        Matrix m;
        synchronized (Bitmap.class) {
            // small pool of just 1 matrix
            m = sScaleMatrix;
            sScaleMatrix = null;
        }

        if (m == null) {
            m = new Matrix();
        }

        final int width = src.getWidth();
        final int height = src.getHeight();
        final float sx = dstWidth  / (float)width;
        final float sy = dstHeight / (float)height;
        m.setScale(sx, sy);
        Bitmap b = Bitmap.createBitmap(src, 0, 0, width, height, m, filter);

        synchronized (Bitmap.class) {
            // do we need to check for null? why not just assign everytime?
            if (sScaleMatrix == null) {
                sScaleMatrix = m;
            }
        }

        return b;
    }


}
+566 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −0

File changed.

Preview size limit exceeded, changes collapsed.