views:

291

answers:

2

Supposing I have 4 bitmaps, say, CMYK, all of which are 1bit/pixel and are of different colors, and I wanted to convert them to an 8bit/color (24bpp) bitmap, how would I do this?

if the data looks like this:

// the Cyan separation

CCCC CCCC CCCC CCCC CCCC CCCC CCCC CCCC
...

// the magenta separation, and so on..
MMMM MMMM MMMM MMMM MMMM MMMM MMMM MMMM
...

Say, the Cyan had an RGB value of (0,255,255), and at Pixel 0 (first pixel), I had a value of 1 (on), and the Magenta had an RGB value of (255,255,0), and at the same pixel, had a value of 1.. What would the first RGB pixel look like? Would it look like this?

BBBB BBBB GGGG GGGG RRRR RRRR
// would this 3-byte sequence  actually be 255,255,255
// because the cyan has (0,255,255) and the 
// magenta has (255,255,0)?

Thanks, just confused as to how to convert 1bit separations into an 8bit image.. Thanks..

+4  A: 

CMYK is a substractive color system, while RGB is an additive one.

If you have a CMY(K) value of (1.0, 1.0, 1.0), it's black, while an RGB value of (255, 255, 255), it's white.

Cyan + Magenta = Blue: (0, 255, 255) + (255, 0, 255) != (0, 0, 255). But not exactly, because we're talking different color systems.

You need to first construct the pixels in CMYK, and then convert them to RGB, which can be approximated by doing (R, G, B) = (1-C, 1-M, 1-Y).

In order to convert a 1-bit value to an 8-bit value, you just need to transform every 0 into 0x00 and every 1 into 0xFF: Multiply bitValue by 0xFF.

Tordek
Right, I completely forgot.. So when you say that I have to construct the pixels in CMYK, does that mean it would be something like 4-bit indexed colour? (CMYK) = (1,1,1,1).. and so on? Anyway, this is quite helpful, thanks.. Marking this as the answer..
krebstar
Yes, you need to build the 4-tuple of colors. The problem, as I said, is converting CMYK to RGB, since there's no standard way, as @danben said. _Perhaps_ `(R,G,B) = ((1-C)(1-K), (1-M)(1-K), (1-Y)(1-K))`.
Tordek
Right, thanks.. :) an approximation is good enough, I only need the RGB to display on an RGB device (monitor).. Thanks again :)
krebstar
BTW, in that last formula you gave, since the values for CMYK can only be 1 or 0 (1-bit), if either C or K is 1, then the R part would be 0?
krebstar
Exactly. I haven't tried it, but it seems like it will work.
Tordek
Thanks, will check it out :)
krebstar
+3  A: 

Practically, with 1-bit coded CMYK you have 16 possible combinations (colors), 9 of which are black.

xxx1 -- black (8 comb's) -- 0x000000
0000 -- white -- 0xFFFFFF
1000 -- cyan -- 0x00FFFF
0100 -- magenta -- 0xFF00FF
0010 -- yellow -- 0xFFFF00
1100 -- blue -- 0x0000FF
1010 -- green -- 0x00FF00
0110 -- red -- 0xFF0000
1110 -- black -- 0x000000

Given this, I'd rather go with a mapping (switch-case or if-elses) than an actual algorithm for calculating RGB from CMYK. Of course, return early if K is set.

Nikola Gedelovski
Great idea! Thanks! :)
krebstar