summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2019-03-06 03:37:23 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-03-06 03:37:23 +0000
commit1b042a7c6efaf7837f4f9ac5c80d6d257f19a26d (patch)
tree9a4664365889d54bbfa69471dfc94b25c75459e1 /graphics/java
parente727454db83a97551747d97a7b392e9b458ad2ea (diff)
parenteac1423a316016a7a50d3f6e60dc77466afdcfd9 (diff)
Merge "Pass ColorSpace to AnimatedImageDrawable"
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/ImageDecoder.java37
-rw-r--r--graphics/java/android/graphics/drawable/AnimatedImageDrawable.java12
2 files changed, 31 insertions, 18 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java
index 2cf802bb9631..2d5babc5ebdb 100644
--- a/graphics/java/android/graphics/ImageDecoder.java
+++ b/graphics/java/android/graphics/ImageDecoder.java
@@ -1642,14 +1642,16 @@ public final class ImageDecoder implements AutoCloseable {
mTempStorage = null;
}
- private void checkState() {
+ private void checkState(boolean animated) {
if (mNativePtr == 0) {
throw new IllegalStateException("Cannot use closed ImageDecoder!");
}
checkSubset(mDesiredWidth, mDesiredHeight, mCropRect);
- if (mAllocator == ALLOCATOR_HARDWARE) {
+ // animated ignores the allocator, so no need to check for incompatible
+ // fields.
+ if (!animated && mAllocator == ALLOCATOR_HARDWARE) {
if (mMutable) {
throw new IllegalStateException("Cannot make mutable HARDWARE Bitmap!");
}
@@ -1673,21 +1675,30 @@ public final class ImageDecoder implements AutoCloseable {
}
}
+ private boolean checkForExtended() {
+ if (mDesiredColorSpace == null) {
+ return false;
+ }
+ return mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB)
+ || mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.LINEAR_EXTENDED_SRGB);
+ }
+
+ private long getColorSpacePtr() {
+ if (mDesiredColorSpace == null) {
+ return 0;
+ }
+ return mDesiredColorSpace.getNativeInstance();
+ }
+
@WorkerThread
@NonNull
private Bitmap decodeBitmapInternal() throws IOException {
- checkState();
- long colorSpacePtr = 0;
- boolean extended = false;
- if (mDesiredColorSpace != null) {
- colorSpacePtr = mDesiredColorSpace.getNativeInstance();
- extended = mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB)
- || mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.LINEAR_EXTENDED_SRGB);
- }
+ checkState(false);
return nDecodeBitmap(mNativePtr, this, mPostProcessor != null,
mDesiredWidth, mDesiredHeight, mCropRect,
mMutable, mAllocator, mUnpremultipliedRequired,
- mConserveMemory, mDecodeAsAlphaMask, colorSpacePtr, extended);
+ mConserveMemory, mDecodeAsAlphaMask, getColorSpacePtr(),
+ checkForExtended());
}
private void callHeaderDecoded(@Nullable OnHeaderDecodedListener listener,
@@ -1753,9 +1764,11 @@ public final class ImageDecoder implements AutoCloseable {
// mPostProcessor exists.
ImageDecoder postProcessPtr = decoder.mPostProcessor == null ?
null : decoder;
+ decoder.checkState(true);
Drawable d = new AnimatedImageDrawable(decoder.mNativePtr,
postProcessPtr, decoder.mDesiredWidth,
- decoder.mDesiredHeight, srcDensity,
+ decoder.mDesiredHeight, decoder.getColorSpacePtr(),
+ decoder.checkForExtended(), srcDensity,
src.computeDstDensity(), decoder.mCropRect,
decoder.mInputStream, decoder.mAssetFd);
// d has taken ownership of these objects.
diff --git a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java
index 3aaec3123d7d..bb6bf243bc76 100644
--- a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java
+++ b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java
@@ -291,8 +291,8 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 {
*/
public AnimatedImageDrawable(long nativeImageDecoder,
@Nullable ImageDecoder decoder, int width, int height,
- int srcDensity, int dstDensity, Rect cropRect,
- InputStream inputStream, AssetFileDescriptor afd)
+ long colorSpaceHandle, boolean extended, int srcDensity, int dstDensity,
+ Rect cropRect, InputStream inputStream, AssetFileDescriptor afd)
throws IOException {
width = Bitmap.scaleFromDensity(width, srcDensity, dstDensity);
height = Bitmap.scaleFromDensity(height, srcDensity, dstDensity);
@@ -309,8 +309,8 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 {
mIntrinsicHeight = cropRect.height();
}
- mState = new State(nCreate(nativeImageDecoder, decoder, width, height, cropRect),
- inputStream, afd);
+ mState = new State(nCreate(nativeImageDecoder, decoder, width, height, colorSpaceHandle,
+ extended, cropRect), inputStream, afd);
final long nativeSize = nNativeByteSize(mState.mNativePtr);
NativeAllocationRegistry registry = new NativeAllocationRegistry(
@@ -574,8 +574,8 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 {
private static native long nCreate(long nativeImageDecoder,
- @Nullable ImageDecoder decoder, int width, int height, Rect cropRect)
- throws IOException;
+ @Nullable ImageDecoder decoder, int width, int height, long colorSpaceHandle,
+ boolean extended, Rect cropRect) throws IOException;
@FastNative
private static native long nGetNativeFinalizer();
private static native long nDraw(long nativePtr, long canvasNativePtr);