-
Notifications
You must be signed in to change notification settings - Fork 5
/
transicc.js
97 lines (64 loc) · 2.06 KB
/
transicc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var spawn = require( "child_process" ).spawn;
// new switch in 1.1.2 to replace symlinks for shortcut profiles
var profile_path = function( profile_name ){
switch ( profile_name ) {
// use Adobe's CMYK profile
case "cmyk":
profile_name = "cmyk-adobe-us-web-uncoated";
break;
// use Apple's lab profile
case "lab":
profile_name = "lab-apple";
break;
// use AdobeRGB for RGB by default
case "rgb":
profile_name = "rgb-adobe-1998";
break;
// use Apple's sRGB profile
case "srgb":
profile_name = "srgb-apple";
break;
// use XYZ with a luminant of d65 by default
case "xyz":
profile_name = "xyz-d65";
break;
}
return "profile/"+profile_name+".icc";
}
// generic function to pass profiles and parameters to the
// LittleCMS transicc command line utility.
module.exports = function( input_profile, output_profile, args, callback ) {
// create an array of arguments we'll pass to the transicc command
var cmd_arg = [];
// add the input profile
cmd_arg.push( profile_path( input_profile ) );
// add the output profile
cmd_arg.push( profile_path( output_profile ) );
// ensure a valid number of arguments
if ( args.length < 3 && args.length > 4 ) {
callback( new Error('Invalid number of arguments.'), null );
return;
}
// loop through the arguments and add them to the command args
for ( var i = 0; i < args.length; i++ ) {
cmd_arg.push( args[i] );
}
// spawn the command and create an empty response
var cmd = spawn( "./shell/"+args.length+".sh", cmd_arg, {
cwd: __dirname
}),
response;
// when we receive output from the command
cmd.stdout.on( 'data', function ( data ) {
// parse the output
response = new String( data ).split( " " );
});
// output errors to the console - only for debugging.
// cmd.stderr.on('data', function (data) { console.log('stderr: ' + data); });
// once the command is finished
cmd.on( 'close', function ( code ) {
// since we're working asynchronously, we can't return
// so we'll pass our response into a callback function.
callback( null, response );
});
};