(int red, int green, int blue)
| 122 | } |
| 123 | |
| 124 | public static float[] convertRGBToHSV(int red, int green, int blue) { |
| 125 | assert 0 <= red && red <= 255 : "Red is out of 0..255 range: " + red; |
| 126 | assert 0 <= green && green <= 255 : "Green is out of 0..255 range: " + green; |
| 127 | assert 0 <= blue && blue <= 255 : "Blue is out of 0..255 range: " + blue; |
| 128 | |
| 129 | int max = Math.max(red, Math.max(green, blue)); |
| 130 | int min = Math.min(red, Math.min(green, blue)); |
| 131 | int delta = max - min; |
| 132 | |
| 133 | float h; |
| 134 | if (delta == 0) { |
| 135 | h = 0f; |
| 136 | } else if (max == red) { |
| 137 | h = 60f * (green - blue) / delta; |
| 138 | if (h < 0f) h += 360f; |
| 139 | } else if (max == green) { |
| 140 | h = 60f * (blue - red) / delta + 120f; |
| 141 | } else { |
| 142 | h = 60f * (red - green) / delta + 240f; |
| 143 | } |
| 144 | |
| 145 | float s = max == 0 ? 0f : delta / (float) max; |
| 146 | float v = max / 255f; |
| 147 | return new float[] {h, s, v}; |
| 148 | } |
| 149 | |
| 150 | public static float[] convertToHSV(int color) { |
| 151 | return convertRGBToHSV(getR(color), getG(color), getB(color)); |
no outgoing calls