GraphicsUtils { public static double[] xyz2luv(double[] xyz, double[] luv) { double tmp = xyz[0] + 15.0*xyz[1] + 3.0*xyz[2]; if (tmp == 0.0) { tmp = 1.0; } double u1 = 4.0*xyz[0]/tmp; double v1 = 9.0*xyz[1]/tmp; double yr = xyz[1]/XYZ_R_D50[1]; double ur = 4.0*XYZ_R_D50[0]/(XYZ_R_D50[0] + 15.0*XYZ_R_D50[1] + 3.0*XYZ_R_D50[2]); double vr = 9.0*XYZ_R_D50[1]/(XYZ_R_D50[0] + 15.0*XYZ_R_D50[1] + 3.0*XYZ_R_D50[2]); if (luv == null) { luv = new double[xyz.length]; } if (yr > CIE_EPSILON) { luv[0] = 116.0*Math.pow(yr, 1.0/3.0) - 16.0; } else { luv[0] = CIE_KAPPA*yr; } luv[1] = 13.0*luv[0]*(u1 - ur); luv[2] = 13.0*luv[0]*(v1 - vr); return luv; } protected  GraphicsUtils(); static Shape getOutline(String text, Font font, float wrappingWidth,
			double alignment); static void fillPaintedShape(Graphics2D graphics, Shape shape,
			Paint paint, Rectangle2D paintBounds); static void drawPaintedShape(Graphics2D graphics, Shape shape,
			Paint paint, Rectangle2D paintBounds, Stroke stroke); static double[] rgb2xyz(double[] rgb, double[] xyz); static double[] luv2xyz(double[] luv, double[] xyz); static double[] xyz2rgb(double[] xyz, double[] rgb); static double[] xyz2luv(double[] xyz, double[] luv); static double[] rgb2luv(double[] rgb, double[] luv); static double[] luv2rgb(double[] luv, double[] rgb); static Color blend(Color color1, Color color2, double weight); static Color deriveWithAlpha(Color color, int alpha); static Color deriveDarker(Color color); static Color deriveBrighter(Color color);  }
@Test public void testXyz2Luv() { double[] luv = new double[3]; GraphicsUtils.xyz2luv(new double[] { 0.0, 0.0, 0.0 }, luv); assertEqualsArray(new double[] { 0.00000000000000, 0.0000000000000000, 0.000000000000000 }, luv, DELTA); GraphicsUtils.xyz2luv(new double[] { 0.0, 0.5, 1.0 }, luv); assertEqualsArray(new double[] { 76.06926101415557,-206.8386281184853600, -58.841402958935040 }, luv, DELTA); GraphicsUtils.xyz2luv(new double[] { 0.5, 0.5, 0.5 }, luv); assertEqualsArray(new double[] { 76.06926101415557, 1.3509283413088070, -14.229355146122007 }, luv, DELTA); GraphicsUtils.xyz2luv(new double[] { 1.0, 0.5, 0.0 }, luv); assertEqualsArray(new double[] { 76.06926101415557, 258.5262627916428000, 40.879645093235310 }, luv, DELTA); GraphicsUtils.xyz2luv(new double[] { 1.0, 1.0, 1.0 }, luv); assertEqualsArray(new double[] {100.00000000000000, 1.7759188446137468, -18.705788588473464 }, luv, DELTA); GraphicsUtils.xyz2luv(new double[] { 0.0012612441091978614, 0.0011070564598794539,-0.00007748319319977360 }, luv); assertEqualsArray(new double[] { 1.00000000000000, 1.0000000000000000, 1.000000000000000 }, luv, DELTA); }