forked from redteam316/html5-embroidery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expformat.js
55 lines (51 loc) · 1.11 KB
/
expformat.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
(function (global) {
"use strict";
function expDecode(input) {
return (input > 128) ? (-(~input & 255) - 1) : input;
}
var expRead = function (file, pattern) {
var b0 = 0,
b1 = 0,
dx = 0,
dy = 0,
flags = 0,
i = 0,
byteCount = file.byteLength;
while (i < byteCount) {
flags = global.stitchTypes.normal;
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
if (b0 === -128) {
if (b1 & 1) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
flags = global.stitchTypes.stop;
} else if ((b1 === 2) || (b1 === 4)) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
flags = global.stitchTypes.trim;
} else if (b1 === -128) {
b0 = file.getInt8(i);
i += 1;
b1 = file.getInt8(i);
i += 1;
b0 = 0;
b1 = 0;
flags = global.stitchTypes.trim;
}
}
dx = expDecode(b0);
dy = expDecode(b1);
pattern.addStitchRel(dx, dy, flags, true);
}
pattern.addStitchRel(0, 0, global.stitchTypes.end);
pattern.invertPatternVertical();
};
global.expRead = expRead;
}(this));