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

Commit 9c0bd864 authored by Santosh Madhava's avatar Santosh Madhava Committed by Android (Google) Code Review
Browse files

Merge "Review rework on Patch Set 2 for issue 3372849" into honeycomb

parents c6a0944c 6bcbb3bd
Loading
Loading
Loading
Loading
+72 −9
Original line number Original line Diff line number Diff line
@@ -30,6 +30,9 @@ import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.view.Surface;
import android.view.Surface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;


/**
/**
 *This class provide Native methods to be used by MediaArtist {@hide}
 *This class provide Native methods to be used by MediaArtist {@hide}
@@ -67,7 +70,10 @@ class MediaArtistNativeHelper {
    private boolean mExportDone = false;
    private boolean mExportDone = false;


    private int mProgressToApp;
    private int mProgressToApp;

    /**
     *  The resize paint
     */
    private static final Paint sResizePaint = new Paint(Paint.FILTER_BITMAP_FLAG);


    public static final int TASK_LOADING_SETTINGS = 1;
    public static final int TASK_LOADING_SETTINGS = 1;


@@ -3838,11 +3844,39 @@ class MediaArtistNativeHelper {
            throw new IllegalArgumentException();
            throw new IllegalArgumentException();
        }
        }


        IntBuffer rgb888 = IntBuffer.allocate(width * height * 4);
        int newWidth = 0;
        int newHeight = 0;
        Bitmap tempBitmap = null;

        /* Make width and height as even */
        newWidth = (width + 1) & 0xFFFFFFFE;
        newHeight = (height + 1) & 0xFFFFFFFE;

        /* Create a temp bitmap for resized thumbnails */
        if ((newWidth != width) || (newHeight != height)) {
             tempBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
        }

        IntBuffer rgb888 = IntBuffer.allocate(newWidth * newHeight * 4);
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        nativeGetPixels(inputFile, rgb888.array(), width, height, timeMS);
        nativeGetPixels(inputFile, rgb888.array(), newWidth, newHeight, timeMS);

        if ((newWidth == width) && (newHeight == height)) {
            bitmap.copyPixelsFromBuffer(rgb888);
            bitmap.copyPixelsFromBuffer(rgb888);
        } else {
            /* Create a temp bitmap to be used for resize */
            tempBitmap.copyPixelsFromBuffer(rgb888);

            /* Create a canvas to resize */
            final Canvas canvas = new Canvas(bitmap);
            canvas.drawBitmap(tempBitmap, new Rect(0, 0, newWidth, newHeight),
                                          new Rect(0, 0, width, height),
                                          sResizePaint);
        }


        if (tempBitmap != null) {
            tempBitmap.recycle();
        }
        return bitmap;
        return bitmap;
    }
    }


@@ -3863,11 +3897,24 @@ class MediaArtistNativeHelper {
    public Bitmap[] getPixelsList(String filename, int width, int height, long startMs, long endMs,
    public Bitmap[] getPixelsList(String filename, int width, int height, long startMs, long endMs,
            int thumbnailCount) {
            int thumbnailCount) {
        int[] rgb888 = null;
        int[] rgb888 = null;
        int thumbnailSize = width * height * 4;
        int thumbnailSize = 0;
        int newWidth = 0;
        int newHeight = 0;
        Bitmap tempBitmap = null;

        /* Make width and height as even */
        newWidth = (width + 1) & 0xFFFFFFFE;
        newHeight = (height + 1) & 0xFFFFFFFE;
        thumbnailSize = newWidth * newHeight * 4;


        /* Create a temp bitmap for resized thumbnails */
        if ((newWidth != width) || (newHeight != height)) {
            tempBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);
        }
        int i = 0;
        int i = 0;
        int deltaTime = (int)(endMs - startMs) / thumbnailCount;
        int deltaTime = (int)(endMs - startMs) / thumbnailCount;
        Bitmap[] bitmap = null;
        Bitmap[] bitmap = null;

        try {
        try {
            // This may result in out of Memory Error
            // This may result in out of Memory Error
            rgb888 = new int[thumbnailSize * thumbnailCount];
            rgb888 = new int[thumbnailSize * thumbnailCount];
@@ -3880,19 +3927,35 @@ class MediaArtistNativeHelper {
                bitmap = new Bitmap[MAX_THUMBNAIL_PERMITTED];
                bitmap = new Bitmap[MAX_THUMBNAIL_PERMITTED];
                thumbnailCount = MAX_THUMBNAIL_PERMITTED;
                thumbnailCount = MAX_THUMBNAIL_PERMITTED;
            } catch (Throwable ex) {
            } catch (Throwable ex) {
                throw new RuntimeException("Memory allocation fails,reduce nos of thumbanail count");
                throw new RuntimeException("Memory allocation fails, thumbnail count too large: "+thumbnailCount);
            }
            }
        }
        }
        IntBuffer tmpBuffer = IntBuffer.allocate(thumbnailSize);
        IntBuffer tmpBuffer = IntBuffer.allocate(thumbnailSize);
        nativeGetPixelsList(filename, rgb888, width, height, deltaTime, thumbnailCount, startMs,
        nativeGetPixelsList(filename, rgb888, newWidth, newHeight, deltaTime, thumbnailCount, startMs,
                endMs);
                endMs);

        for (; i < thumbnailCount; i++) {
        for (; i < thumbnailCount; i++) {
            bitmap[i] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            bitmap[i] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            tmpBuffer.put(rgb888, (i * thumbnailSize), thumbnailSize);
            tmpBuffer.put(rgb888, (i * thumbnailSize), thumbnailSize);
            tmpBuffer.rewind();
            tmpBuffer.rewind();

            if ((newWidth == width) && (newHeight == height)) {
                bitmap[i].copyPixelsFromBuffer(tmpBuffer);
                bitmap[i].copyPixelsFromBuffer(tmpBuffer);
            } else {
                /* Copy the out rgb buffer to temp bitmap */
                tempBitmap.copyPixelsFromBuffer(tmpBuffer);

                /* Create a canvas to resize */
                final Canvas canvas = new Canvas(bitmap[i]);
                canvas.drawBitmap(tempBitmap, new Rect(0, 0, newWidth, newHeight),
                                              new Rect(0, 0, width, height),
                                              sResizePaint);
            }
        }
        }


        if (tempBitmap != null) {
            tempBitmap.recycle();
        }
        return bitmap;
        return bitmap;
    }
    }


+13 −2
Original line number Original line Diff line number Diff line
@@ -1013,9 +1013,20 @@ public class MediaImageItem extends MediaItem {


            if (dx > dy) {
            if (dx > dy) {
                bitmapWidth = width;
                bitmapWidth = width;
                bitmapHeight = Math.round(nativeHeight / dx);

                if (((float)nativeHeight / dx) < (float)height) {
                    bitmapHeight = (float)Math.ceil(nativeHeight / dx);
                } else { // value equals the requested height
                    bitmapHeight = (float)Math.floor(nativeHeight / dx);
                }

            } else {
            } else {
                bitmapWidth = Math.round(nativeWidth / dy);
                if (((float)nativeWidth / dy) > (float)width) {
                    bitmapWidth = (float)Math.floor(nativeWidth / dy);
                } else { // value equals the requested width
                    bitmapWidth = (float)Math.ceil(nativeWidth / dy);
                }

                bitmapHeight = height;
                bitmapHeight = height;
            }
            }