-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Re-using Bitmaps with RGBA_F16 configs.
Also adds emulator tests for wide gamut images on API 26+.
- Loading branch information
Showing
4 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
instrumentation/src/androidTest/java/com/bumptech/glide/WideGamutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package com.bumptech.glide; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Bitmap.CompressFormat; | ||
import android.graphics.ColorSpace; | ||
import android.graphics.ColorSpace.Named; | ||
import android.os.Build; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import com.bumptech.glide.load.DecodeFormat; | ||
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool; | ||
import com.bumptech.glide.test.ConcurrencyHelper; | ||
import com.bumptech.glide.test.GlideApp; | ||
import com.bumptech.glide.test.ResourceIds; | ||
import com.bumptech.glide.test.TearDownGlide; | ||
import java.io.ByteArrayOutputStream; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class WideGamutTest { | ||
@Rule public final TestRule tearDownGlide = new TearDownGlide(); | ||
private final ConcurrencyHelper concurrency = new ConcurrencyHelper(); | ||
private final Context context = InstrumentationRegistry.getTargetContext(); | ||
|
||
@Before | ||
public void setUp() { | ||
assumeTrue(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O); | ||
} | ||
|
||
@Test | ||
public void load_withWideGamutImage_returnsWideGamutBitmap() { | ||
Bitmap bitmap = | ||
concurrency.get( | ||
Glide.with(context) | ||
.asBitmap() | ||
.load(ResourceIds.raw.webkit_logo_p3) | ||
.submit()); | ||
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.RGBA_F16); | ||
} | ||
|
||
@Test | ||
public void load_withWideGamutImage_bitmapInPoolWithSizeAndConfig_usesBitmapFromPool() { | ||
int bitmapDimension = 1000; | ||
Glide.init( | ||
context, | ||
new GlideBuilder() | ||
.setBitmapPool(new LruBitmapPool(bitmapDimension * bitmapDimension * 8 * 4))); | ||
Bitmap expected = Bitmap.createBitmap(bitmapDimension, bitmapDimension, Bitmap.Config.RGBA_F16); | ||
|
||
Glide.get(context) | ||
.getBitmapPool() | ||
.put(expected); | ||
|
||
Bitmap bitmap = | ||
concurrency.get( | ||
Glide.with(context) | ||
.asBitmap() | ||
.load(ResourceIds.raw.webkit_logo_p3) | ||
.submit()); | ||
assertThat(bitmap).isSameAs(expected); | ||
} | ||
|
||
@Test | ||
public void load_withWideGamutImage_hardwareAllowed_returnsHardwareBitmap() { | ||
Bitmap bitmap = | ||
concurrency.get( | ||
GlideApp.with(context) | ||
.asBitmap() | ||
.format(DecodeFormat.PREFER_ARGB_8888) | ||
.load(ResourceIds.raw.webkit_logo_p3) | ||
.submit()); | ||
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.HARDWARE); | ||
} | ||
|
||
@Test | ||
public void load_withEncodedPngWideGamutImage_decodesWideGamut() { | ||
Bitmap toCompress = | ||
Bitmap.createBitmap( | ||
100, 100, Bitmap.Config.RGBA_F16, /*hasAlpha=*/ true, ColorSpace.get(Named.DCI_P3)); | ||
|
||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
toCompress.compress(CompressFormat.PNG, 100, os); | ||
byte[] data = os.toByteArray(); | ||
|
||
Bitmap bitmap = | ||
concurrency.get( | ||
Glide.with(context) | ||
.asBitmap() | ||
.load(data) | ||
.submit()); | ||
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.RGBA_F16); | ||
} | ||
|
||
@Test | ||
public void load_withEncodedJpegWideGamutImage_decodesArgb8888() { | ||
Bitmap toCompress = | ||
Bitmap.createBitmap( | ||
100, 100, Bitmap.Config.RGBA_F16, /*hasAlpha=*/ true, ColorSpace.get(Named.DCI_P3)); | ||
|
||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
toCompress.compress(CompressFormat.JPEG, 100, os); | ||
byte[] data = os.toByteArray(); | ||
|
||
Bitmap bitmap = | ||
concurrency.get( | ||
Glide.with(context) | ||
.asBitmap() | ||
.load(data) | ||
.submit()); | ||
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.ARGB_8888); | ||
} | ||
|
||
@Test | ||
public void load_withEncodedWebpWideGamutImage_decodesArgb8888() { | ||
Bitmap toCompress = | ||
Bitmap.createBitmap( | ||
100, 100, Bitmap.Config.RGBA_F16, /*hasAlpha=*/ true, ColorSpace.get(Named.DCI_P3)); | ||
|
||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
toCompress.compress(CompressFormat.WEBP, 100, os); | ||
byte[] data = os.toByteArray(); | ||
|
||
Bitmap bitmap = | ||
concurrency.get( | ||
Glide.with(context) | ||
.asBitmap() | ||
.load(data) | ||
.submit()); | ||
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.ARGB_8888); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters