am 231a0005: Merge "Avoid allocating buffer every time getThumbnail is called." into gingerbread
Merge commit '231a0005654d23284ab58a2d9ea892b995988c34' into gingerbread-plus-aosp * commit '231a0005654d23284ab58a2d9ea892b995988c34': Avoid allocating buffer every time getThumbnail is called.
This commit is contained in:
@@ -249,6 +249,8 @@ public final class MediaStore {
|
|||||||
private static final int MICRO_KIND = 3;
|
private static final int MICRO_KIND = 3;
|
||||||
private static final String[] PROJECTION = new String[] {_ID, MediaColumns.DATA};
|
private static final String[] PROJECTION = new String[] {_ID, MediaColumns.DATA};
|
||||||
static final int DEFAULT_GROUP_ID = 0;
|
static final int DEFAULT_GROUP_ID = 0;
|
||||||
|
private static final Object sThumbBufLock = new Object();
|
||||||
|
private static byte[] sThumbBuf;
|
||||||
|
|
||||||
private static Bitmap getMiniThumbFromFile(Cursor c, Uri baseUri, ContentResolver cr, BitmapFactory.Options options) {
|
private static Bitmap getMiniThumbFromFile(Cursor c, Uri baseUri, ContentResolver cr, BitmapFactory.Options options) {
|
||||||
Bitmap bitmap = null;
|
Bitmap bitmap = null;
|
||||||
@@ -321,13 +323,17 @@ public final class MediaStore {
|
|||||||
long magic = thumbFile.getMagic(origId);
|
long magic = thumbFile.getMagic(origId);
|
||||||
if (magic != 0) {
|
if (magic != 0) {
|
||||||
if (kind == MICRO_KIND) {
|
if (kind == MICRO_KIND) {
|
||||||
byte[] data = new byte[MiniThumbFile.BYTES_PER_MINTHUMB];
|
synchronized (sThumbBufLock) {
|
||||||
if (thumbFile.getMiniThumbFromFile(origId, data) != null) {
|
if (sThumbBuf == null) {
|
||||||
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
sThumbBuf = new byte[MiniThumbFile.BYTES_PER_MINTHUMB];
|
||||||
|
}
|
||||||
|
if (thumbFile.getMiniThumbFromFile(origId, sThumbBuf) != null) {
|
||||||
|
bitmap = BitmapFactory.decodeByteArray(sThumbBuf, 0, sThumbBuf.length);
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
Log.w(TAG, "couldn't decode byte array.");
|
Log.w(TAG, "couldn't decode byte array.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return bitmap;
|
return bitmap;
|
||||||
} else if (kind == MINI_KIND) {
|
} else if (kind == MINI_KIND) {
|
||||||
String column = isVideo ? "video_id=" : "image_id=";
|
String column = isVideo ? "video_id=" : "image_id=";
|
||||||
@@ -357,13 +363,17 @@ public final class MediaStore {
|
|||||||
|
|
||||||
// Assuming thumbnail has been generated, at least original image exists.
|
// Assuming thumbnail has been generated, at least original image exists.
|
||||||
if (kind == MICRO_KIND) {
|
if (kind == MICRO_KIND) {
|
||||||
byte[] data = new byte[MiniThumbFile.BYTES_PER_MINTHUMB];
|
synchronized (sThumbBufLock) {
|
||||||
if (thumbFile.getMiniThumbFromFile(origId, data) != null) {
|
if (sThumbBuf == null) {
|
||||||
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
sThumbBuf = new byte[MiniThumbFile.BYTES_PER_MINTHUMB];
|
||||||
|
}
|
||||||
|
if (thumbFile.getMiniThumbFromFile(origId, sThumbBuf) != null) {
|
||||||
|
bitmap = BitmapFactory.decodeByteArray(sThumbBuf, 0, sThumbBuf.length);
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
Log.w(TAG, "couldn't decode byte array.");
|
Log.w(TAG, "couldn't decode byte array.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (kind == MINI_KIND) {
|
} else if (kind == MINI_KIND) {
|
||||||
if (c.moveToFirst()) {
|
if (c.moveToFirst()) {
|
||||||
bitmap = getMiniThumbFromFile(c, baseUri, cr, options);
|
bitmap = getMiniThumbFromFile(c, baseUri, cr, options);
|
||||||
|
|||||||
Reference in New Issue
Block a user