03/07 指定のRGBカラーをGeneric CMYKプロファイルでCMYKに変換して……RGB値を取得
指定のRGBカラー値をGeneric CMYKプロファイルを用いてCMYK変換し、CMYK値を取り出そうとして……できなかったので仕方なくRGB値を取り出したAppleScriptObjCのプログラムです。
上のColorWellをクリックして任意の色(ここではライトグリーン)を選択。

「Convert RGB to CMYK」ボタンをクリックすると、Mac OS XのGeneric CMYK Profileに基づいてCMYK変換を行い、下のColorWellに色を設定します。

いい感じのCMYKっぽい色に変換されるのですが、ここからCMYK値を取り出すのに失敗(なんでだ〜)。仕方なくRGB値を取り出しています。
→ プロジェクトのダウンロード(Xcode 4.1 on Mac OS X 10.6.8)
| AppleScriptObjCファイル名:rgb2cmykAppDelegate.applescript |
| – – rgb2cmykAppDelegate.applescript – rgb2cmyk – – Created by 長野谷 隆昌 on 12/01/26. – Copyright 2012 Piyomaru Software. All rights reserved. – – generic CMYK color Spaceを用いて、RGB→CMYK変換を行い、ColorWellにCMYKベースで色をセットしたあとRGB値でその色を取り出す – script rgb2cmykAppDelegate property parent : class “NSObject” property rgbWell : missing value property rgbR : missing value property rgbG : missing value property rgbB : missing value property cmykWell : missing value property cmykC : missing value property cmykM : missing value property cmykY : missing value property cmykK : missing value on applicationWillFinishLaunching_(aNotification) – Insert code here to initialize your application before any files are opened end applicationWillFinishLaunching_ on applicationShouldTerminate_(sender) – Insert code here to do any housekeeping before your application quits return current application’s NSTerminateNow end applicationShouldTerminate_ on clicked_(sender) –RGB Color Wellのカラー値を読み取って、TextFieldに文字を入れる set {rNum, gNum, bNum, aNum} to retColData(rgbWell) set rNumStr to (rNum as integer) as string set gNumStr to (gNum as integer) as string set bNumStr to (bNum as integer) as string rgbR’s setStringValue_(rNumStr) rgbG’s setStringValue_(gNumStr) rgbB’s setStringValue_(bNumStr) –RGB Colorwellからカラーを読み取る set tmpColor to rgbWell’s |color| –Generic ProfileでRGB to CMYK変換してColorWellに設定 set cmykColSpace to current application’s NSColorSpace’s genericCMYKColorSpace set color1 to tmpColor’s colorUsingColorSpace_(cmykColSpace) –cmykWell’s setColor_(color1) tell cmykWell setColor_(color1) end tell –とりあえずRGBAでデータを取り出してみる set {temp21, temp22, temp23, temp24} to retColData(cmykWell) set temp21 to temp21 as string set temp22 to temp22 as string set temp23 to temp23 as string set temp24 to temp24 as string –TextFieldにCMYKデータを入れる cmykC’s setStringValue_(temp21) cmykM’s setStringValue_(temp22) cmykY’s setStringValue_(temp23) cmykK’s setStringValue_(temp24) end clicked_ –指定オブジェクトのカラー値を取得する on retColData(aObject) –色空間のコンバートを行ってカラー値を取得する(強制的にRGB) set tmpColor to aObject’s |color| set color1 to tmpColor’s colorUsingColorSpaceName_(current application’s NSCalibratedRGBColorSpace) set temp11 to color1’s redComponent() set temp12 to color1’s greenComponent() set temp13 to color1’s blueComponent() set temp14 to color1’s alphaComponent() –RGBAの並びでデータを返す set TheColor to {(temp11 * 255) as integer, (temp12 * 255) as integer, (temp13 * 255) as integer, (temp14 * 255) as integer} return TheColor end retColData end script |
