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

Commit 28f3943f authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Make ImageDecoder.setTargetColorSpace to EXTENDED promote to F16

Bug: 117601185
Test: I5e5bc6b73d5d27ae30f00507d59896008d4cf364

ImageDecoder does not have a way to request decoding to F16 on 8 bit
images, but it does have a way to request an EXTENDED ColorSpace. Treat
that as a request to use a higher bit depth. This matches how we match
EXTENDED to F16 in other cases (createBitmap, Bitmap#copy, etc).

Change-Id: I3d31b13b56bb57a23b47ffcb2eaba11c53e0b8d9
parent a45b41f5
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -203,7 +203,8 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong
                                          jint desiredWidth, jint desiredHeight, jobject jsubset,
                                          jboolean requireMutable, jint allocator,
                                          jboolean requireUnpremul, jboolean preferRamOverQuality,
                                          jboolean asAlphaMask, jlong colorSpaceHandle) {
                                          jboolean asAlphaMask, jlong colorSpaceHandle,
                                          jboolean extended) {
    auto* decoder = reinterpret_cast<ImageDecoder*>(nativePtr);
    SkAndroidCodec* codec = decoder->mCodec.get();
    const SkISize desiredSize = SkISize::Make(desiredWidth, desiredHeight);
@@ -253,8 +254,9 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong
            }
        }
        // Otherwise, stick with N32
    } else if (extended) {
        colorType = kRGBA_F16_SkColorType;
    } else {
        // This is currently the only way to know that we should decode to F16.
        colorType = codec->computeOutputColorType(colorType);
    }

@@ -517,7 +519,7 @@ static const JNINativeMethod gImageDecoderMethods[] = {
    { "nCreate",        "([BIILandroid/graphics/ImageDecoder$Source;)Landroid/graphics/ImageDecoder;", (void*) ImageDecoder_nCreateByteArray },
    { "nCreate",        "(Ljava/io/InputStream;[BLandroid/graphics/ImageDecoder$Source;)Landroid/graphics/ImageDecoder;", (void*) ImageDecoder_nCreateInputStream },
    { "nCreate",        "(Ljava/io/FileDescriptor;Landroid/graphics/ImageDecoder$Source;)Landroid/graphics/ImageDecoder;", (void*) ImageDecoder_nCreateFd },
    { "nDecodeBitmap",  "(JLandroid/graphics/ImageDecoder;ZIILandroid/graphics/Rect;ZIZZZJ)Landroid/graphics/Bitmap;",
    { "nDecodeBitmap",  "(JLandroid/graphics/ImageDecoder;ZIILandroid/graphics/Rect;ZIZZZJZ)Landroid/graphics/Bitmap;",
                                                                 (void*) ImageDecoder_nDecodeBitmap },
    { "nGetSampledSize","(JI)Landroid/util/Size;",               (void*) ImageDecoder_nGetSampledSize },
    { "nGetPadding",    "(JLandroid/graphics/Rect;)V",           (void*) ImageDecoder_nGetPadding },
+9 −4
Original line number Diff line number Diff line
@@ -1641,12 +1641,17 @@ public final class ImageDecoder implements AutoCloseable {
    @NonNull
    private Bitmap decodeBitmapInternal() throws IOException {
        checkState();
        long colorSpacePtr = mDesiredColorSpace == null ? 0 :
                mDesiredColorSpace.getNativeInstance();
        long colorSpacePtr = 0;
        boolean extended = false;
        if (mDesiredColorSpace != null) {
            colorSpacePtr = mDesiredColorSpace.getNativeInstance();
            extended = mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB)
                || mDesiredColorSpace == ColorSpace.get(ColorSpace.Named.LINEAR_EXTENDED_SRGB);
        }
        return nDecodeBitmap(mNativePtr, this, mPostProcessor != null,
                mDesiredWidth, mDesiredHeight, mCropRect,
                mMutable, mAllocator, mUnpremultipliedRequired,
                mConserveMemory, mDecodeAsAlphaMask, colorSpacePtr);
                mConserveMemory, mDecodeAsAlphaMask, colorSpacePtr, extended);
    }

    private void callHeaderDecoded(@Nullable OnHeaderDecodedListener listener,
@@ -1934,7 +1939,7 @@ public final class ImageDecoder implements AutoCloseable {
            @Nullable Rect cropRect, boolean mutable,
            int allocator, boolean unpremulRequired,
            boolean conserveMemory, boolean decodeAsAlphaMask,
            long desiredColorSpace)
            long desiredColorSpace, boolean extended)
        throws IOException;
    private static native Size nGetSampledSize(long nativePtr,
                                               int sampleSize);