forked from redteam316/html5-embroidery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dstformat.js
109 lines (106 loc) · 2.68 KB
/
dstformat.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(function (global) {
"use strict";
function decodeExp(b2) {
var returnCode = 0;
if (b2 === 0xF3) {
return global.stitchTypes.end;
}
if ((b2 & 0xC3) === 0xC3) {
return global.stitchTypes.trim | global.stitchTypes.stop;
}
if (b2 & 0x80) {
returnCode |= global.stitchTypes.trim;
}
if (b2 & 0x40) {
returnCode |= global.stitchTypes.stop;
}
return returnCode;
}
function dstRead(file, pattern) {
var flags,
x,
y,
prevJump = false,
thisJump = false,
b = [],
byteCount = file.byteLength;
file.seek(512);
while (file.tell() < (byteCount - 3)) {
b[0] = file.getUint8();
b[1] = file.getUint8();
b[2] = file.getUint8();
x = 0;
y = 0;
if (b[0] & 0x01) {
x += 1;
}
if (b[0] & 0x02) {
x -= 1;
}
if (b[0] & 0x04) {
x += 9;
}
if (b[0] & 0x08) {
x -= 9;
}
if (b[0] & 0x80) {
y += 1;
}
if (b[0] & 0x40) {
y -= 1;
}
if (b[0] & 0x20) {
y += 9;
}
if (b[0] & 0x10) {
y -= 9;
}
if (b[1] & 0x01) {
x += 3;
}
if (b[1] & 0x02) {
x -= 3;
}
if (b[1] & 0x04) {
x += 27;
}
if (b[1] & 0x08) {
x -= 27;
}
if (b[1] & 0x80) {
y += 3;
}
if (b[1] & 0x40) {
y -= 3;
}
if (b[1] & 0x20) {
y += 27;
}
if (b[1] & 0x10) {
y -= 27;
}
if (b[2] & 0x04) {
x += 81;
}
if (b[2] & 0x08) {
x -= 81;
}
if (b[2] & 0x20) {
y += 81;
}
if (b[2] & 0x10) {
y -= 81;
}
flags = decodeExp(b[2]);
thisJump = flags & global.stitchTypes.jump;
if (prevJump) {
flags |= global.stitchTypes.jump;
}
pattern.addStitchRel(x, y, flags, true);
prevJump = thisJump;
}
pattern.addStitchRel(0, 0, global.stitchTypes.end, true);
pattern.invertPatternVertical();
}
global.dstRead = dstRead;
}(this));