Skip to content

Commit 65b75a0

Browse files
committed
If the whole image is required at native resolution, use BitmapDecoder to decode it for better image format support
1 parent e6a9d21 commit 65b75a0

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

library/src/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ public class SubsamplingScaleImageView extends View {
136136
// Specifies if a cache handler is also referencing the bitmap. Do not recycle if so.
137137
private boolean bitmapIsCached;
138138

139+
// Uri of full size image
140+
private Uri uri;
141+
139142
// Sample size used to display the whole image when fully zoomed out
140143
private int fullImageSampleSize;
141144

@@ -403,12 +406,12 @@ public final void setImage(ImageSource imageSource, ImageSource previewSource, I
403406
} else if (imageSource.getBitmap() != null) {
404407
onImageLoaded(imageSource.getBitmap(), ORIENTATION_0, imageSource.isCached());
405408
} else {
406-
this.sRegion = imageSource.getSRegion();
407-
Uri uri = imageSource.getUri();
409+
sRegion = imageSource.getSRegion();
410+
uri = imageSource.getUri();
408411
if (uri == null && imageSource.getResource() != null) {
409412
uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getContext().getPackageName() + "/" + imageSource.getResource());
410413
}
411-
if (imageSource.getTile() || this.sRegion != null) {
414+
if (imageSource.getTile() || sRegion != null) {
412415
// Load the bitmap using tile decoding.
413416
TilesInitTask task = new TilesInitTask(this, getContext(), regionDecoderFactory, uri);
414417
execute(task);
@@ -447,6 +450,7 @@ private void reset(boolean newImage) {
447450
matrix = null;
448451
sRect = null;
449452
if (newImage) {
453+
uri = null;
450454
if (decoder != null) {
451455
synchronized (decoderLock) {
452456
decoder.recycle();
@@ -1098,14 +1102,27 @@ private synchronized void initialiseBaseLayer(Point maxTileDimensions) {
10981102
fullImageSampleSize /= 2;
10991103
}
11001104

1101-
initialiseTileMap(maxTileDimensions);
1105+
if (fullImageSampleSize == 1 && sRegion == null && sWidth() < maxTileDimensions.x && sHeight() < maxTileDimensions.y) {
11021106

1103-
List<Tile> baseGrid = tileMap.get(fullImageSampleSize);
1104-
for (Tile baseTile : baseGrid) {
1105-
TileLoadTask task = new TileLoadTask(this, decoder, baseTile);
1107+
// Whole image is required at native resolution, and is smaller than the canvas max bitmap size.
1108+
// Use BitmapDecoder for better image support.
1109+
decoder.recycle();
1110+
decoder = null;
1111+
BitmapLoadTask task = new BitmapLoadTask(this, getContext(), bitmapDecoderFactory, uri, false);
11061112
execute(task);
1113+
1114+
} else {
1115+
1116+
initialiseTileMap(maxTileDimensions);
1117+
1118+
List<Tile> baseGrid = tileMap.get(fullImageSampleSize);
1119+
for (Tile baseTile : baseGrid) {
1120+
TileLoadTask task = new TileLoadTask(this, decoder, baseTile);
1121+
execute(task);
1122+
}
1123+
refreshRequiredTiles(true);
1124+
11071125
}
1108-
refreshRequiredTiles(true);
11091126

11101127
}
11111128

0 commit comments

Comments
 (0)