diff options
author | Santosh Madhava <smadhava@google.com> | 2011-01-24 22:45:57 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-01-24 22:45:57 -0800 |
commit | 5386fd807716835e41ca9475a6fde7560dc4fcd0 (patch) | |
tree | 53b540f8b19bd6f7b3692e2d93942264eabce443 /media/java | |
parent | 3aa78c96a7c363508929f7d4ef5a8f49b54a5251 (diff) | |
parent | a1ec9893b8fd2aa0e499261323d9fe7ad115d915 (diff) | |
download | frameworks_base-5386fd807716835e41ca9475a6fde7560dc4fcd0.zip frameworks_base-5386fd807716835e41ca9475a6fde7560dc4fcd0.tar.gz frameworks_base-5386fd807716835e41ca9475a6fde7560dc4fcd0.tar.bz2 |
am a1ec9893: am 9c0bd864: Merge "Review rework on Patch Set 2 for issue 3372849" into honeycomb
* commit 'a1ec9893b8fd2aa0e499261323d9fe7ad115d915':
Review rework on Patch Set 2 for issue 3372849
Diffstat (limited to 'media/java')
-rwxr-xr-x | media/java/android/media/videoeditor/MediaArtistNativeHelper.java | 81 | ||||
-rwxr-xr-x | media/java/android/media/videoeditor/MediaImageItem.java | 15 |
2 files changed, 85 insertions, 11 deletions
diff --git a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java index 77b7dc8..271e9dd 100755 --- a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java +++ b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java @@ -30,6 +30,9 @@ import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; import android.util.Log; import android.util.Pair; 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} @@ -67,7 +70,10 @@ class MediaArtistNativeHelper { private boolean mExportDone = false; 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; @@ -3838,11 +3844,39 @@ class MediaArtistNativeHelper { 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); - nativeGetPixels(inputFile, rgb888.array(), width, height, timeMS); - bitmap.copyPixelsFromBuffer(rgb888); + nativeGetPixels(inputFile, rgb888.array(), newWidth, newHeight, timeMS); + + if ((newWidth == width) && (newHeight == height)) { + 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; } @@ -3863,11 +3897,24 @@ class MediaArtistNativeHelper { public Bitmap[] getPixelsList(String filename, int width, int height, long startMs, long endMs, int thumbnailCount) { 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 deltaTime = (int)(endMs - startMs) / thumbnailCount; Bitmap[] bitmap = null; + try { // This may result in out of Memory Error rgb888 = new int[thumbnailSize * thumbnailCount]; @@ -3880,19 +3927,35 @@ class MediaArtistNativeHelper { bitmap = new Bitmap[MAX_THUMBNAIL_PERMITTED]; thumbnailCount = MAX_THUMBNAIL_PERMITTED; } 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); - nativeGetPixelsList(filename, rgb888, width, height, deltaTime, thumbnailCount, startMs, + nativeGetPixelsList(filename, rgb888, newWidth, newHeight, deltaTime, thumbnailCount, startMs, endMs); + for (; i < thumbnailCount; i++) { bitmap[i] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); tmpBuffer.put(rgb888, (i * thumbnailSize), thumbnailSize); tmpBuffer.rewind(); - bitmap[i].copyPixelsFromBuffer(tmpBuffer); + + if ((newWidth == width) && (newHeight == height)) { + 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; } diff --git a/media/java/android/media/videoeditor/MediaImageItem.java b/media/java/android/media/videoeditor/MediaImageItem.java index 1c02878..a977b8e 100755 --- a/media/java/android/media/videoeditor/MediaImageItem.java +++ b/media/java/android/media/videoeditor/MediaImageItem.java @@ -1013,9 +1013,20 @@ public class MediaImageItem extends MediaItem { if (dx > dy) { 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 { - 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; } |