Merge "ImageDecoder: Add getters. Rename setAsAlphaMask" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-08 21:40:22 +00:00
committed by Android (Google) Code Review
3 changed files with 107 additions and 10 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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.
*
* <p>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.</p>
*/
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.</p>
*
* <p>setAsAlphaMask is incompatible with {@link #ALLOCATOR_HARDWARE}. Trying to
* <p>setDecodeAsAlphaMask is incompatible with {@link #ALLOCATOR_HARDWARE}. Trying to
* combine them will result in {@link #decodeDrawable}/
* {@link #decodeBitmap} throwing an
* {@link java.lang.IllegalStateException}.</p>
*
* @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.
*
* <p>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.</p>
*/
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);