@Test public void testLABToXYZ() { for (TestEntry entry : sEntryList) { verifyLABToXYZ(entry.lab, entry.xyz); } }
public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l, @FloatRange(from = -128, to = 127) final double a, @FloatRange(from = -128, to = 127) final double b, @NonNull double[] outXyz) { final double fy = (l + 16) / 116; final double fx = a / 500 + fy; final double fz = fy - b / 200; double tmp = Math.pow(fx, 3); final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA; final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA; tmp = Math.pow(fz, 3); final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA; outXyz[0] = xr * XYZ_WHITE_REFERENCE_X; outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y; outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z; }
ColorUtils { public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l, @FloatRange(from = -128, to = 127) final double a, @FloatRange(from = -128, to = 127) final double b, @NonNull double[] outXyz) { final double fy = (l + 16) / 116; final double fx = a / 500 + fy; final double fz = fy - b / 200; double tmp = Math.pow(fx, 3); final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA; final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA; tmp = Math.pow(fz, 3); final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA; outXyz[0] = xr * XYZ_WHITE_REFERENCE_X; outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y; outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z; } }
ColorUtils { public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l, @FloatRange(from = -128, to = 127) final double a, @FloatRange(from = -128, to = 127) final double b, @NonNull double[] outXyz) { final double fy = (l + 16) / 116; final double fx = a / 500 + fy; final double fz = fy - b / 200; double tmp = Math.pow(fx, 3); final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA; final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA; tmp = Math.pow(fz, 3); final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA; outXyz[0] = xr * XYZ_WHITE_REFERENCE_X; outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y; outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z; } private  ColorUtils(); }
ColorUtils { public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l, @FloatRange(from = -128, to = 127) final double a, @FloatRange(from = -128, to = 127) final double b, @NonNull double[] outXyz) { final double fy = (l + 16) / 116; final double fx = a / 500 + fy; final double fz = fy - b / 200; double tmp = Math.pow(fx, 3); final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA; final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA; tmp = Math.pow(fz, 3); final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA; outXyz[0] = xr * XYZ_WHITE_REFERENCE_X; outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y; outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z; } private  ColorUtils(); static int compositeColors(@ColorInt int foreground, @ColorInt int background); @RequiresApi(26) @NonNull static Color compositeColors(@NonNull Color foreground, @NonNull Color background); @FloatRange(from = 0.0, to = 1.0) static double calculateLuminance(@ColorInt int color); static double calculateContrast(@ColorInt int foreground, @ColorInt int background); static int calculateMinimumAlpha(@ColorInt int foreground, @ColorInt int background,
            float minContrastRatio); static void RGBToHSL(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull float[] outHsl); static void colorToHSL(@ColorInt int color, @NonNull float[] outHsl); @ColorInt static int HSLToColor(@NonNull float[] hsl); @ColorInt static int setAlphaComponent(@ColorInt int color,
            @IntRange(from = 0x0, to = 0xFF) int alpha); static void colorToLAB(@ColorInt int color, @NonNull double[] outLab); static void RGBToLAB(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull double[] outLab); static void colorToXYZ(@ColorInt int color, @NonNull double[] outXyz); static void RGBToXYZ(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull double[] outXyz); static void XYZToLAB(@FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_X) double x,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Y) double y,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Z) double z,
            @NonNull double[] outLab); static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l,
            @FloatRange(from = -128, to = 127) final double a,
            @FloatRange(from = -128, to = 127) final double b,
            @NonNull double[] outXyz); @ColorInt static int XYZToColor(@FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_X) double x,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Y) double y,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Z) double z); @ColorInt static int LABToColor(@FloatRange(from = 0f, to = 100) final double l,
            @FloatRange(from = -128, to = 127) final double a,
            @FloatRange(from = -128, to = 127) final double b); static double distanceEuclidean(@NonNull double[] labX, @NonNull double[] labY); @ColorInt static int blendARGB(@ColorInt int color1, @ColorInt int color2,
            @FloatRange(from = 0.0, to = 1.0) float ratio); static void blendHSL(@NonNull float[] hsl1, @NonNull float[] hsl2,
            @FloatRange(from = 0.0, to = 1.0) float ratio, @NonNull float[] outResult); static void blendLAB(@NonNull double[] lab1, @NonNull double[] lab2,
            @FloatRange(from = 0.0, to = 1.0) double ratio, @NonNull double[] outResult); }
ColorUtils { public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l, @FloatRange(from = -128, to = 127) final double a, @FloatRange(from = -128, to = 127) final double b, @NonNull double[] outXyz) { final double fy = (l + 16) / 116; final double fx = a / 500 + fy; final double fz = fy - b / 200; double tmp = Math.pow(fx, 3); final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA; final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA; tmp = Math.pow(fz, 3); final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA; outXyz[0] = xr * XYZ_WHITE_REFERENCE_X; outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y; outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z; } private  ColorUtils(); static int compositeColors(@ColorInt int foreground, @ColorInt int background); @RequiresApi(26) @NonNull static Color compositeColors(@NonNull Color foreground, @NonNull Color background); @FloatRange(from = 0.0, to = 1.0) static double calculateLuminance(@ColorInt int color); static double calculateContrast(@ColorInt int foreground, @ColorInt int background); static int calculateMinimumAlpha(@ColorInt int foreground, @ColorInt int background,
            float minContrastRatio); static void RGBToHSL(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull float[] outHsl); static void colorToHSL(@ColorInt int color, @NonNull float[] outHsl); @ColorInt static int HSLToColor(@NonNull float[] hsl); @ColorInt static int setAlphaComponent(@ColorInt int color,
            @IntRange(from = 0x0, to = 0xFF) int alpha); static void colorToLAB(@ColorInt int color, @NonNull double[] outLab); static void RGBToLAB(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull double[] outLab); static void colorToXYZ(@ColorInt int color, @NonNull double[] outXyz); static void RGBToXYZ(@IntRange(from = 0x0, to = 0xFF) int r,
            @IntRange(from = 0x0, to = 0xFF) int g, @IntRange(from = 0x0, to = 0xFF) int b,
            @NonNull double[] outXyz); static void XYZToLAB(@FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_X) double x,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Y) double y,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Z) double z,
            @NonNull double[] outLab); static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l,
            @FloatRange(from = -128, to = 127) final double a,
            @FloatRange(from = -128, to = 127) final double b,
            @NonNull double[] outXyz); @ColorInt static int XYZToColor(@FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_X) double x,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Y) double y,
            @FloatRange(from = 0f, to = XYZ_WHITE_REFERENCE_Z) double z); @ColorInt static int LABToColor(@FloatRange(from = 0f, to = 100) final double l,
            @FloatRange(from = -128, to = 127) final double a,
            @FloatRange(from = -128, to = 127) final double b); static double distanceEuclidean(@NonNull double[] labX, @NonNull double[] labY); @ColorInt static int blendARGB(@ColorInt int color1, @ColorInt int color2,
            @FloatRange(from = 0.0, to = 1.0) float ratio); static void blendHSL(@NonNull float[] hsl1, @NonNull float[] hsl2,
            @FloatRange(from = 0.0, to = 1.0) float ratio, @NonNull float[] outResult); static void blendLAB(@NonNull double[] lab1, @NonNull double[] lab2,
            @FloatRange(from = 0.0, to = 1.0) double ratio, @NonNull double[] outResult);  }