Here you can find the source of rgbToY(int rgb)
public static int rgbToY(int rgb)
//package com.java2s; /*//from ww w. ja v a 2 s . com * JaamSim Discrete Event Simulation * Copyright (C) 2012 Ausenco Engineering Canada Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ public class Main { public static int rgbToY(int rgb) { int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = (rgb) & 0xff; return (int) (16 + 0.2568 * r + 0.5052 * g + 0.0979 * b); } }