diff options
author | 2019-02-04 10:30:22 -0500 | |
---|---|---|
committer | 2019-02-26 12:03:29 -0500 | |
commit | eac1423a316016a7a50d3f6e60dc77466afdcfd9 (patch) | |
tree | fa040e9202aa2e57fff5e7fd29e40379ed2bce4c /graphics/java | |
parent | 869f5c42a0fbf73e284949fd5fd58eaff7b8882b (diff) |
Pass ColorSpace to AnimatedImageDrawable
Bug: 123301872
Bug: 117601185
Test: Manual (Ie18811ba29a1db163aca08472b04ae185e9344f0)
Test: CTS (Ie4b0a232effc67ab7a7fc6070302c722177cadfa)
Test: Infeasible (verify desired ColorSpace is used)
When calling setTargetColorSpace on an ImageDecoder for an animated
image, pass this to the AnimatedImageDrawable. Also respect an EXTENDED
ColorSpace as a cue to decode to RGBA_F16, as with Bitmaps.
Call ImageDecoder#checkState for AnimatedImageDrawables, as with
Bitmaps.
Change-Id: I5f6e11ee14ce4477bfedf2d1fdde8e15ed5f24d5
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/ImageDecoder.java | 37 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/AnimatedImageDrawable.java | 12 |
2 files changed, 31 insertions, 18 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 7016cc741e90..a7058c319124 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -1606,14 +1606,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!"); } @@ -1637,21 +1639,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, @@ -1717,9 +1728,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); |