Color correct with look-up tables (LUTs)

Varying HDR capabilities across Android devices can lead to fragmented HDR display outputs. A look-up table (LUT) is a new color correction solution designed to resolve this inconsistency. This inconsistency is resolved by prescribing a way to color correct, rather than delegating to an undefined per-device color correction mechanism.

SDK prerequisites

To implement LUTs, your SDK version must 36 or higher.

Implement a LUT

Follow these steps to apply a LUT to a SurfaceControl:

  1. Create a DisplayLuts instance.
  2. Create DisplayLuts.Entry instance(s) with the LUT data buffer, LUT dimension, and the sampling key of the LUT. For more information, see LutProperties documentation.
  3. Call DisplayLuts#set(DisplayLuts.Entry luts) or DisplayLuts#set(DisplayLuts.Entry first, DisplayLuts.Entry second) to set LUT entries. The framework supports 1D LUT, 3D LUT, or a combination of 1D and 3D LUTs.
  4. Call SurfaceControl.Transaction#setLuts to apply the LUTs to the layer.

Kotlin

val sc = SurfaceControl.Builder().build()
val luts = DisplayLuts()
val entry = DisplayLuts.Entry(
    floatArrayOf(0.5f, 0.5f, 0.5f, 0.5f),
    LutProperties.ONE_DIMENSION,
    LutProperties.SAMPLING_KEY_MAX_RGB
)
luts.set(entry)
SurfaceControl.Transaction().setLuts(sc, luts).apply()

Java

SurfaceControl sc = new SurfaceControl.Builder().build();
DisplayLuts luts = new DisplayLuts();
DisplayLuts.Entry entry = new DisplayLuts.Entry(
  new float[]{0.5f, 0.5f, 0.5f, 0.5f},
  LutProperties.ONE_DIMENSION,
  LutProperties.SAMPLING_KEY_MAX_RGB
);
luts.set(entry);
new SurfaceControl.Transaction().setLuts(sc, luts).apply();

You can also use OverlayProperties.getLutProperties() to understand the LUT properties of the device, and determine if the Hardware Composer can handle the selected LUT.