UIColor CMYK和实验室值 [英] UIColor CMYK and Lab Values

查看:202
本文介绍了UIColor CMYK和实验室值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题,而不是可能的复杂答案:

Simple question, more than likely complex answer:

如何从UIColor对象获取CMYK和Lab值(如果有帮助,我知道RGB值)?

How can I get CMYK and Lab values from a UIColor object (of which I know the RGB values if it helps)?

我发现这与获取CMYK值有关,但是我无法从中获得任何准确的值,尽管它无处不在,我听说这不是一个很好的摘录.

I have found this regarding getting CMYK values but I can't get any accurate values out of it, despite it being everywhere, I've heard it's not a great snippet.

CGFloat rgbComponents[4];
    [color getRed:&rgbComponents[0] green:&rgbComponents[1] blue:&rgbComponents[2] alpha:&rgbComponents[3]];

    CGFloat k = MIN(1-rgbComponents[0], MIN(1-rgbComponents[1], 1-rgbComponents[2]));
    CGFloat c = (1-rgbComponents[0]-k)/(1-k);
    CGFloat m = (1-rgbComponents[1]-k)/(1-k);
    CGFloat y = (1-rgbComponents[2]-k)/(1-k);

推荐答案

对于基于ICC的颜色转换,可以使用 Little颜色管理系统. (我刚刚将下载档案中的所有.c和.h文件添加到iOS Xcode项目中.它编译并运行了以下代码,没有任何问题.)

For ICC-based color conversion, you can use the Little Color Management System. (I have just added all .c and .h files from the download archive to an iOS Xcode project. It compiled and ran the following code without problems.)

备注: RGB和CMYK是与设备无关的颜色空间,而Lab是与设备无关的颜色空间.因此,要从RGB转换为Lab,您必须选择与设备无关(或校准")的RGB颜色空间进行转换,例如sRGB.

Remark: RGB and CMYK are a device dependent color spaces, Lab is a device independent color space. Therefore, to convert from RGB to Lab, you have to choose a device independent (or "calibrated") RGB color space for the conversion, for example sRGB.

Little CMS带有用于sRGB和Lab色彩空间的内置配置文件.从sRGB到Lab的转换看起来像这样:

Little CMS comes with built-in profiles for sRGB and Lab color spaces. A conversion from sRGB to Lab looks like this:

创建颜色转换:

cmsHPROFILE rgbProfile = cmsCreate_sRGBProfile();
cmsHPROFILE labProfile = cmsCreateLab4Profile(NULL);
cmsHTRANSFORM xform = cmsCreateTransform(rgbProfile, TYPE_RGB_FLT, labProfile,
                                         TYPE_Lab_FLT,
                                         INTENT_PERCEPTUAL, 0);
cmsCloseProfile(labProfile);
cmsCloseProfile(rgbProfile);

转换颜色:

float rgbValues[3];
// fill rgbValues array with input values ...
float labValues[3];
cmsDoTransform(xform, rgbValues, labValues, 1);
// labValues array contains output values.

处理颜色转换:

cmsDeleteTransform(xform);

当然,该转换只能创建一次,并用于所有颜色转换.

Of course, the transformation would be created only once and used for all color conversions.

对于从RGB到CMYK的转换,您还可以使用Little CMS,但必须提供ICC配置文件,例如一个来自Adobe的免费下载页面适用于Mac OS的ICC配置文件下载

For RGB to CMYK conversion you can also use Little CMS, but you have to provide an ICC-Profile, e.g. one from the free Adobe download page ICC profile downloads for Mac OS.

将RGB转换为CMYK的代码示例:

Code example for RGB to CMYK conversion:

float rgb[3]; // fill with input values (range 0.0 .. 1.0)
float cmyk[4]; // output values (range 0.0 .. 100.0)

cmsHPROFILE rgbProfile = cmsCreate_sRGBProfile();

// The CMYK profile is a resource in the application bundle:
NSString *cmykProfilePath = [[NSBundle mainBundle] pathForResource:@"YourCMYKProfile.icc" ofType:nil];
cmsHPROFILE cmykProfile = cmsOpenProfileFromFile([cmykProfilePath fileSystemRepresentation], "r");

cmsHTRANSFORM xform = cmsCreateTransform(rgbProfile, TYPE_RGB_FLT, cmykProfile,
                                         TYPE_CMYK_FLT,
                                         INTENT_PERCEPTUAL, 0);

cmsCloseProfile(cmykProfile);
cmsCloseProfile(rgbProfile);

cmsDoTransform(xform, rgb, cmyk, 1);

cmsDeleteTransform(xform);

这篇关于UIColor CMYK和实验室值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