From 746a9fee937969af9be7e060335e26e098971615 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 8 Mar 2018 10:32:10 -0500 Subject: [PATCH] ImageDecoder: Add getters. Rename setAsAlphaMask Bug: 73788928 Test: I1606cbb4e71579160ffaef12c1ed738fad882cd1 This will allow Kotlin developers to treat the setters as properties. Part of the motivation for the rename is that "getAsAlphaMask" sounds like it returns an alpha mask itself. Rename both to _etDecodeAsAlphaMask. Change-Id: I8f9b04f8381840490b662c3bcd37a95442af8110 --- api/current.txt | 10 +- api/removed.txt | 5 + .../java/android/graphics/ImageDecoder.java | 102 ++++++++++++++++-- 3 files changed, 107 insertions(+), 10 deletions(-) diff --git a/api/current.txt b/api/current.txt index b2a6ba6251076..0220504622bf3 100644 --- a/api/current.txt +++ b/api/current.txt @@ -13601,11 +13601,19 @@ package android.graphics { method public static android.graphics.Bitmap decodeBitmap(android.graphics.ImageDecoder.Source) throws java.io.IOException; method public static android.graphics.drawable.Drawable decodeDrawable(android.graphics.ImageDecoder.Source, android.graphics.ImageDecoder.OnHeaderDecodedListener) throws java.io.IOException; method public static android.graphics.drawable.Drawable decodeDrawable(android.graphics.ImageDecoder.Source) throws java.io.IOException; + method public int getAllocator(); + method public boolean getConserveMemory(); + method public android.graphics.Rect getCrop(); + method public boolean getDecodeAsAlphaMask(); + method public boolean getMutable(); + method public android.graphics.ImageDecoder.OnPartialImageListener getOnPartialImageListener(); + method public android.graphics.PostProcessor getPostProcessor(); + method public boolean getRequireUnpremultiplied(); method public android.util.Size getSampledSize(int); method public android.graphics.ImageDecoder setAllocator(int); - method public android.graphics.ImageDecoder setAsAlphaMask(boolean); method public android.graphics.ImageDecoder setConserveMemory(boolean); method public android.graphics.ImageDecoder setCrop(android.graphics.Rect); + method public android.graphics.ImageDecoder setDecodeAsAlphaMask(boolean); method public android.graphics.ImageDecoder setMutable(boolean); method public android.graphics.ImageDecoder setOnPartialImageListener(android.graphics.ImageDecoder.OnPartialImageListener); method public android.graphics.ImageDecoder setPostProcessor(android.graphics.PostProcessor); diff --git a/api/removed.txt b/api/removed.txt index b8e2b98572cf1..a5370f48fb3ad 100644 --- a/api/removed.txt +++ b/api/removed.txt @@ -152,6 +152,11 @@ package android.graphics { method public deprecated boolean clipRegion(android.graphics.Region); } + public final class ImageDecoder implements java.lang.AutoCloseable { + method public deprecated boolean getAsAlphaMask(); + method public deprecated android.graphics.ImageDecoder setAsAlphaMask(boolean); + } + public deprecated class LayerRasterizer extends android.graphics.Rasterizer { ctor public LayerRasterizer(); method public void addLayer(android.graphics.Paint, float, float); diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 5602a3ee76360..88701fac66c76 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -493,7 +493,7 @@ public final class ImageDecoder implements AutoCloseable { private boolean mRequireUnpremultiplied = false; private boolean mMutable = false; private boolean mConserveMemory = false; - private boolean mAsAlphaMask = false; + private boolean mDecodeAsAlphaMask = false; private Rect mCropRect; private Rect mOutPaddingRect; private Source mSource; @@ -730,7 +730,7 @@ public final class ImageDecoder implements AutoCloseable { * Will typically result in a {@link Bitmap.Config#HARDWARE} * allocation, but may be software for small images. In addition, this will * switch to software when HARDWARE is incompatible, e.g. - * {@link #setMutable}, {@link #setAsAlphaMask}. + * {@link #setMutable}, {@link #setDecodeAsAlphaMask}. */ public static final int ALLOCATOR_DEFAULT = 0; @@ -753,7 +753,7 @@ public final class ImageDecoder implements AutoCloseable { * Require a {@link Bitmap.Config#HARDWARE} {@link Bitmap}. * * When this is combined with incompatible options, like - * {@link #setMutable} or {@link #setAsAlphaMask}, {@link #decodeDrawable} + * {@link #setMutable} or {@link #setDecodeAsAlphaMask}, {@link #decodeDrawable} * / {@link #decodeBitmap} will throw an * {@link java.lang.IllegalStateException}. */ @@ -782,6 +782,14 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return the allocator for the pixel memory. + */ + @Allocator + public int getAllocator() { + return mAllocator; + } + /** * Specify whether the {@link Bitmap} should have unpremultiplied pixels. * @@ -802,6 +810,13 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return whether the {@link Bitmap} will have unpremultiplied pixels. + */ + public boolean getRequireUnpremultiplied() { + return mRequireUnpremultiplied; + } + /** * Modify the image after decoding and scaling. * @@ -822,6 +837,14 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return the {@link PostProcessor} currently set. + */ + @Nullable + public PostProcessor getPostProcessor() { + return mPostProcessor; + } + /** * Set (replace) the {@link OnPartialImageListener} on this object. * @@ -835,6 +858,14 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return the {@link OnPartialImageListener} currently set. + */ + @Nullable + public OnPartialImageListener getOnPartialImageListener() { + return mOnPartialImageListener; + } + /** * Crop the output to {@code subset} of the (possibly) scaled image. * @@ -854,6 +885,14 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return the cropping rectangle, if set. + */ + @Nullable + public Rect getCrop() { + return mCropRect; + } + /** * Set a Rect for retrieving nine patch padding. * @@ -892,6 +931,13 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return whether the {@link Bitmap} will be mutable. + */ + public boolean getMutable() { + return mMutable; + } + /** * Specify whether to potentially save RAM at the expense of quality. * @@ -911,6 +957,17 @@ public final class ImageDecoder implements AutoCloseable { return this; } + /** + * Return whether this object will try to save RAM at the expense of quality. + * + *

This returns whether {@link #setConserveMemory} was set to {@code true}. + * It may still return {@code true} even if the {@code ImageDecoder} does not + * have a way to save RAM at the expense of quality for this image.

+ */ + public boolean getConserveMemory() { + return mConserveMemory; + } + /** * Specify whether to potentially treat the output as an alpha mask. * @@ -918,18 +975,45 @@ public final class ImageDecoder implements AutoCloseable { * with only one channel, treat that channel as alpha. Otherwise this call has * no effect.

* - *

setAsAlphaMask is incompatible with {@link #ALLOCATOR_HARDWARE}. Trying to + *

setDecodeAsAlphaMask is incompatible with {@link #ALLOCATOR_HARDWARE}. Trying to * combine them will result in {@link #decodeDrawable}/ * {@link #decodeBitmap} throwing an * {@link java.lang.IllegalStateException}.

* * @return this object for chaining. */ - public ImageDecoder setAsAlphaMask(boolean asAlphaMask) { - mAsAlphaMask = asAlphaMask; + public ImageDecoder setDecodeAsAlphaMask(boolean decodeAsAlphaMask) { + mDecodeAsAlphaMask = decodeAsAlphaMask; return this; } + /** @removed + * @deprecated Call {@link #setDecodeAsAlphaMask} instead. + */ + @java.lang.Deprecated + public ImageDecoder setAsAlphaMask(boolean asAlphaMask) { + return this.setDecodeAsAlphaMask(asAlphaMask); + } + + /** + * Return whether to treat single channel input as alpha. + * + *

This returns whether {@link #setDecodeAsAlphaMask} was set to {@code true}. + * It may still return {@code true} even if the image has more than one + * channel and therefore will not be treated as an alpha mask.

+ */ + public boolean getDecodeAsAlphaMask() { + return mDecodeAsAlphaMask; + } + + /** @removed + * @deprecated Call {@link #getDecodeAsAlphaMask} instead. + */ + @java.lang.Deprecated + public boolean getAsAlphaMask() { + return this.getDecodeAsAlphaMask(); + } + @Override public void close() { mCloseGuard.close(); @@ -960,7 +1044,7 @@ public final class ImageDecoder implements AutoCloseable { if (mMutable) { throw new IllegalStateException("Cannot make mutable HARDWARE Bitmap!"); } - if (mAsAlphaMask) { + if (mDecodeAsAlphaMask) { throw new IllegalStateException("Cannot make HARDWARE Alpha mask Bitmap!"); } } @@ -992,7 +1076,7 @@ public final class ImageDecoder implements AutoCloseable { return nDecodeBitmap(mNativePtr, partialImagePtr, postProcessPtr, mDesiredWidth, mDesiredHeight, mCropRect, mMutable, mAllocator, mRequireUnpremultiplied, - mConserveMemory, mAsAlphaMask); + mConserveMemory, mDecodeAsAlphaMask); } private void callHeaderDecoded(@Nullable OnHeaderDecodedListener listener, @@ -1224,7 +1308,7 @@ public final class ImageDecoder implements AutoCloseable { int width, int height, @Nullable Rect cropRect, boolean mutable, int allocator, boolean requireUnpremul, - boolean conserveMemory, boolean asAlphaMask) + boolean conserveMemory, boolean decodeAsAlphaMask) throws IOException; private static native Size nGetSampledSize(long nativePtr, int sampleSize);