-
Notifications
You must be signed in to change notification settings - Fork 19
/
zskformat.js
137 lines (122 loc) · 3.88 KB
/
zskformat.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(function (global) {
"use strict";
function zskRead(file, pattern) {
var rr,
gg,
bb,
b = [],
stitchType,
colorNumber = 0,
byteCount = file.byteLength;
file.seek(0x230);
colorNumber = file.getUint8();
while(colorNumber != 0)
{
rr = file.getUint8();
gg = file.getUint8();
bb = file.getUint8();
pattern.addColor(new Color(rr, gg, bb, ""));
file.seek(file.tell() + 0x48);
colorNumber = file.getUint8();
}
file.seek(file.tell() + 0x2E);
while(file.tell() < (byteCount - 3))
{
b[0] = file.getUint8();
b[1] = file.getUint8();
b[2] = file.getUint8();
stitchType = global.stitchTypes.normal;
if(b[0] & 0x4)
b[2] = -b[2];
if(b[0] & 0x8)
b[1] = -b[1];
if(b[0] & 0x02)
stitchType = global.stitchTypes.jump;
if(b[0] & 0x20)
{
if(b[1] === 2)
stitchType = global.stitchTypes.trim;
else if(b[1] === -1)
break;
else
{
if(b[2] != 0)
colorNumber = b[2];
stitchType = global.stitchTypes.stop; //TODO: need to determine what b[1] is used for.
//pattern.changeColor(pattern, colorNumber - 1); //TODO: port this function
}
b[1] = 0;
b[2] = 0;
}
pattern.addStitchRel(b[1] / 10.0, b[2] / 10.0, stitchType, true);
}
pattern.addStitchRel(0, 0, global.stitchTypes.end, true);
pattern.invertPatternVertical();
return true;
}
global.zskRead = zskRead;
}(this));
/*
//TODO:This is the C code for reference. Remove when everything is fully ported.
int readZsk(EmbPattern* pattern, const char* fileName)
{
char b[3];
EmbFile* file = 0;
int stitchType;
unsigned char colorNumber;
if(!pattern) { embLog_error("format-zsk.c readZsk(), pattern argument is null\n"); return 0; }
if(!fileName) { embLog_error("format-zsk.c readZsk(), fileName argument is null\n"); return 0; }
file = embFile_open(fileName, "rb");
if(!file)
{
embLog_error("format-zsk.c readZsk(), cannot open %s for reading\n", fileName);
return 0;
}
embFile_seek(file, 0x230, SEEK_SET);
colorNumber = binaryReadUInt8(file);
while(colorNumber != 0)
{
EmbThread t;
t.color.r = binaryReadUInt8(file);
t.color.g = binaryReadUInt8(file);
t.color.b = binaryReadUInt8(file);
t.catalogNumber = "";
t.description = "";
embPattern_addThread(pattern, t);
embFile_seek(file, 0x48, SEEK_CUR);
colorNumber = binaryReadUInt8(file);
}
embFile_seek(file, 0x2E, SEEK_CUR);
while(embFile_read(b, 1, 3, file) == 3)
{
stitchType = NORMAL;
if(b[0] & 0x4)
b[2] = -b[2];
if(b[0] & 0x8)
b[1] = -b[1];
if(b[0] & 0x02)
stitchType = JUMP;
if(b[0] & 0x20)
{
if(b[1] == 2)
stitchType = TRIM;
else if(b[1] == -1)
break;
else
{
if(b[2] != 0)
colorNumber = b[2];
stitchType = STOP; //TODO: need to determine what b[1] is used for.
embPattern_changeColor(pattern, colorNumber - 1);
}
b[1] = 0;
b[2] = 0;
}
embPattern_addStitchRel(pattern, b[1] / 10.0, b[2] / 10.0, stitchType, 0);
}
embFile_close(file);
if(pattern->lastStitch->stitch.flags != END)
embPattern_addStitchRel(pattern, 0, 0, END, 1);
return 1;
}
*/