Continuing right along...

| | Comments (10)

Since I've been on a colors kick recently, and I've seen some questions regarding colors pop up on the forums, let's take a peek at how to get a CMYK color into a REALbasic color.

I don't even pretend to be a color expert, so I'm hoping my faithful readers can shed more light on the topics for me. But I do know that there are various colorspaces which are all used for different scenarios. RGB seems to be the most popular one, but another big one is CMYK. I recall from talking to my dad (he used to work in the printing industry) that CMYK is big with printers because the colors are easier to combine for true colors (or something along those lines). There's also HSV and HSL (though I don't pretend to know what those are really used for).

In any event, I found a neat way to convert CMYK into a REALbasic color object, and so here it is:
[rbcode]
Function CMYK(c as Double, m as Double, y as Double, k as Double) As Color
dim red, green, blue as Double

// Gets the RGB on the range [0,1]
red = 1 - Min( 1, c * (1 - k) + k )
green = 1 - Min( 1, m * (1 - k ) + k)
blue = 1 - Min( 1, y * (1 - k) + k)

return RGB( 255 * red, 255 * green, 255 * blue )
End Function[/rbcode]
So, now it's your turn to educate me! I want a decent, layman's explanation of what the various color spaces are, and why they're useful. I know RB supports RGB, CYM and HSV directly -- but what are we missing, and why are they important? What do they get used for? And please, don't tell me to just google it; I want to know what your reasoning is.

10 Comments

Hey buddy! The last 6 posts have been programming related! Give a girl a break already, give me something to read! Hope you're having a lovely evening!

Afraid I'm not a color geek, so I can't help you out here. I'm happy with what we've got color-wise; all I ever use is RGB.

The YUV color standard is missing, and that is very popular for video (like TV). Y stands for Lumeniance, and the best generic color formula for converting pictures to Grayscale. I have already submitted a feature request here:

http://www.realsoftware.com/feedback/viewreport.php?reportid=rsrgjslj

I spent 14 years in the printing industry, and I can assure you that CMYK is what is almost always expected. The only problem with your method is that your formula is only one example of how you can convert RGB into CMYK and there are really a lot of variables that go into converting the colors.

The summary is that having a method to convert RGB to CMYK is only part of the process... REALbasic would also need to have a CMYK datatype. Once the new Structure types are able to be returned from methods, I am going to try to get a variety of additional Color Datatypes including RGBA, CMYK, and CMYKA.

For those of us in vision science, CIE color space is extremely important, as are conversions from RGB CIE. ColorSync color profiles (and their ICC equivalents on other platforms) use CIE coordinates for monitor, scanner and printer calibration, then conversion to equivalent RGB colors. To truly define accurate color, CIE color space is a must. I'd like to see built-in support for reading ICC profiles (e.g., ColorSync on the Mac), getting values such as a monitor's white point and gamut, and converting between RGB and CIE color spaces.

CMYK stands for cyan, magenta, yellow, key (=black), which are the colours of the four sets of dots used to the print colour pictures by 'traditional' methods. All other colours are made up from combinations of different sizes of dots of those four.

I think I'm right is saying that RCB (red, green, blue) are the three colours used by cathode ray tubes to make up other colours. It's therefore obviously fundamental to computers and the web.

Again, as I understand it, Colorsync and other profiles attempt to transfer information between monitor, computer printer and printing press to acheive consistent results all along the line. This is particularly hard to do because of the differnt systems involved and the fact that colour is ultimately subjective.

I hope this returns a little of the understanding that your blog and forum posts have given me, for which many thanks.

As others have pointed out, there are many RGBs, and many CMYKs. For instance, two popular RGB color spaces are sRGB, and AdobeRGB.

There are also many CMYKs - Status T, Status E are the most popular.

But none of this means anything unless you're taking the spectral response of the phosphors (for CRTs), or the inks (for printing) into account. This is why ICC profiles and color management libraries exist.

As a side note, if you read the documentation on the Color class in RB 06 R1, you'll notice that RGB and CMY are already represented.

My company writes software (some of it written in RB) that communicates with spectrophotometers, specifically for measuring color. The spectrophotometers read a color, and return spectral response data, which I then use to calculate CMYK, L*a*b*, and sRGB.

Color's a mystery to me too. One time we were submitting a catalogue for printing at a printing press and one of the images looked shockingly wrong on the test print we received. When we printed it, it looked fine. The problem turned out to be that all the TIFFs we supplied were grayscale, except the one that looked wrong, which was RGB. We converted it to grayscale in Photoshop and sent it back, and the next test print came back perfectly. It looked the same the whole time on our computers. Color is super-weird stuff.

Phew! Thanks everyone for your comments -- it appears as though colors are a lot more complicated than I originally thought!

Phew! Thanks everyone for your comments — it appears as though colors are a lot more complicated than I originally thought!

Go ahead and keep asking questions if you want to know more. It'll be an well-deserved opportunity for some of us to return all the educational favors you've done for us.

Color fans might be interested in a simple tool I wrote to grab pixel color values from the screen in various text formats. REALbasic source is available if you want to add your own format. Free at http://ljensen.com/colorgrab

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.