package com.ai.da.common.utils;

public class PantoneUtils {

    public static int[] rgbToHsv(int[] rgb) {
        //切割rgb数组
        int red = rgb[0];
        int green = rgb[1];
        int blue = rgb[2];

        float r = (float) red / 255;
        float g = (float) green / 255;
        float b = (float) blue / 255;

        float min = Math.min(Math.min(r, g), b);

        float[] hsv = {60, 0, Math.max(Math.max(r, g), b)};

        hsv[1] = (hsv[2] == 0) ? 0 : 1 - min / hsv[2];

        hsv[0] = 60 * (
                (hsv[2] == min) ? Float.NaN :
                        (hsv[2] == r) ? (g - b) / (hsv[2] - min) + ((g < b) ? 6 : 0) :
                                (hsv[2] == g) ? (b - r) / (hsv[2] - min) + 2 :
                                        (r - g) / (hsv[2] - min) + 4
        );

        return new int[]{Math.round(hsv[0]), Math.round(hsv[1] * 100), Math.round(hsv[2] * 100)};
    }

}
