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
|
"use strict";
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
jsdom = require("jsdom");
var suite = vows.describe("mp.dye");
var dyeString = "R:#ede5b2,fff7bf;G:#cccccc,ffffff";
var dyeData = {
"R": [
[0xed, 0xe5, 0xb2],
[0xff, 0xf7, 0xbf]
],
"G": [
[0xcc, 0xcc, 0xcc],
[0xff, 0xff, 0xff]
]
};
function unshiftLoadImageBind(url, tests) {
tests.topic = function() {
var mp = arguments[arguments.length - 1];
var tester = this;
var args = arguments;
mp.resource.loadImage(url, function(err, data) {
if (err) {
throw new Error("Error loading '" + url + "': " + data);
}
tester.callback.bind(tester, err, data).apply(tester, args);
});
};
return tests;
}
function testDyeParse(expected, input, mp) {
assert.dyeDataEqual(mp.dye.parseDyeString(input), expected);
}
function testDye(err, dyed, dyeable, mp) {
var input = dyeable.data;
var expected = dyed.data;
var actual = new Uint8ClampedArray(input);
mp.dye.dyeImage(actual, dyeData);
assert.imageDataEqual(actual, expected, input, dyed.width);
}
suite.addBatch({
"The manaportal dye": {
topic: load("mp/dye", "mp/resource").expression("mp").document(),
"parseDyeString": {
"extracts the dye channel data from the dyestring": testDyeParse.bind(null, dyeData, dyeString)
},
"asDyeString": {
"reconstructs the dyestring from the dye channel data": function(mp) {
assert.equal(mp.dye.asDyeString(dyeData), dyeString);
}
},
"dyeImage": {
"with the big recolorable cake": unshiftLoadImageBind("test/data/bigcake.png", {
"to the big white cake dyed by TMWW": unshiftLoadImageBind("test/data/whitecake.png", {
"dyes correctly when given the correct dye data": testDye
})
}),
"with a gradient of all channels with all intensities": unshiftLoadImageBind("test/data/gradient.png", {
"to a gradient of all channels with all intensities dyed by TMWW with the white cake dye": unshiftLoadImageBind("test/data/gradient-whitecakedye.png", {
"dyes correctly when given the correct dye data": testDye
})
})
}
}
});
suite.export(module);
|