Java RGB Color Convert To rgbToY(int rgb)

Here you can find the source of rgbToY(int rgb)

Description

rgb To Y

License

Open Source License

Declaration

public static int rgbToY(int rgb) 

Method Source Code

//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);
    }
}

Related

  1. rgbToString(float r, float g, float b)
  2. rgbToText(int red, int green, int blue)
  3. rgbToUnscaledYUV(int[][] rgb)
  4. RGBtoXYZ(float r, float g, float b)
  5. rgbToXyz(int r, int g, int b)