Using ApplescriptObjC to convert color spaces of an image using NSColorSpace and iccProfileData

空扰寡人 提交于 2019-12-11 15:59:51

问题


I have some code that will change an images colorspace from RGB to a GenericCMYK profile. I would like to be able to use an ICC Profile to convert the image to a CMYK colorspace. There is a way to do this in Photoshop, but the process takes too much of a users time when you are dealing with 100's of images, I am trying to create an AppleScript droplet that will do this for them.

I have already looked at the page for NSColorspace and there looks like there is a way to do this. I just have no idea how to convert this Objective-C into ApplescriptObjC. Here are the two references to the ICC Profiles in NSColorSpace: init?(iccProfileData: Data) Initializes and returns an NSColorSpace object given an ICC profile. var iccProfileData: Data? The ICC profile data from which the receiver was created.

Here is the code I have thanks to Shane at Macscripter.net:

set theImage to (current application's NSImage's alloc()'s initWithContentsOfURL:theInput)
    set imageRep to (theImage's representations()'s objectAtIndex:0)
    set targetSpace to current application's NSColorSpace's genericCMYKColorSpace()
    set bitmapRep to (imageRep's bitmapImageRepByConvertingToColorSpace:targetSpace renderingIntent:(current application's NSColorRenderingIntentPerceptual))
    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)
    set colorSpace to bitmapRep's colorSpaceName() as text
    (jpegData's writeToURL:theOutput atomically:true)

I just need to figure out how to include the ICC Profile as a park of the CMYK conversion process that happens I believe on this line of code:

set targetSpace to current application's NSColorSpace's genericCMYKColorSpace()

Can anyone give me some guidance on this?

Thanks!


回答1:


You are looking at the NSColorSpace documentation in Swift. AppleScriptObjC is an Objective-C bridge, so it makes more sense viewing the documentation in Objective-C (the language can be set in the page header), where your snippet becomes

set targetSpace to current application's NSColorSpace's alloc's initWithICCProfileData:iccData

where iccData is the ICC profile data you are going to use.



来源:https://stackoverflow.com/questions/56692855/using-applescriptobjc-to-convert-color-spaces-of-an-image-using-nscolorspace-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!