扫描仪的颜色空间一般为CMYK,从扫描仪上得到的图片如果是自己移植图片解码器, 一般需要将CMYK转换至RGB888。相关解释,参考国外资料:
To understand the CMYK color model, it is best to start with an understanding of RGB color.
The RGB color model is made up of red, green and blue. It is used on your computer monitor and is what you will view your projects in while still on the screen. RGB is retained for projects that are designed to stay on screen (websites, pdfs, and other web graphics, for instance).
These colors, however, can only be viewed with natural or produced light, such as in the computer monitor, and not on a printed page. This is where CMYK comes in.
When two RGB colors are mixed equally they produce the colors of the CMYK model, which are known as subtractive primaries.
Green and blue create cyan (C).
Red and blue create magenta (M).
Red and green create yellow (Y).
Black is added to the model because it cannot be created with the 3 subtractive primaries (when combined they create a dark brown). The K, or “key,” stands for black.
转换公式如下:
R = C* (255 - cyan)/255;
G = C* (255 - magenta)/255;
B = C* (255 - yellow)/255;
C实现代码:
uint8_t* CMYKToRGB24(uint32_t* cmyk, int width, int height)
{uint32_t off;uint32_t color;int i,j;uint32_t row_bytes;uint8_t* rgb;uint8_t* ptr;uint8_t c,m,y,k;int tmp;row_bytes = (width * 3 + 3) & ~3;rgb = (uint8_t*)malloc(row_bytes * height);if(!rgb)return NULL;off = 0;for (i = 0; i < height; i++){ ptr = rgb + off;for(j = 0; j < width; j++){color = *cmyk++;c = color & 0x000000FF;m = (color >> 8) & 0x000000FF;y = (color >> 16) & 0x000000FF;k = (color >> 24) & 0x000000FF;*ptr++ = k * c/255;*ptr++ = k * m/255;*ptr++ = k * y/255;}off += row_bytes;}return rgb;
}