Java Utililty Methods RGB Color Convert To

List of utility methods to do RGB Color Convert To

Description

The list of methods to do RGB Color Convert To are organized into topic(s).

Method

int[]rgb2lab(int R, int G, int B)
rgblab
float r, g, b, X, Y, Z, fx, fy, fz, xr, yr, zr;
float Ls, as, bs;
float eps = 216.f / 24389.f;
float k = 24389.f / 27.f;
float Xr = 0.964221f; 
float Yr = 1.0f;
float Zr = 0.825211f;
r = R / 255.f; 
...
double[]rgb2luv(double[] rgb, double[] luv)
Converts color components from the CIE L*u*v* to the sRGB color space.
double[] xyz = rgb2xyz(rgb, null);
return xyz2luv(xyz, luv);
double[]rgb2xyz(double[] RGB)
Converts from the given RGB triplet into a corresponding XYZ triplet.
double[] xyz = new double[3];
double[] rgb = new double[3];
System.arraycopy(RGB, 0, rgb, 0, 3);
for (int i = 0; i < 3; i++) {
    if (rgb[i] > 0.04045) {
        rgb[i] = Math.pow((rgb[i] + 0.055) / 1.055, 2.4);
    } else {
        rgb[i] = rgb[i] / 12.92;
...
double[]rgb2xyz(double[] rgb, double[] xyz)
Converts color components from the sRGB to the CIE XYZ color space.
if (xyz == null) {
    xyz = new double[rgb.length];
double[] rgbLin = new double[rgb.length];
for (int i = 0; i < rgb.length; i++) {
    if (rgb[i] <= 0.04045) {
        rgbLin[i] = rgb[i] / 12.92;
    } else {
...
int[]RGB2YCbCr(int r, int g, int b, boolean useBT601)
Convert RGB color info to YCBCr
int[] yCbCr = new int[3];
double y, cb, cr;
if (useBT601) {
    y = r * 0.299 * 219 / 255 + g * 0.587 * 219 / 255 + b * 0.114 * 219 / 255;
    cb = -r * 0.168736 * 224 / 255 - g * 0.331264 * 224 / 255 + b * 0.5 * 224 / 255;
    cr = r * 0.5 * 224 / 255 - g * 0.418688 * 224 / 255 - b * 0.081312 * 224 / 255;
} else {
    y = r * 0.2126 * 219 / 255 + g * 0.7152 * 219 / 255 + b * 0.0722 * 219 / 255;
...
voidRGB2YCbCr(int[] rgb, float[][] Y, float[][] Cb, float[][] Cr, int imageWidth, int imageHeight)
RGBY Cb Cr
int red, green, blue, index = 0;
for (int i = 0; i < imageHeight; i++) {
    for (int j = 0; j < imageWidth; j++) {
        red = ((rgb[index] >> 16) & 0xff);
        green = ((rgb[index] >> 8) & 0xff);
        blue = (rgb[index++] & 0xff);
        Y[i][j] = (0.299f * red + 0.587f * green + 0.114f * blue) - 128.0f;
        Cb[i][j] = -0.1687f * red - 0.3313f * green + 0.5f * blue;
...
voidrgb2yuv(float r, float g, float b, float[] yuv)
rgbyuv
yuv[0] = .299f * r + .587f * g + .114f * b;
yuv[1] = -.14713f * r + -.28886f * g + .436f * b;
yuv[2] = .615f * r + -.51499f * g + -.10001f * b;
voidrgb565ToRGB(short pixel, byte[] rgb)
rgb To RGB
int r = (pixel >> 11) & 0x1f;
int g = (pixel >> 5) & 0x3f;
int b = (pixel) & 0x1f;
rgb[0] = (byte) (r * 0xff / 0x1f);
rgb[1] = (byte) (g * 0xff / 0x3f);
rgb[2] = (byte) (b * 0xff / 0x1f);
intrgb8ToPixel(byte[] nrgb)
rgb To Pixel
return ((nrgb[0] & 0xff) << 16) | ((nrgb[1] & 0xff) << 8) | (nrgb[2] & 0xff);
shortrgb8ToRgbRBXG(byte[] rgb)
rgb To Rgb RBXG
return (short) ((((rgb[0] >> 5) & 0x7) << 12) | (((rgb[2] >> 5) & 0x7) << 8)
        | (((rgb[1] >> 5) & 0x7) << 0));