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

Commit 53b03c0f authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Clean up ColorSpace.java

Bug: 156282935
Test: I3ce1bbd4285443a4e481a0a1e9267feafbe49d44
Test: DisplayWhiteBalanceTintControllerTest

Remove cctToIlluminantdXyz, which was @hide, but unused.

Make the @hide constructor package-protected so it can be called by
ParcelableColorSpace, but not from outside the package.

Make cctToXyz and chromaticAdaptation public. These are used by
other parts of the system and may be useful to other clients. Make the
public version of chromaticAdaptation throw IllegalArgumentExceptions
for passing arrays with the wrong number of arguments.

Make mul3x3(float[], float[]) private and copy it over to
DisplayWhiteBalanceTintController. There is nothing ColorSpace-specific
about this code.

Remove Renderer and related. They were originally used to generate the
documentation pages, but they are no longer needed. Remove
ColorSpaceRenderTest, which tested it.

Change-Id: I9094046c8e5e72be0ac208d4d242e6f0b274f386
parent 4b91335d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14487,6 +14487,8 @@ package android.graphics {
  @AnyThread public abstract class ColorSpace {
    method @NonNull public static android.graphics.ColorSpace adapt(@NonNull android.graphics.ColorSpace, @NonNull @Size(min=2, max=3) float[]);
    method @NonNull public static android.graphics.ColorSpace adapt(@NonNull android.graphics.ColorSpace, @NonNull @Size(min=2, max=3) float[], @NonNull android.graphics.ColorSpace.Adaptation);
    method @NonNull @Size(3) public static float[] cctToXyz(@IntRange(from=1) int);
    method @NonNull @Size(9) public static float[] chromaticAdaptation(@NonNull android.graphics.ColorSpace.Adaptation, @NonNull @Size(min=2, max=3) float[], @NonNull @Size(min=2, max=3) float[]);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace.RenderIntent);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace);
