summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2019-03-01 09:29:02 -0700
committer Jeff Sharkey <jsharkey@android.com> 2019-03-01 11:46:15 -0700
commit575f065150240a610aa9fb7c11fd86268602a38c (patch)
tree7dca63c87e50dcc6799584d60386f192ae1f8fbb /graphics/java
parent7b040522e85d363de2c432590c15cb66f93ed350 (diff)
API to determine if MIME type is supported.
This'll help developers decide if they can try decoding an image file directly, or if they need to convert it to a more general format first. Bug: 126276695 Test: atest android.graphics.cts.ImageDecoderTest Change-Id: I6a404e3be883ac14ac2e6376247d4209f8963908
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/ImageDecoder.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java
index 7016cc741e90..d3ca11c7f8b4 100644
--- a/graphics/java/android/graphics/ImageDecoder.java
+++ b/graphics/java/android/graphics/ImageDecoder.java
@@ -59,6 +59,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Retention;
import java.nio.ByteBuffer;
+import java.util.Locale;
+import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -838,6 +840,39 @@ public final class ImageDecoder implements AutoCloseable {
}
/**
+ * Return if the given MIME type is a supported file format that can be
+ * decoded by this class. This can be useful to determine if a file can be
+ * decoded directly, or if it needs to be converted into a more general
+ * format using an API like {@link ContentResolver#openTypedAssetFile}.
+ */
+ public static boolean isMimeTypeSupported(@NonNull String mimeType) {
+ Objects.requireNonNull(mimeType);
+ switch (mimeType.toLowerCase(Locale.US)) {
+ case "image/png":
+ case "image/jpeg":
+ case "image/webp":
+ case "image/gif":
+ case "image/heif":
+ case "image/bmp":
+ case "image/x-ico":
+ case "image/vnd.wap.wbmp":
+ case "image/x-sony-arw":
+ case "image/x-canon-cr2":
+ case "image/x-adobe-dng":
+ case "image/x-nikon-nef":
+ case "image/x-nikon-nrw":
+ case "image/x-olympus-orf":
+ case "image/x-fuji-raf":
+ case "image/x-panasonic-rw2":
+ case "image/x-pentax-pef":
+ case "image/x-samsung-srw":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
* Create a new {@link Source Source} from a resource.
*
* @param res the {@link Resources} object containing the image data.