Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static int XYZtoRGB(float[] xyz) {
        return XYZtoRGB(xyz[0], xyz[1], xyz[2]);
    }

    public static int XYZtoRGB(float x, float y, float z) {
        x /= 100f;
        y /= 100f;
        z /= 100f;

        float r = x * 3.2406f + y * -1.5372f + z * -0.4986f;
        float g = x * -0.9689f + y * 1.8758f + z * 0.0415f;
        float b = x * 0.0557f + y * -0.2040f + z * 1.0570f;

        if (r > 0.0031308) {
            r = 1.055f * (float) Math.pow(r, 1 / 2.4f) - 0.055f;
        } else {
            r = 12.92f * r;
        }

        if (g > 0.0031308) {
            g = 1.055f * (float) Math.pow(g, 1 / 2.4f) - 0.055f;
        } else {
            g = 12.92f * g;
        }

        if (b > 0.0031308) {
            b = 1.055f * (float) Math.pow(b, 1 / 2.4f) - 0.055f;
        } else {
            b = 12.92f * b;
        }

        return 0xFF000000 | (((int) (r * 255.0f)) << 16) | (((int) (g * 255.0f)) << 8) | ((int) (b * 255.0f));
    }
}