convert cmyk to hsb
in
Programming Questions
•
1 year ago
I made a function to convert a color to cmyk in the rage of 0 to 100 (it returns a int array).
I also want to be able to convert it back to a color.
The problem is, how do i deal with hsb and the current range of that?
I looked a lot at http://code.google.com/p/processing/source/browse/trunk/processing/core/methods/demo/PGraphics.java
and there are a lot of color functions there but there out of my league.
Here is what i have so far ( i want to make it for a library, that's why i have the p.g. etc):
- public int cmykToColor(float c, float m, float y, float k) {
- // Converts CMYK to CMY C = ( C * ( 1 - K ) + K ) M = ( M * ( 1 - K ) +
- // K ) Y = ( Y * ( 1 - K ) + K ) and converts CMY to RGB R = ( 1 - C ) G
- // = ( 1 - M ) B = ( 1 - Y )
- // c = c/100;
- // m = m/100;
- // y = y/100;
- k = k / 100;
- c = ((c / 100) * (1 - k) + k);
- m = ((m / 100) * (1 - k) + k);
- y = ((y / 100) * (1 - k) + k);
- switch (p.g.colorMode) {
- case PApplet.RGB:
- float r = (1 - c) * p.g.colorModeX;
- float g = (1 - m) * p.g.colorModeY;
- float b = (1 - y) * p.g.colorModeZ;
- return p.color(r, g, b);
- }
- // hsb?
- return -1;
- }
1