Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 575f0651 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent 7b040522
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14154,6 +14154,7 @@ package android.graphics {
    method @Nullable public android.graphics.ImageDecoder.OnPartialImageListener getOnPartialImageListener();
    method @Nullable public android.graphics.PostProcessor getPostProcessor();
    method public boolean isDecodeAsAlphaMaskEnabled();
    method public static boolean isMimeTypeSupported(@NonNull String);
    method public boolean isMutableRequired();
    method public boolean isUnpremultipliedRequired();
    method public void setAllocator(int);
+35 −0
Original line number Diff line number Diff line
@@ -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;

@@ -837,6 +839,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.
     *