1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.ui.graphics.colorspace 18 19 import androidx.annotation.Size 20 21 /** 22 * Class for constructing white points used in [RGB][Rgb] color space. The value is stored in the 23 * CIE xyY color space. The Y component of the white point is assumed to be 1. 24 * 25 * @see Illuminant 26 */ 27 @Suppress("DataClassDefinition") 28 data class WhitePoint(val x: Float, val y: Float) { 29 /** Illuminant for CIE XYZ white point */ 30 constructor(x: Float, y: Float, z: Float) : this(x, y, z, x + y + z) 31 32 @Suppress("UNUSED_PARAMETER") 33 private constructor(x: Float, y: Float, z: Float, sum: Float) : this(x / sum, y / sum) 34 35 /** 36 * Converts a value from CIE xyY to CIE XYZ. Y is assumed to be 1 so the input xyY array only 37 * contains the x and y components. 38 * 39 * @return A new float array of length 3 containing XYZ values 40 */ 41 @Size(3) toXyznull42 internal fun toXyz(): FloatArray { 43 return floatArrayOf(x / y, 1.0f, (1f - x - y) / y) 44 } 45 } 46