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

Commit 094d11d3 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Add Gainmap bitmap & imagedecoder"

parents 81f10863 5bd537ea
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ public final class Bitmap implements Parcelable {
    private boolean mRecycled;

    private ColorSpace mColorSpace;
    private Gainmap mGainmap;

    /*package*/ int mDensity = getDefaultDensity();

@@ -1896,6 +1897,27 @@ public final class Bitmap implements Parcelable {
        }
    }

    /**
     * Returns whether or not this Bitmap contains a Gainmap.
     * @hide
     */
    public boolean hasGainmap() {
        checkRecycled("Bitmap is recycled");
        return nativeHasGainmap(mNativePtr);
    }

    /**
     * Returns the gainmap or null if the bitmap doesn't contain a gainmap
     * @hide
     */
    public @Nullable Gainmap getGainmap() {
        checkRecycled("Bitmap is recycled");
        if (mGainmap == null) {
            mGainmap = nativeExtractGainmap(mNativePtr);
        }
        return mGainmap;
    }

    /**
     * Fills the bitmap's pixels with the specified {@link Color}.
     *
@@ -2380,6 +2402,8 @@ public final class Bitmap implements Parcelable {

    private static native void nativeSetImmutable(long nativePtr);

    private static native Gainmap nativeExtractGainmap(long nativePtr);

    // ---------------- @CriticalNative -------------------

    @CriticalNative
@@ -2387,4 +2411,7 @@ public final class Bitmap implements Parcelable {

    @CriticalNative
    private static native boolean nativeIsBackedByAshmem(long nativePtr);

    @CriticalNative
    private static native boolean nativeHasGainmap(long nativePtr);
}
+127 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics;

import android.annotation.NonNull;

import libcore.util.NativeAllocationRegistry;

/**
 * Gainmap represents a mechanism for augmenting an SDR image to produce an HDR one with variable
 * display adjustment capability.
 *
 * It is a combination of a set of metadata describing the gainmap, as well as either a 1 or 3
 * channel Bitmap that represents the gainmap data itself.
 *
 * @hide
 */
public class Gainmap {
    private final long mNativePtr;
    private final Bitmap mGainmapImage;

    // called from JNI and Bitmap_Delegate.
    private Gainmap(Bitmap gainmapImage, long nativeGainmap, int allocationByteCount,
            boolean fromMalloc) {
        if (nativeGainmap == 0) {
            throw new RuntimeException("internal error: native gainmap is 0");
        }

        mGainmapImage = gainmapImage;
        mNativePtr = nativeGainmap;

        final NativeAllocationRegistry registry;
        if (fromMalloc) {
            registry = NativeAllocationRegistry.createMalloced(
                    Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount);
        } else {
            registry = NativeAllocationRegistry.createNonmalloced(
                    Bitmap.class.getClassLoader(), nGetFinalizer(), allocationByteCount);
        }
        registry.registerNativeAllocation(this, nativeGainmap);
    }

    /**
     * Returns the image data of the gainmap represented as a Bitmap
     * @return
     */
    @NonNull
    public Bitmap getGainmapImage() {
        return mGainmapImage;
    }

    /**
     * Sets the gainmap max metadata. For single-plane gainmaps, r, g, and b should be the same.
     */
    @NonNull
    public void setGainmapMax(float r, float g, float b) {
        nSetGainmapMax(mNativePtr, r, g, b);
    }

    /**
     * Gets the gainmap max metadata. For single-plane gainmaps, all 3 components should be the
     * same. The components are in r, g, b order.
     */
    @NonNull
    public float[] getGainmapMax() {
        float[] ret = new float[3];
        nGetGainmapMax(mNativePtr, ret);
        return ret;
    }

    /**
     * Sets the maximum HDR ratio for the gainmap
     */
    @NonNull
    public void setHdrRatioMax(float max) {
        nSetHdrRatioMax(mNativePtr, max);
    }

    /**
     * Gets the maximum HDR ratio for the gainmap
     */
    @NonNull
    public float getHdrRatioMax() {
        return nGetHdrRatioMax(mNativePtr);
    }

    /**
     * Sets the maximum HDR ratio for the gainmap
     */
    @NonNull
    public void setHdrRatioMin(float min) {
        nSetHdrRatioMin(mNativePtr, min);
    }

    /**
     * Gets the maximum HDR ratio for the gainmap
     */
    @NonNull
    public float getHdrRatioMin() {
        return nGetHdrRatioMin(mNativePtr);
    }

    private static native long nGetFinalizer();

    private static native void nSetGainmapMax(long ptr, float r, float g, float b);
    private static native void nGetGainmapMax(long ptr, float[] components);

    private static native void nSetHdrRatioMax(long ptr, float max);
    private static native float nGetHdrRatioMax(long ptr);

    private static native void nSetHdrRatioMin(long ptr, float min);
    private static native float nGetHdrRatioMin(long ptr);
}
+1 −0
Original line number Diff line number Diff line
@@ -347,6 +347,7 @@ cc_defaults {
        "jni/CreateJavaOutputStreamAdaptor.cpp",
        "jni/FontFamily.cpp",
        "jni/FontUtils.cpp",
        "jni/Gainmap.cpp",
        "jni/Graphics.cpp",
        "jni/ImageDecoder.cpp",
        "jni/Interpolator.cpp",

libs/hwui/Gainmap.h

0 → 100644
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <SkGainmapInfo.h>
#include <SkImage.h>
#include <hwui/Bitmap.h>
#include <utils/LightRefBase.h>

namespace android::uirenderer {

class Gainmap : public LightRefBase<Gainmap> {
public:
    SkGainmapInfo info;
    sk_sp<Bitmap> bitmap;
};

}  // namespace android::uirenderer
+2 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ extern int register_android_graphics_ColorFilter(JNIEnv* env);
extern int register_android_graphics_ColorSpace(JNIEnv* env);
extern int register_android_graphics_DrawFilter(JNIEnv* env);
extern int register_android_graphics_FontFamily(JNIEnv* env);
extern int register_android_graphics_Gainmap(JNIEnv* env);
extern int register_android_graphics_HardwareRendererObserver(JNIEnv* env);
extern int register_android_graphics_Matrix(JNIEnv* env);
extern int register_android_graphics_Paint(JNIEnv* env);
@@ -114,6 +115,7 @@ extern int register_android_graphics_HardwareBufferRenderer(JNIEnv* env);
            REG_JNI(register_android_graphics_ColorFilter),
            REG_JNI(register_android_graphics_DrawFilter),
            REG_JNI(register_android_graphics_FontFamily),
            REG_JNI(register_android_graphics_Gainmap),
            REG_JNI(register_android_graphics_HardwareRendererObserver),
            REG_JNI(register_android_graphics_ImageDecoder),
            REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable),
Loading