开发者

How is 1-bit bitmap data converted to 8bit (24bpp)?

开发者 https://www.devze.com 2022-12-15 22:49 出处:网络
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?

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消