-
Notifications
You must be signed in to change notification settings - Fork 0
/
cquant.js
55 lines (55 loc) · 1.9 KB
/
cquant.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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const addon = require('bindings')('cquant');
function paletteAsync() {
const [buffer, depth = 3, maxColor = 5, maxSub = 0, callback = null] = arguments;
if (arguments.length < 1 || buffer == null) {
throw new Error("Too Few arguments");
}
else if (arguments.length === 2) {
if (typeof (arguments[1]) === 'function') {
return paletteAsync(buffer, undefined, undefined, undefined, arguments[1]);
}
}
else if (arguments.length === 3) {
if (typeof (arguments[2]) === 'function') {
return paletteAsync(buffer, arguments[1], undefined, undefined, arguments[2]);
}
}
else if (arguments.length === 4) {
if (typeof (arguments[3]) === 'function') {
return paletteAsync(buffer, arguments[1], arguments[2], undefined, arguments[3]);
}
}
if (callback == null) {
if (depth !== 3 && depth !== 4) {
return Promise.reject(new Error('Wrong depth!'));
}
if (maxColor <= 1 || maxColor > 256) {
return Promise.reject(new Error('maxColor too small or too large!'));
}
return new Promise((res, rej) => {
addon.PaletteAsync(buffer, maxColor, depth, maxSub, (err, val) => {
if (err) {
rej(err);
}
else {
res(val);
}
});
});
}
else {
if (depth !== 3 && depth !== 4) {
callback(new Error('Wrong depth!'));
return;
}
if (maxColor <= 1 || maxColor > 256) {
callback(new Error('maxColor too small or too large!'));
return;
}
addon.PaletteAsync(buffer, maxColor, depth, maxSub, callback);
}
}
exports.paletteAsync = paletteAsync;
//# sourceMappingURL=cquant.js.map