【发布时间】:2019-06-22 06:33:36
【问题描述】:
我已经有了一些代码,可以使用 NSIMage 和 NSColorSpace 完成我需要的大部分工作。不幸的是,我正在尝试重新创建在 Photoshop 中发生的色彩空间/配置文件更改,它比 NSColorSpace 可以做的要复杂一些。你可以在这里看到那个帖子: Using ApplescriptObjC to convert color spaces of an image using NSColorSpace and iccProfileData
所以我需要帮助的是要么从 CGColorSpace 添加以下内容,要么重新创建脚本的某些部分,以便它们从一开始就使用 Core Graphics。我希望完成的功能是: CGColorRenderingIntent 使用 kCGRenderingIntentPerceptual kCGColorConversionBlackPointCompensation 加上使用抖动作为这种色彩空间转换的一部分,但我似乎无法在 Apple Objective-C 文档中找到一个选项。 NSColor 确实有 NSColorRenderingIntentPerceptual 但似乎在 NSColor 下没有 BlackPointCompensation。
我想我已经确定了构建此脚本所需的所有部分。我认为剧本已经写到一半了。我只是需要一些帮助将最后几位粘合在一起。
我相信脚本仍然需要将配置文件打开到 NSData(该文件是对我正在使用的 ICC 配置文件的 POSIX 文件引用)
set theData to current application's NSData's dataWithContentsOfFile:theFile
现在我需要打开图片,我希望无论使用 NSColor 还是 CGColor 都是一样的:
set theInput to (choose file with prompt "Choose RGB file")
set theOutput to (choose file name default name "Untitled.jpg")
set theImage to current application's NSImage's alloc()'s initWithContentsOfURL:theInput
set imageRep to theImage's representations()'s objectAtIndex:0
这是我看到的最需要帮助的代码行。这实际上是使用 NSColorSpace 进行颜色转换的地方:
set targetSpace to current application's NSColorSpace's alloc's initWithICCProfileData:theData
似乎我应该将 CGColorSpaceCreateICCBased 与 CGDataProviderRef 和 theFile 一起使用,但我怀疑我是否可以将它们替换为 NSColorSpace 和 initWithICCProfileData。我还需要使用 kCGRenderingIntentPerceptual 和 kCGColorConversionBlackPointCompensation 将 CGColorRenderingIntent 移植到这条线或新线(如果该选项甚至存在,则使用抖动)。
我不确定接下来的两行是否需要更新,但我很确定第三行可以保持不变(或者我真的很愚蠢,请原谅我)。
set theProps to current application's NSDictionary's dictionaryWithObjects:{1.0, true} forKeys:{current application's NSImageCompressionFactor, current application's NSImageProgressive}
set jpegData to bitmapRep's representationUsingType:(current application's NSJPEGFileType) |properties|:theProps
jpegData's writeToURL:theOutput atomically:true
因此输入将是具有通用 sRGB 配置文件的 RGB,输出将是具有特定 CMYK 配置文件(确切地说是 GRACoL2013_CRPC6.icc)的 CMYK 文件。
【问题讨论】:
-
您能否在 AppleScriptObjC 中使用
CGColorRenderingIntent()值得怀疑,因为它接受使用 C 数据类型的参数,而这些参数不会桥接到 AppleScript。 -
感谢 CJK 为我调查此问题。你会建议我的选择是什么?尝试使用 NSColorRenderingIntentPerceptual 看看我可以多接近 Photoshop 版本?将图像文件和颜色配置文件作为参数并基于配置文件输出具有新颜色空间的文件的命令行工具放在一起会有多困难?
-
您可以使用 图像事件 做到这一点。如果您使用自定义配置文件设置,您将无法指定黑点补偿。但如果您的机器上保存了特定的 ICC 配置文件,我相信您可以加载它进行嵌入。
标签: core-graphics nsimage applescript-objc cgcolorspace