4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CMYKカラーを全て書き出す

Last updated at Posted at 2014-03-23

Photoshop「カラー設定」で色域を書き出したいCMYKプロファイルを選択しておき、以下を実行

lab2cmyk.jsx

var myFile = new File('~/Desktop/labcmyk.txt');
myFile.open("w");
myFile.encoding='BINARY';



myColor = new SolidColor;
for (var myL = 0; myL<=100;myL++){
    for (var myA = -128 ; myA <=127;myA++){
        for (var myB = -128 ; myB <=127;myB++){
        myColor.lab.l = myL;
        myColor.lab.a = myA;
        myColor.lab.b = myB;
        myC = Math.round(myColor.cmyk.cyan);
        myM = Math.round(myColor.cmyk.magenta);
        myY = Math.round(myColor.cmyk.yellow);
        myK = Math.round(myColor.cmyk.black);
        
        myWrite = myC + '\t' + myM + '\t' + myY +'\t' + myK
        myFile.writeln(myWrite);
        }
    }
}
myFile.close();

Labスペース全てでCMYK値が書き出される。
sortし、uniqで同一のCMYK値を削除→色域外が削除される。
CMYKを0-100で単純に描画しても意味が無い…CMYK400%はありえない…のでLabから削り取る。ただし面積比率は評価していない。
処理したテキストを読み込んでPhotoshopで描画

CMYKALLColors.jsx
app.preferences.rulerUnits = Units.PIXELS;
var myDoc = app.documents.add(872,872,72,"CMYK ALL Colors",NewDocumentMode.CMYK);


var myFile = new File('~/Desktop/labcmyksortuniq.txt');
myFile.open('r');
var myText = myFile.readln();

myX =0;
myY =0;
myColor=new SolidColor();
while ( myText !=''){
    var myColorText=myText.split ("\t");
    
    myColor.cmyk.cyan=myColorText[0];
    myColor.cmyk.magenta=myColorText[1];
    myColor.cmyk.yellow=myColorText[2];
    myColor.cmyk.black=myColorText[3];
    
  myDoc.selection.select([[myX,myY],[myX+1,myY],[myX+1,myY+1],[myX,myY+1]]);
  myDoc.selection.fill(myColor,ColorBlendMode.NORMAL,100,false);
myX=myX+1;
if (myX >= 873){
    myY=myY+1;
    myX=0;
    }


myText = myFile.readln();
}

ちょう遅い。selection&fillが遅い。CCだとさらに遅いので、CS6で実行して5時間以内(i7)

あまりに遅いのでIllustratorで描画して書き出すことにした

CMYKALLCOLORSAI.jsx

var myDoc = activeDocument;
var myFile = new File('~/Desktop/labcmyksortuniq.txt');
myFile.open('r');
var myText = myFile.readln();

myX =0;
myY =0;
function setColor(c,m,y,k){
var myColor=new CMYKColor();
myColor.cyan=c;
myColor.magenta=m;
myColor.yellow=y;
myColor.black=k;
return myColor;
}

while ( myText !=''){
    var myColorText=myText.split ('\t');
    

    myColor=setColor(myColorText[0],myColorText[1],myColorText[2],myColorText[3]);
    
    myPath=myDoc.pathItems.rectangle(myY,myX,1,1);
    myPath.filled=true;
    myPath.stroked =false;
    myPath.fillColor=myColor;
myX=myX+1;
if (myX >= 850){
   myY=myY-1;
   myX=0;
    }


myText = myFile.readln();
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?