How to convert 1-bit raster data to 8 bits (24bpp)?

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

if the data is as follows:

// 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 ... 

Let's say that Cyan had an RGB value (0.255,255), and with a pixel of 0 (first pixel) I had a value of 1 (on), while Magenta had an RGB value (255,255,0) and on 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, I just got confused about how to convert 1 bit to an 8-bit image .. Thanks ..

+2
source share
2 answers

CMYK is a subtractive color system, and RGB is an additive color system.

If you have a CMY (K) value (1.0, 1.0, 1.0), it is black, and the RGB value (255, 255, 255) is white.

Cyan + Magenta = Blue: (0, 255, 255) + (255, 0, 255)! = (0, 0, 255). But not quite, because we are talking about different color systems.

First you have to design 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) .

To convert a single-bit value to an 8-bit value, you just need to convert each 0 to 0x00 and each 1 to 0xFF : Multiply bitValue by 0xFF .

+4
source

In practice, with 1-bit encoded 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 

With that in mind, I'd rather go with the mapping (switch-case or if-elses) than the actual RGB calculation algorithm from CMYK. Of course, come back earlier if K is installed.

+3
source

All Articles