forked from alexkirsz/node-dxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (37 loc) · 1.56 KB
/
Copy pathindex.js
File metadata and controls
43 lines (37 loc) · 1.56 KB
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
var dxt = require('./build/Release/dxt');
var flags = {
kDxt1: 1 << 0,
kDxt3: 1 << 1,
kDxt5: 1 << 2,
kColourIterativeClusterFit: 1 << 8,
kColourClusterFit: 1 << 3,
kColourRangeFit: 1 << 4,
kColourMetricPerceptual: 1 << 5,
kColourMetricUniform: 1 << 6,
kWeightColourByAlpha: 1 << 7
};
exports.compress = function compress(input, width, height, flags) {
if (!Buffer.isBuffer(input))
throw new Error("Argument 1 of dxt.compress() (input) must be a buffer");
if (typeof width !== 'number')
throw new Error("Argument 2 of dxt.compress() (width) must be a number");
if (typeof height !== 'number')
throw new Error("Argument 3 of dxt.compress() (height) must be a number");
if (typeof flags !== 'number' && typeof flags !== 'undefined')
throw new Error("Argument 4 of dxt.compress() (flags) should be a number or undefined");
return dxt.compress(input, width, height, flags);
};
exports.decompress = function decompress(input, width, height, flags) {
if (!Buffer.isBuffer(input))
throw new Error("Argument 1 of dxt.compress() (input) must be a buffer");
if (typeof width !== 'number')
throw new Error("Argument 2 of dxt.compress() (width) must be a number");
if (typeof height !== 'number')
throw new Error("Argument 3 of dxt.compress() (height) must be a number");
if (typeof flags !== 'number' && typeof flags !== 'undefined')
throw new Error("Argument 4 of dxt.compress() (flags) should be a number or undefined");
return dxt.decompress(input, width, height, flags);
};
for (var key in flags) {
exports[key] = flags[key];
}