Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// FPlayAndroid is distributed under the FreeBSD License

public class Main {
    public static double relativeLuminance(int rgb) {
        //http://www.w3.org/TR/2007/WD-WCAG20-TECHS-20070517/Overview.html#G18
        double RsRGB = (double) ((rgb >>> 16) & 0xff) / 255.0, GsRGB = (double) ((rgb >>> 8) & 0xff) / 255.0,
                BsRGB = (double) (rgb & 0xff) / 255.0, R, G, B;
        if (RsRGB <= 0.03928)
            R = RsRGB / 12.92;
        else
            R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
        if (GsRGB <= 0.03928)
            G = GsRGB / 12.92;
        else
            G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
        if (BsRGB <= 0.03928)
            B = BsRGB / 12.92;
        else
            B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
        return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
    }
}