-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (30 loc) · 1001 Bytes
/
index.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
var colorSpaces = require('color-space')
var cwise = require('cwise')
module.exports = function (from, to) {
var convert = cwise({
funcName: 'convert',
args: ['scalar', 'scalar', 'scalar', { blockIndices: -1}, { blockIndices: -1}, 'index'],
body: function (converter, inputLength, outputLength, input, output, path) {
var inputChunk = new Array(inputLength)
for (var i = 0; i < inputLength; i++) {
inputChunk[i] = input[i]
}
var outputChunk = converter(inputChunk)
for (i = 0; i < outputLength; i++) {
output[i] = outputChunk[i]
}
}
})
var inputSpace = colorSpaces[from]
var inputLength = inputSpace.channel.length
var outputSpace = colorSpaces[to]
var outputLength = outputSpace.channel.length
var converter = inputSpace[to]
return function convertData (input, output) {
if (!output) {
output = input
}
convert(converter, inputLength, outputLength, input, output)
return output
}
}