Remove isShareable from BitmapRegionDecoder
Bug: 140600285 Test: CtsGraphicsTestCases:android.graphics.cts.BitmapRegionDecoderTest Test: I684e0ed6049e146e2c1698383c73709a7163b642 Clean up BRD in preparation for mainline module changes. isShareable has been ignored for a long time, so update the APIs to reflect that. Deprecate the existing ones, and add replacements without isShareable. Make newInstance(FileDescriptor, boolean) into newInstance(ParcelFileDescriptor), as recommended by the build failure. - newInstance(byte[], int, int, boolean) has ignored it since I7dd545c9d52d21c226e11b8921e35a1d9bba9515 (GB) - newInstance(FileDescriptor, boolean) has ignored it since Id1e1c8c5938ee1a33c6fa3caabd2c28e89243eb4 (KITKAT) - newInstance(InputStream, boolean) and newInstance(String, boolean) have always ignored it Document WebP and HEIF support. Add @NonNull annotations. Remove misleading comments about returning null on failure. My understanding is that if it either returns an object or throws an Exception, @NonNull is the appropriate annotation - the client does not need to check for null. Change-Id: I0bf8c4c72cc118d2799a59e8eb6c2cede546fceb
This commit is contained in:
committed by
Leon Scroggins
parent
7d96ce573d
commit
96a13885e8
@@ -15,9 +15,11 @@
|
||||
|
||||
package android.graphics;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
@@ -43,113 +45,156 @@ public final class BitmapRegionDecoder {
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from the specified byte array.
|
||||
* Currently only the JPEG and PNG formats are supported.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param data byte array of compressed image data.
|
||||
* @param offset offset into data for where the decoder should begin
|
||||
* parsing.
|
||||
* @param length the number of bytes, beginning at offset, to parse
|
||||
* @param isShareable This field has been ignored since
|
||||
* {@link Build.VERSION_CODES#GINGERBREAD}.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
* @deprecated In favor of {@link #newInstance(byte[], int, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull byte[] data,
|
||||
int offset, int length, boolean isShareable) throws IOException {
|
||||
return newInstance(data, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from the specified byte array.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param data byte array of compressed image data.
|
||||
* @param offset offset into data for where the decoder should begin
|
||||
* parsing.
|
||||
* @param length the number of bytes, beginning at offset, to parse
|
||||
* @param isShareable If this is true, then the BitmapRegionDecoder may keep a
|
||||
* shallow reference to the input. If this is false,
|
||||
* then the BitmapRegionDecoder will explicitly make a copy of the
|
||||
* input data, and keep that. Even if sharing is allowed,
|
||||
* the implementation may still decide to make a deep
|
||||
* copy of the input data. If an image is progressively encoded,
|
||||
* allowing sharing may degrade the decoding speed.
|
||||
* @return BitmapRegionDecoder, or null if the image data could not be decoded.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
*/
|
||||
public static BitmapRegionDecoder newInstance(byte[] data,
|
||||
int offset, int length, boolean isShareable) throws IOException {
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull byte[] data,
|
||||
int offset, int length) throws IOException {
|
||||
if ((offset | length) < 0 || data.length < offset + length) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return nativeNewInstance(data, offset, length, isShareable);
|
||||
return nativeNewInstance(data, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from the file descriptor.
|
||||
* The position within the descriptor will not be changed when
|
||||
* this returns, so the descriptor can be used again as is.
|
||||
* Currently only the JPEG and PNG formats are supported.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param fd The file descriptor containing the data to decode
|
||||
* @param isShareable If this is true, then the BitmapRegionDecoder may keep a
|
||||
* shallow reference to the input. If this is false,
|
||||
* then the BitmapRegionDecoder will explicitly make a copy of the
|
||||
* input data, and keep that. Even if sharing is allowed,
|
||||
* the implementation may still decide to make a deep
|
||||
* copy of the input data. If an image is progressively encoded,
|
||||
* allowing sharing may degrade the decoding speed.
|
||||
* @return BitmapRegionDecoder, or null if the image data could not be decoded.
|
||||
* @param isShareable This field has been ignored since
|
||||
* {@link Build.VERSION_CODES#KITKAT}.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
* @deprecated In favor of {@link #newInstance(ParcelFileDescriptor)}
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(
|
||||
@NonNull FileDescriptor fd, boolean isShareable) throws IOException {
|
||||
return nativeNewInstance(fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from the file descriptor.
|
||||
* The position within the descriptor will not be changed when
|
||||
* this returns, so the descriptor can be used again as is.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param pfd The parcel file descriptor containing the data to decode
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
*/
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(
|
||||
FileDescriptor fd, boolean isShareable) throws IOException {
|
||||
return nativeNewInstance(fd, isShareable);
|
||||
@NonNull ParcelFileDescriptor pfd) throws IOException {
|
||||
return nativeNewInstance(pfd.getFileDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from an input stream.
|
||||
* The stream's position will be where ever it was after the encoded data
|
||||
* was read.
|
||||
* Currently only the JPEG and PNG formats are supported.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param is The input stream that holds the raw data to be decoded into a
|
||||
* BitmapRegionDecoder.
|
||||
* @param isShareable If this is true, then the BitmapRegionDecoder may keep a
|
||||
* shallow reference to the input. If this is false,
|
||||
* then the BitmapRegionDecoder will explicitly make a copy of the
|
||||
* input data, and keep that. Even if sharing is allowed,
|
||||
* the implementation may still decide to make a deep
|
||||
* copy of the input data. If an image is progressively encoded,
|
||||
* allowing sharing may degrade the decoding speed.
|
||||
* @return BitmapRegionDecoder, or null if the image data could not be decoded.
|
||||
* @param isShareable This field has always been ignored.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
* @deprecated In favor of {@link #newInstance(InputStream)}
|
||||
*
|
||||
* <p class="note">Prior to {@link android.os.Build.VERSION_CODES#KITKAT},
|
||||
* <p class="note">Prior to {@link Build.VERSION_CODES#KITKAT},
|
||||
* if {@link InputStream#markSupported is.markSupported()} returns true,
|
||||
* <code>is.mark(1024)</code> would be called. As of
|
||||
* {@link android.os.Build.VERSION_CODES#KITKAT}, this is no longer the case.</p>
|
||||
* {@link Build.VERSION_CODES#KITKAT}, this is no longer the case.</p>
|
||||
*/
|
||||
public static BitmapRegionDecoder newInstance(InputStream is,
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull InputStream is,
|
||||
boolean isShareable) throws IOException {
|
||||
return newInstance(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from an input stream.
|
||||
* The stream's position will be where ever it was after the encoded data
|
||||
* was read.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param is The input stream that holds the raw data to be decoded into a
|
||||
* BitmapRegionDecoder.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
*/
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull InputStream is) throws IOException {
|
||||
if (is instanceof AssetManager.AssetInputStream) {
|
||||
return nativeNewInstance(
|
||||
((AssetManager.AssetInputStream) is).getNativeAsset(),
|
||||
isShareable);
|
||||
((AssetManager.AssetInputStream) is).getNativeAsset());
|
||||
} else {
|
||||
// pass some temp storage down to the native code. 1024 is made up,
|
||||
// but should be large enough to avoid too many small calls back
|
||||
// into is.read(...).
|
||||
byte [] tempStorage = new byte[16 * 1024];
|
||||
return nativeNewInstance(is, tempStorage, isShareable);
|
||||
return nativeNewInstance(is, tempStorage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from a file path.
|
||||
* Currently only the JPEG and PNG formats are supported.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param pathName complete path name for the file to be decoded.
|
||||
* @param isShareable This field has always been ignored.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
* @deprecated In favor of {@link #newInstance(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull String pathName,
|
||||
boolean isShareable) throws IOException {
|
||||
return newInstance(pathName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a BitmapRegionDecoder from a file path.
|
||||
* Currently only the JPEG, PNG, WebP and HEIF formats are supported.
|
||||
*
|
||||
* @param pathName complete path name for the file to be decoded.
|
||||
* @param isShareable If this is true, then the BitmapRegionDecoder may keep a
|
||||
* shallow reference to the input. If this is false,
|
||||
* then the BitmapRegionDecoder will explicitly make a copy of the
|
||||
* input data, and keep that. Even if sharing is allowed,
|
||||
* the implementation may still decide to make a deep
|
||||
* copy of the input data. If an image is progressively encoded,
|
||||
* allowing sharing may degrade the decoding speed.
|
||||
* @return BitmapRegionDecoder, or null if the image data could not be decoded.
|
||||
* @throws IOException if the image format is not supported or can not be decoded.
|
||||
*/
|
||||
public static BitmapRegionDecoder newInstance(String pathName,
|
||||
boolean isShareable) throws IOException {
|
||||
@NonNull
|
||||
public static BitmapRegionDecoder newInstance(@NonNull String pathName) throws IOException {
|
||||
BitmapRegionDecoder decoder = null;
|
||||
InputStream stream = null;
|
||||
|
||||
try {
|
||||
stream = new FileInputStream(pathName);
|
||||
decoder = newInstance(stream, isShareable);
|
||||
decoder = newInstance(stream);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
@@ -275,11 +320,11 @@ public final class BitmapRegionDecoder {
|
||||
|
||||
@UnsupportedAppUsage
|
||||
private static native BitmapRegionDecoder nativeNewInstance(
|
||||
byte[] data, int offset, int length, boolean isShareable);
|
||||
byte[] data, int offset, int length);
|
||||
private static native BitmapRegionDecoder nativeNewInstance(
|
||||
FileDescriptor fd, boolean isShareable);
|
||||
FileDescriptor fd);
|
||||
private static native BitmapRegionDecoder nativeNewInstance(
|
||||
InputStream is, byte[] storage, boolean isShareable);
|
||||
InputStream is, byte[] storage);
|
||||
private static native BitmapRegionDecoder nativeNewInstance(
|
||||
long asset, boolean isShareable);
|
||||
long asset);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user