Skip to content

Commit b767f43

Browse files
committed
Adding RGB-To-Cmyk method in Tools
1 parent 5cb47f0 commit b767f43

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/milchreis/imageprocessing/utils/Tools.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,18 @@ public static int hsbToRgb(float h, float s, float b) {
133133
h = PApplet.map(h, 0f, 360f, 0, 1f);
134134
return Color.HSBtoRGB(h, s, b);
135135
}
136-
136+
137+
public static float[] rgbToCmyk(int rgb) {
138+
int[] rgbArr = getRGB(rgb);
139+
float k = 1 - (Math.max(rgbArr[0], Math.max(rgbArr[1], rgbArr[2]))/255.0f);
140+
return new float[] {
141+
(1 - (rgbArr[0] / 255.0f) - k) / (1 - k),
142+
(1 - (rgbArr[1] / 255.0f) - k) / (1 - k),
143+
(1 - (rgbArr[2] / 255.0f) - k) / (1 - k),
144+
k
145+
};
146+
}
147+
137148
public static boolean in(int x, int start, int end) {
138149
return in((float)x, start, end);
139150
}

0 commit comments

Comments
 (0)