ColorHelper { public static int colorFromFloatComponents(float red, float green, float blue, Float alpha) { if (alpha == null) { alpha = 1.0F; } if (red > 1.0) { red = 1.0F; } if (green > 1.0) { green = 1.0F; } if (blue > 1.0) { blue = 1.0F; } if (alpha > 1.0) { alpha = 1.0F; } red *= 255.0F; blue *= 255.0F; green *= 255.0F; alpha *= 255.0F; return colorFromComponents((int)Math.floor(red), (int)Math.floor(green), (int)Math.floor(blue), (int)Math.floor(alpha)); } private  ColorHelper(); static int getAlpha(final int color); static int increaseAlpha(final int color, final double amount); static boolean isColorDefinition(String color); static boolean isOpaque(int color); static boolean isTransparent(int color); @Deprecated static int makeColor(float red, float green, float blue); @Deprecated static int makeColor(float red, float green, float blue,
                                float alpha); static int colorFromFloatComponents(float red, float green, float blue,
                                Float alpha); static int makeColor(int red, int green, int blue); static int makeColor(int red, int green, int blue, int alpha); static int colorFromComponents(int red, int green, int blue, Integer alpha); static int makeColor(final int red, final int green, final int blue, 
                                final int alpha, final int top); static int makeColor(String color); @Deprecated static int[] makeComponents(final int color); static int[] colorToComponents(final int color); static float[] colorToFloatComponents(int rgba); static int colorFromFloatComponents(float[] rgba); static Map<String, Integer> colorToComponents(final int color,
            Map<String, Integer> out); static int makeOpaque(int value); static int makeVisible(int value); static int makeVisible(int value, int threshold); static Integer makeVisible(int value, int threshold, Integer white,
            Integer black); static int neverTransparent(int color); static int setAlpha(final int color, final int alpha); static Map<String, Float> colorToHSV(int rgba, Map<String, Float> out); @Deprecated static float[] ColorToHSV(int rgba); static float[] colorToHSV(int rgba); static int shiftHue(int rgba, float shift); static int scaleSV(int rgba, float scaleS, float scaleV); static int colorFromHSV(float hue, float saturation, float value, Float alpha); static int colorFromHSV(Map<String, Float> hsva); @Deprecated static int ColorFromHSV(float[] hsva); static int colorFromHSV(float[] hsva); static int saturate(int rgba, float satStep); static void saturatePalette(ColorPalette pal, int startIdx, int endIdx, float satStep); static void repeatForPalette(ColorPalette pal, int startIdx, ColorTransformer transformer, Integer length); static void repeatForPalette(ColorPalette pal, int startIdx, int endIdx, ColorTransformer transformer); static int multiply(int rgba1, int rgba2); static int multiply(int rgba1, float value); static int add(int rgba1, int rgba2); static int subtract(int rgba1, int rgba2); static int lerp(int rgba1, int rgba2, float weight); static int lerp(int rgba1, int rgba2); static int lerp(int rgba1, int rgba2, float[] weight); @Deprecated static int lerp(int rgba1, int rgba2, int weight); static int colorFromComponents(Map<String, Integer> components); static int colorFromComponents(int[] components); static List<Integer> createGradient(int colors, Integer... rgbaColors); static List<Integer> lookup(ColorPalette in, String... namesOrColorDefs); static List<Integer> lookup(ColorPalette in, Integer... indexesOrColors); static List<Integer> extendGradient(List<Integer> out, int colors, List<Integer> colorValues); static List<Integer> extendGradient(List<Integer> out, int colors, int colorValue); static List<Integer> createGradient(List<Integer> out, int colors,
            List<Integer> rgbaColors); static int guessBlack(ColorPalette palette); static int guessWhite(ColorPalette palette); static Set<Integer> findChangedColors(ColorPalette newPalette, ColorPalette oldPalette); static final String HUE; static final String SATURATION; static final String VALUE; static final String ALPHA; static final String RED; static final String GREEN; static final String BLUE; }
@Test @Covers("public static int colorFromFloatComponents(float[])") public void colorFromFloatComponents_floatarr() { float[] value = {1.0F, 1.0F, 1.0F, 1.0F}; assertEquals(WHITE, ColorHelper.colorFromFloatComponents(value)); value = new float[] {0F, 0F, 0F, 1.0F}; assertEquals(BLACK, ColorHelper.colorFromFloatComponents(value)); value = new float[] {1.0F, 0F, 0F, 1.0F}; assertEquals(RED, ColorHelper.colorFromFloatComponents(value)); value = new float[] {0F, 0F, 0F, 1F/255F}; assertEquals(NEAR_BLACK, ColorHelper.colorFromFloatComponents(value)); value = new float[] {0F, 0F, 0F, 0F}; assertEquals(TRANSPARENT, ColorHelper.colorFromFloatComponents(value)); }
@Test @Covers("public static int colorFromFloatComponents(float,float,float,Float)") public void colorFromFloatComponents_floats() { int got = ColorHelper.colorFromFloatComponents(1.0F, 1.0F, 1.0F, 1.0F); assertEquals(WHITE, got); got = ColorHelper.colorFromFloatComponents(0F, 0F, 0F, 1.0F); assertEquals(BLACK, got); got = ColorHelper.colorFromFloatComponents(1.0F, 0F, 0F, 1.0F); assertEquals(RED, got); got = ColorHelper.colorFromFloatComponents(0F, 0F, 0F, 1F/255F); assertEquals(NEAR_BLACK, got); got = ColorHelper.colorFromFloatComponents(0F, 0F, 0F, 0F); assertEquals(TRANSPARENT, got); }