请帮助在 LittleCMS 中运行颜色转换:我确实找到了如何使用 double,但我正在使用 unsigned char 进行堆叠。我在 unsigned char 数组中确实有 BGR 颜色,如下所示: unsigned char scanline [3] = {147, 112 220}
。值可以0-255
。据我了解 LittleCMS 的文档:对于这种类型,我必须使用TYPE_BGR_8
(和TYPE_CMYK_8
输出)。但它并没有以正确的方式转换——只有当我使用TYPE_BGR_DBL
, TYPE_CMYK_DBL
,从无符号数组转换为 double 并将我的输入数组标准化为 0-1 的值时,我才收到正确的转换。请帮助优化我的代码:
1)我是否必须将值标准化为 0-1?
2) 我必须在我的程序中使用哪些类型来排除从无符号数组到双精度的转换?
我的程序和输出
1)以正确的方式工作:
#include <stdio.h>
#include <stdlib.h>
#include "lcms2.h"
int main (){
cmsHPROFILE hInProfile, hOutProfile;
cmsHTRANSFORM hTransform;
hInProfile = cmsCreate_sRGBProfile();
hOutProfile = cmsOpenProfileFromFile("/home/ab/Documents/cmyk/colorProfiles/WebCoatedSWOP2006Grade5.icc", "r");
hTransform = cmsCreateTransform(hInProfile, TYPE_BGR_DBL, hOutProfile, TYPE_CMYK_DBL, INTENT_PERCEPTUAL, 0);
cmsCloseProfile(hInProfile);
cmsCloseProfile(hOutProfile);
unsigned char scanline0[3] = {147, 112, 220};
double scanline [3], outputline [4];
for(int k=0;k<3;k++){
scanline [k] = (double)scanline0 [k]/255;
}
printf("Red = %f \n",scanline [2]);
printf("Green = %f \n", scanline [1]);
printf("Blue = %f \n \n", scanline [0]);
cmsDoTransform(hTransform, scanline, outputline, 1); //transforming from one to other
printf(" Cyan %f\n Mageta %f\n Yellow %f\n Black %f\n ", outputline[0], outputline[1], outputline[2], outputline[3]); //C M Y K
return 0;
}
输出:
Red = 0.862745
Green = 0.439216
Blue = 0.576471
Cyan 15.350576
Mageta 68.361944
Yellow 25.549707
Black 1.419089
2)当我使用无符号字符时,它的工作方式错误。程序:
hTransform = cmsCreateTransform(hInProfile, TYPE_BGR_8, hOutProfile, TYPE_CMYK_8, INTENT_PERCEPTUAL, 0);
...
unsigned char scanline[3] = {147, 112, 220}, outputline [4];
printf("Red = %d \n",scanline [2]);
printf("Green = %d \n", scanline [1]);
printf("Blue = %d \n \n", scanline [0]);
cmsDoTransform(hTransform, scanline, outputline, 1);
输出:
Red = 220
Green = 112
Blue = 147
Cyan 39
Mageta 174
Yellow 65
Black 4