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

Commit 0b0ed6d1 authored by Alec Mouri's avatar Alec Mouri
Browse files

Add DISPLAY_BT2020 ColorSpace and DataSpace

This already exists as an aidl dataspace, and some ICC profiles may
use this.

Bug: 349357636
Bug: 355264141
Flag: com.android.graphics.flags.display_bt2020_colorspace
Test: ColorSpaceTest
Change-Id: I6c4093264d41c6e4ca99a7d6569abfebda90ac3f
parent 19ec5dc4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16103,6 +16103,7 @@ package android.graphics {
    enum_constant public static final android.graphics.ColorSpace.Named CIE_LAB;
    enum_constant public static final android.graphics.ColorSpace.Named CIE_XYZ;
    enum_constant public static final android.graphics.ColorSpace.Named DCI_P3;
    enum_constant @FlaggedApi("com.android.graphics.flags.display_bt2020_colorspace") public static final android.graphics.ColorSpace.Named DISPLAY_BT2020;
    enum_constant public static final android.graphics.ColorSpace.Named DISPLAY_P3;
    enum_constant public static final android.graphics.ColorSpace.Named EXTENDED_SRGB;
    enum_constant public static final android.graphics.ColorSpace.Named LINEAR_EXTENDED_SRGB;
@@ -18619,6 +18620,7 @@ package android.hardware {
    field public static final int DATASPACE_BT709 = 281083904; // 0x10c10000
    field public static final int DATASPACE_DCI_P3 = 155844608; // 0x94a0000
    field public static final int DATASPACE_DEPTH = 4096; // 0x1000
    field @FlaggedApi("com.android.graphics.flags.display_bt2020_colorspace") public static final int DATASPACE_DISPLAY_BT2020 = 142999552; // 0x8860000
    field public static final int DATASPACE_DISPLAY_P3 = 143261696; // 0x88a0000
    field public static final int DATASPACE_DYNAMIC_DEPTH = 4098; // 0x1002
    field public static final int DATASPACE_HEIF = 4100; // 0x1004
+17 −1
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@
 */
package android.hardware;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.view.SurfaceControl;

import com.android.graphics.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@@ -639,6 +642,18 @@ public final class DataSpace {
     */
    public static final int DATASPACE_SRGB_LINEAR = 138477568;

    /**
     * Display BT. 2020 encoding.
     *
     * <p>Composed of the following -</p>
     * <pre>
     *   Primaries: STANDARD_BT2020
     *   Transfer: TRANSFER_SRGB
     *   Range: RANGE_FULL</pre>
     */
    @FlaggedApi(Flags.FLAG_DISPLAY_BT2020_COLORSPACE)
    public static final int DATASPACE_DISPLAY_BT2020 = 142999552;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, value = {
@@ -660,7 +675,8 @@ public final class DataSpace {
        DATASPACE_BT2020,
        DATASPACE_BT709,
        DATASPACE_DCI_P3,
        DATASPACE_SRGB_LINEAR
        DATASPACE_SRGB_LINEAR,
        DATASPACE_DISPLAY_BT2020
    })
    public @interface NamedDataSpace {};

+9 −0
Original line number Diff line number Diff line
@@ -33,3 +33,12 @@ flag {
  description: "Add OkLab ColorSpace support"
  bug: "344038816"
}

flag {
  name: "display_bt2020_colorspace"
  is_exported: true
  is_fixed_read_only: true
  namespace: "core_graphics"
  description: "Add DISPLAY_BT2020 ColorSpace support"
  bug: "344038816"
}
+51 −1
Original line number Diff line number Diff line
@@ -768,7 +768,44 @@ public abstract class ColorSpace {
         * </table>
         */
        @FlaggedApi(Flags.FLAG_OK_LAB_COLORSPACE)
        OK_LAB
        OK_LAB,

        /**
         * <p>{@link ColorSpace.Rgb RGB} color space BT.2020 based on Rec. ITU-R BT.2020-1 and IEC 61966-2.1:1999.</p></p>
         * <table summary="Color space definition">
         *     <tr>
         *         <th>Chromaticity</th><th>Red</th><th>Green</th><th>Blue</th><th>White point</th>
         *     </tr>
         *     <tr><td>x</td><td>0.708</td><td>0.170</td><td>0.131</td><td>0.3127</td></tr>
         *     <tr><td>y</td><td>0.292</td><td>0.797</td><td>0.046</td><td>0.3290</td></tr>
         *     <tr><th>Property</th><th colspan="4">Value</th></tr>
         *     <tr><td>Name</td><td colspan="4">Rec. ITU-R BT.2020-1</td></tr>
         *     <tr><td>CIE standard illuminant</td><td colspan="4">D65</td></tr>
         *     <tr>
         *         <td>Opto-electronic transfer function (OETF)</td>
         *         <td colspan="4">\(\begin{equation}
         *             C_{DisplayBT2020} = \begin{cases} 12.92 \times C_{linear} & C_{linear} \lt 0.0030186 \\\
         *             1.055 \times C_{linear}^{\frac{1}{2.4}} - 0.055 & C_{linear} \ge 0.0030186 \end{cases}
         *             \end{equation}\)
         *         </td>
         *     </tr>
         *     <tr>
         *         <td>Electro-optical transfer function (EOTF)</td>
         *         <td colspan="4">\(\begin{equation}
         *             C_{linear} = \begin{cases}\frac{C_{DisplayBT2020}}{12.92} & C_{sRGB} \lt 0.04045 \\\
         *             \left( \frac{C_{DisplayBT2020} + 0.055}{1.055} \right) ^{2.4} & C_{sRGB} \ge 0.04045 \end{cases}
         *             \end{equation}\)
         *         </td>
         *     </tr>
         *     <tr><td>Range</td><td colspan="4">\([0..1]\)</td></tr>
         * </table>
         * <p>
         *     <img style="display: block; margin: 0 auto;" src="{@docRoot}reference/android/images/graphics/colorspace_bt2020.png" />
         *     <figcaption style="text-align: center;">BT.2020 (orange) vs sRGB (white)</figcaption>
         * </p>
         */
        @FlaggedApi(Flags.FLAG_DISPLAY_BT2020_COLORSPACE)
        DISPLAY_BT2020
        // Update the initialization block next to #get(Named) when adding new values
    }

@@ -1721,6 +1758,19 @@ public abstract class ColorSpace {
                    Named.OK_LAB.ordinal()
            ));
        }

        if (Flags.displayBt2020Colorspace()) {
            sNamedColorSpaceMap.put(Named.DISPLAY_BT2020.ordinal(), new ColorSpace.Rgb(
                    "BT 2020",
                    BT2020_PRIMARIES,
                    ILLUMINANT_D65,
                    null,
                    SRGB_TRANSFER_PARAMETERS,
                    Named.DISPLAY_BT2020.ordinal()
            ));
            sDataToColorSpaces.put(DataSpace.DATASPACE_DISPLAY_BT2020,
                    Named.DISPLAY_BT2020.ordinal());
        }
    }

    private static double transferHLGOETF(Rgb.TransferParameters params, double x) {
+10 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "Color.h"

#include <Properties.h>
#include <aidl/android/hardware/graphics/common/Dataspace.h>
#include <android/hardware_buffer.h>
#include <android/native_window.h>
#include <ui/ColorSpace.h>
@@ -25,6 +26,8 @@
#include <algorithm>
#include <cmath>

#include "SkColorSpace.h"

namespace android {
namespace uirenderer {

@@ -215,9 +218,13 @@ android_dataspace ColorSpaceToADataSpace(SkColorSpace* colorSpace, SkColorType c
        return HAL_DATASPACE_ADOBE_RGB;
    }

    if (nearlyEqual(fn, SkNamedTransferFn::kRec2020) &&
        nearlyEqual(gamut, SkNamedGamut::kRec2020)) {
    if (nearlyEqual(gamut, SkNamedGamut::kRec2020)) {
        if (nearlyEqual(fn, SkNamedTransferFn::kRec2020)) {
            return HAL_DATASPACE_BT2020;
        } else if (nearlyEqual(fn, SkNamedTransferFn::kSRGB)) {
            return static_cast<android_dataspace>(
                    ::aidl::android::hardware::graphics::common::Dataspace::DISPLAY_BT2020);
        }
    }

    if (nearlyEqual(fn, k2Dot6) && nearlyEqual(gamut, kDCIP3)) {