Java RGB Color Create RGBAequals(float[] rgba1, float[] rgba2, float eps)

Here you can find the source of RGBAequals(float[] rgba1, float[] rgba2, float eps)

Description

Checks if two colors differ within supplied epsilon.

License

BSD License

Parameter

Parameter Description
rgba1 first color
rgba2 second color

Return

true if any component differs by more than epsilon

Declaration

public static boolean RGBAequals(float[] rgba1, float[] rgba2, float eps) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**//from ww  w . j av a2  s.  c o m
     * Checks if two colors differ within supplied epsilon.  Colors must
     * have length of at least 3.  If only RGB is supplied, the alpha
     * component is assumed to be one.
     * @param rgba1 first color
     * @param rgba2 second color
     * @return true if any component differs by more than epsilon
     */
    public static boolean RGBAequals(float[] rgba1, float[] rgba2, float eps) {
        for (int i = 0; i < 3; ++i) {
            if (Math.abs(rgba1[i] - rgba2[2]) > eps) {
                return false;
            }
        }
        float a1 = 1;
        float a2 = 1;
        if (rgba1.length > 3) {
            a1 = rgba1[3];
        }
        if (rgba2.length > 3) {
            a2 = rgba2[3];
        }
        return (Math.abs(a1 - a2) <= eps);
    }
}

Related

  1. RGBA(int r, int g, int b, float a)
  2. RGBA(int r, int g, int b, int a)
  3. rgba(int red, int green, int blue)
  4. rgba_bilinear_filter(int rgb00, int rgb01, int rgb10, int rgb11, int u, int v)
  5. rgbaColour(int red, int green, int blue, int alpha)
  6. RGBAFromHEX(String stringValue)
  7. RGBAFromHSLA(float h, float s, float l, float a)
  8. rgbClamp(float c)
  9. rgbComponents(int argb)