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

Commit ce89a6e6 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Work around incorrect Skia gamma

Bug: 74408046
Test: Ic6acdc4a1a16840ec6ad9b13b4926c643d0f81ae

Skia incorrectly sets the gamma for LINEAR_EXTENDED_SRGB to 0 as a
misguided optimization attempt. As a result, a HARDWARE Bitmap which
natively has this color space does not match it properly. (Note that we
already catch an F16 Bitmap, above.) Add a workaround in
Bitmap.getColorSpace() to check for the color space explicitly.

Change-Id: Id595e365d1c8d572cfcea214d230a8ce1decdc01
parent 15e91e6f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1247,6 +1247,15 @@ static jboolean Bitmap_isSRGB(JNIEnv* env, jobject, jlong bitmapHandle) {
    return GraphicsJNI::isColorSpaceSRGB(colorSpace);
}

static jboolean Bitmap_isSRGBLinear(JNIEnv* env, jobject, jlong bitmapHandle) {
    LocalScopedBitmap bitmapHolder(bitmapHandle);
    if (!bitmapHolder.valid()) return JNI_FALSE;

    SkColorSpace* colorSpace = bitmapHolder->info().colorSpace();
    sk_sp<SkColorSpace> srgbLinear = SkColorSpace::MakeSRGBLinear();
    return colorSpace == srgbLinear.get() ? JNI_TRUE : JNI_FALSE;
}

static jboolean Bitmap_getColorSpace(JNIEnv* env, jobject, jlong bitmapHandle,
        jfloatArray xyzArray, jfloatArray paramsArray) {

@@ -1592,6 +1601,7 @@ static const JNINativeMethod gBitmapMethods[] = {
        (void*) Bitmap_createGraphicBufferHandle },
    {   "nativeGetColorSpace",      "(J[F[F)Z", (void*)Bitmap_getColorSpace },
    {   "nativeIsSRGB",             "(J)Z", (void*)Bitmap_isSRGB },
    {   "nativeIsSRGBLinear",       "(J)Z", (void*)Bitmap_isSRGBLinear},
    {   "nativeCopyColorSpace",     "(JJ)V",
        (void*)Bitmap_copyColorSpace },
};
+3 −0
Original line number Diff line number Diff line
@@ -1654,6 +1654,8 @@ public final class Bitmap implements Parcelable {
        if (mColorSpace == null) {
            if (nativeIsSRGB(mNativePtr)) {
                mColorSpace = ColorSpace.get(ColorSpace.Named.SRGB);
            } else if (getConfig() == Config.HARDWARE && nativeIsSRGBLinear(mNativePtr)) {
                mColorSpace = ColorSpace.get(ColorSpace.Named.LINEAR_EXTENDED_SRGB);
            } else {
                float[] xyz = new float[9];
                float[] params = new float[7];
@@ -2077,5 +2079,6 @@ public final class Bitmap implements Parcelable {
    private static native GraphicBuffer nativeCreateGraphicBufferHandle(long nativeBitmap);
    private static native boolean nativeGetColorSpace(long nativePtr, float[] xyz, float[] params);
    private static native boolean nativeIsSRGB(long nativePtr);
    private static native boolean nativeIsSRGBLinear(long nativePtr);
    private static native void nativeCopyColorSpace(long srcBitmap, long dstBitmap);
}