forked from redteam316/html5-embroidery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sewformat.js
62 lines (60 loc) · 2.04 KB
/
sewformat.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
(function (global) {
"use strict";
function sewDecode(inputByte) {
return (inputByte >= 0x80) ? ((-(~inputByte & 0xFF)) - 1) : inputByte;
}
function sewRead(file, pattern) {
var i,
fileLength = 0,
dx = 0,
dy = 0,
flags = 0,
numberOfColors = 0,
thisStitchIsJump = 0,
b0 = 0,
b1 = 0,
colors = global.jefColors;
fileLength = file.byteLength;
numberOfColors = file.getUint8();
numberOfColors += (file.getUint8() << 8);
for (i = 0; i < numberOfColors; i += 1) {
var colorIndex = file.getInt16(file.tell(), true);
pattern.addColor(colors[colorIndex]);
}
file.seek(0x1D78);
for (i = 0; file.tell() < fileLength; i += 1) {
b0 = file.getUint8();
b1 = file.getUint8();
flags = global.stitchTypes.normal;
if (thisStitchIsJump) {
flags = global.stitchTypes.trim;
thisStitchIsJump = 0;
}
if (b0 === 0x80) {
if (b1 === 1) {
b0 = file.getUint8();
b1 = file.getUint8();
flags = global.stitchTypes.stop;
} else if ((b1 === 0x02) || (b1 === 0x04)) {
thisStitchIsJump = 1;
b0 = file.getUint8();
b1 = file.getUint8();
flags = global.stitchTypes.trim;
} else if (b1 === 0x10) {
break;
}
}
dx = sewDecode(b0);
dy = sewDecode(b1);
if (Math.abs(dx) === 127 || Math.abs(dy) === 127) {
thisStitchIsJump = 1;
flags = global.stitchTypes.trim;
}
pattern.addStitchRel(dx, dy, flags, true);
}
pattern.addStitchRel(0, 0, global.stitchTypes.end, true);
pattern.invertPatternVertical();
return true;
}
global.sewRead = sewRead;
}(this));