Skip to content

Commit

Permalink
[M3][Color] Refactored material color utilities library into its own …
Browse files Browse the repository at this point in the history
…directory.

PiperOrigin-RevId: 479289696
  • Loading branch information
Material Design Team authored and paulfthomas committed Oct 6, 2022
1 parent 62b2b19 commit 9897bc2
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 17 deletions.
Expand Up @@ -32,6 +32,8 @@
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import com.google.android.material.color.utilities.Blend;
import com.google.android.material.color.utilities.Hct;
import com.google.android.material.resources.MaterialAttributes;

/**
Expand Down
Expand Up @@ -14,12 +14,20 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import static java.lang.Math.min;

/** Functions for blending in HCT and CAM16. */
final class Blend {
import androidx.annotation.RestrictTo;

/**
* Functions for blending in HCT and CAM16.
*
* @hide
*/
@RestrictTo(LIBRARY_GROUP)
public final class Blend {
private static final float HARMONIZE_MAX_DEGREES = 15.0f;
private static final float HARMONIZE_PERCENTAGE = 0.5f;

Expand Down
Expand Up @@ -14,10 +14,13 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import static java.lang.Math.max;

import androidx.annotation.RestrictTo;

/**
* CAM16, a color appearance model. Colors are not just defined by their hex code, but rather, a hex
* code and viewing conditions.
Expand All @@ -32,8 +35,11 @@
*
* <p>For example, white under the traditional assumption of a midday sun white point is accurately
* measured as a slightly chromatic blue by CAM16. (roughly, hue 203, chroma 3, lightness 100)
*
* @hide
*/
final class Cam16 {
@RestrictTo(LIBRARY_GROUP)
public final class Cam16 {
// Transforms XYZ color space coordinates to 'cone'/'RGB' responses in CAM16.
static final float[][] XYZ_TO_CAM16RGB = {
{0.401288f, 0.650173f, -0.051461f},
Expand Down
Expand Up @@ -14,14 +14,23 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.RestrictTo;
import java.util.Arrays;

/**
* Utility methods for color science constants and color space conversions that aren't HCT or CAM16.
* Color science utilities.
*
* <p>Utility methods for color science constants and color space conversions that aren't HCT or
* CAM16.
*
* @hide
*/
final class ColorUtils {
@RestrictTo(LIBRARY_GROUP)
public final class ColorUtils {
private ColorUtils() {}

private static final float[] WHITE_POINT_D65 = {95.047f, 100.0f, 108.883f};
Expand Down
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.RestrictTo;

/**
* A color system built using CAM16 hue and chroma, and L* from L*a*b*.
Expand All @@ -34,8 +38,11 @@
* HCT, hue, chroma, and tone. A color system that provides a perceptually accurate color
* measurement system that can also accurately render what colors will appear as in different
* lighting environments.
*
* @hide
*/
final class Hct {
@RestrictTo(LIBRARY_GROUP)
public final class Hct {
private float hue;
private float chroma;
private float tone;
Expand Down
Expand Up @@ -14,13 +14,21 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import static java.lang.Math.max;
import static java.lang.Math.min;

/** Utility methods for mathematical operations. */
final class MathUtils {
import androidx.annotation.RestrictTo;

/**
* Utility methods for mathematical operations.
*
* @hide
*/
@RestrictTo(LIBRARY_GROUP)
public final class MathUtils {
private MathUtils() {}
/** Ensure min <= input <= max */
static float clamp(float min, float max, float input) {
Expand Down
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import androidx.annotation.RestrictTo;

/**
* In traditional color spaces, a color can be identified solely by the observer's measurement of
Expand All @@ -26,8 +30,11 @@
*
* <p>This class caches intermediate values of the CAM16 conversion process that depend only on
* viewing conditions, enabling speed ups.
*
* @hide
*/
final class ViewingConditions {
@RestrictTo(LIBRARY_GROUP)
public final class ViewingConditions {
/** sRGB-like viewing conditions. */
public static final ViewingConditions DEFAULT =
ViewingConditions.make(
Expand Down
Expand Up @@ -24,6 +24,8 @@
import androidx.annotation.ColorInt;
import androidx.annotation.IntRange;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.material.color.utilities.Blend;
import com.google.android.material.color.utilities.Hct;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static com.google.common.truth.Truth.assertThat;

Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.android.material.color;
package com.google.android.material.color.utilities;

import static org.junit.Assert.assertEquals;

Expand Down

0 comments on commit 9897bc2

Please sign in to comment.