Skip to content

Commit

Permalink
Re-implemented decoding lock
Browse files Browse the repository at this point in the history
  • Loading branch information
DHuckaby committed Nov 10, 2012
1 parent 794845f commit 16275a6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/src/com/handlerexploit/prime/utils/ImageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public final class ImageManager {

private static final String TAG = "ImageManager";

private static Object LOCK = new Object();

private static ImageManager sInstance;

private final String mCacheDirectory;
Expand Down Expand Up @@ -346,7 +348,10 @@ private static BitmapFactory.Options decodeSampleSize(InputStream inputStream, E
int width = request.getWidth();
if (height > 0 && width > 0) {
bitmapFactoryOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, bitmapFactoryOptions);

synchronized (LOCK) {
BitmapFactory.decodeStream(inputStream, null, bitmapFactoryOptions);
}

int heightRatio = (int) Math.ceil(bitmapFactoryOptions.outHeight / (float) height);
int widthRatio = (int) Math.ceil(bitmapFactoryOptions.outWidth / (float) width);
Expand All @@ -366,7 +371,10 @@ private static BitmapFactory.Options decodeSampleSize(InputStream inputStream, E

private static Bitmap decodeInputStream(InputStream inputStream, ExtendedRequest request, BitmapFactory.Options bitmapFactoryOptions) {
try {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream, null, bitmapFactoryOptions);
Bitmap bitmap = null;
synchronized (LOCK) {
bitmap = BitmapFactory.decodeStream(inputStream, null, bitmapFactoryOptions);
}
if (request != null) {
bitmap = request.onPreProcess(bitmap);
}
Expand Down

0 comments on commit 16275a6

Please sign in to comment.