+0 −75
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class ColorSpaceRendererTest {

    @Test
    public void testRendererSize() {
        Bitmap b = ColorSpace.createRenderer()
                .size(0)
                .render();
        assertEquals(128, b.getWidth());
        assertEquals(128, b.getHeight());

        b = ColorSpace.createRenderer()
                .size(768)
                .render();
        assertEquals(768, b.getWidth());
        assertEquals(768, b.getHeight());
    }

    @Test
    public void testRenderer() {
        Bitmap b = ColorSpace.createRenderer()
                .size(1024)
                .clip(true)
                .showWhitePoint(false)
                .add(ColorSpace.get(ColorSpace.Named.SRGB), 0xffffffff)
                .add(ColorSpace.get(ColorSpace.Named.DCI_P3), 0xffffffff)
                .add(ColorSpace.get(ColorSpace.Named.PRO_PHOTO_RGB), 0.1f, 0.5f, 0.1f, 0xff000000)
                .add(ColorSpace.get(ColorSpace.Named.ADOBE_RGB), 0.1f, 0.5f, 0.1f, 0xff000000)
                .render();
        assertNotNull(b);
    }

    @Test
    public void testUcsRenderer() {
        Bitmap b = ColorSpace.createRenderer()
                .size(1024)
                .clip(true)
                .showWhitePoint(false)
                .uniformChromaticityScale(true)
                .add(ColorSpace.get(ColorSpace.Named.SRGB), 0xffffffff)
                .add(ColorSpace.get(ColorSpace.Named.DCI_P3), 0xffffffff)
                .add(ColorSpace.get(ColorSpace.Named.PRO_PHOTO_RGB), 0.1f, 0.5f, 0.1f, 0xff000000)
                .add(ColorSpace.get(ColorSpace.Named.ADOBE_RGB), 0.1f, 0.5f, 0.1f, 0xff000000)
                .render();
        assertNotNull(b);
    }
}
+6 −850

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -14469,6 +14469,8 @@ package android.graphics {
  @AnyThread public abstract class ColorSpace {
    method @NonNull public static android.graphics.ColorSpace adapt(@NonNull android.graphics.ColorSpace, @NonNull @Size(min=2, max=3) float[]);
    method @NonNull public static android.graphics.ColorSpace adapt(@NonNull android.graphics.ColorSpace, @NonNull @Size(min=2, max=3) float[], @NonNull android.graphics.ColorSpace.Adaptation);
    method @NonNull @Size(3) public static float[] cctToXyz(@IntRange(from=1) int);
    method @NonNull @Size(9) public static float[] chromaticAdaptation(@NonNull android.graphics.ColorSpace.Adaptation, @NonNull @Size(min=2, max=3) float[], @NonNull @Size(min=2, max=3) float[]);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace, @NonNull android.graphics.ColorSpace.RenderIntent);
    method @NonNull public static android.graphics.ColorSpace.Connector connect(@NonNull android.graphics.ColorSpace);
+28 −3
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.display.color;

import static com.android.server.display.color.DisplayTransformManager.LEVEL_COLOR_MATRIX_DISPLAY_WHITE_BALANCE;

import android.annotation.NonNull;
import android.annotation.Size;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.ColorSpace;
@@ -32,7 +34,6 @@ import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;

import java.io.PrintWriter;
import java.lang.System;

final class DisplayWhiteBalanceTintController extends TintController {

@@ -131,6 +132,30 @@ final class DisplayWhiteBalanceTintController extends TintController {
                : ColorDisplayService.MATRIX_IDENTITY;
    }

    /**
     * Multiplies two 3x3 matrices, represented as non-null arrays of 9 floats.
     *
     * @param lhs 3x3 matrix, as a non-null array of 9 floats
     * @param rhs 3x3 matrix, as a non-null array of 9 floats
     * @return A new array of 9 floats containing the result of the multiplication
     *         of rhs by lhs
     */
    @NonNull
    @Size(9)
    private static float[] mul3x3(@NonNull @Size(9) float[] lhs, @NonNull @Size(9) float[] rhs) {
        float[] r = new float[9];
        r[0] = lhs[0] * rhs[0] + lhs[3] * rhs[1] + lhs[6] * rhs[2];
        r[1] = lhs[1] * rhs[0] + lhs[4] * rhs[1] + lhs[7] * rhs[2];
        r[2] = lhs[2] * rhs[0] + lhs[5] * rhs[1] + lhs[8] * rhs[2];
        r[3] = lhs[0] * rhs[3] + lhs[3] * rhs[4] + lhs[6] * rhs[5];
        r[4] = lhs[1] * rhs[3] + lhs[4] * rhs[4] + lhs[7] * rhs[5];
        r[5] = lhs[2] * rhs[3] + lhs[5] * rhs[4] + lhs[8] * rhs[5];
        r[6] = lhs[0] * rhs[6] + lhs[3] * rhs[7] + lhs[6] * rhs[8];
        r[7] = lhs[1] * rhs[6] + lhs[4] * rhs[7] + lhs[7] * rhs[8];
        r[8] = lhs[2] * rhs[6] + lhs[5] * rhs[7] + lhs[8] * rhs[8];
        return r;
    }

    @Override
    public void setMatrix(int cct) {
        if (!mSetUp) {
@@ -160,9 +185,9 @@ final class DisplayWhiteBalanceTintController extends TintController {
                            mDisplayNominalWhiteXYZ, mCurrentColorTemperatureXYZ);

            // Convert the adaptation matrix to RGB space
            float[] result = ColorSpace.mul3x3(mChromaticAdaptationMatrix,
            float[] result = mul3x3(mChromaticAdaptationMatrix,
                    mDisplayColorSpaceRGB.getTransform());
            result = ColorSpace.mul3x3(mDisplayColorSpaceRGB.getInverseTransform(), result);
            result = mul3x3(mDisplayColorSpaceRGB.getInverseTransform(), result);

            // Normalize the transform matrix to peak white value in RGB space
            final float adaptedMaxR = result[0] + result[3] + result[6];