-
Notifications
You must be signed in to change notification settings - Fork 19
/
vp3format.js
160 lines (138 loc) · 4.86 KB
/
vp3format.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
(function (global) {
"use strict";
function vp3ReadString(file) {
var stringLength = file.getInt16();
return file.getString(stringLength);
}
function vp3Decode(inputByte) {
return (inputByte > 0x80) ? -(((~inputByte) + 1) & 0xFF) : inputByte;
}
function vp3DecodeInt16(inputByte) {
return ((inputByte & 0xFFFF) >= 0x8000) ? -(((~inputByte) + 1) & 0xFFFF) : inputByte;
}
function vp3ReadHoopSection(file) {
var hoop = {
right : file.getInt32(),
bottom : file.getInt32(),
left : file.getInt32(),
top : file.getInt32(),
unknown1 : file.getInt32(),
unknown2 : file.getInt32(),
unknown3 : file.getInt32(),
numberOfBytesRemaining : file.getInt32(),
xOffset : file.getInt32(),
yOffset : file.getInt32(),
byte1 : file.getUint8(),
byte2 : file.getUint8(),
byte3 : file.getUint8(),
/* Centered hoop dimensions */
right2 : file.getInt32(),
left2 : file.getInt32(),
bottom2 : file.getInt32(),
top2 : file.getInt32(),
width : file.getInt32(),
height : file.getInt32()
};
return hoop;
}
function vp3Read(file, pattern) {
var magicString,
some,
someString = 0,
unknownString3 = 0,
numberOfColors,
colorSectionOffset,
magicCode,
someShort,
someByte,
bytesRemainingInFile,
unknownByteString = 0,
hoopConfigurationOffset,
unknownString2 = 0,
stitchTypes = global.stitchTypes,
i,
r,
g,
b,
tableSize,
unknownX,
unknownY,
unknownX2,
unknownY2,
str1,
str2,
str3,
unknownThreadString,
numberOfBytesInColor,
x,
y;
if (!pattern) {
embLog("format-vp3.c readVp3(), pattern argument is null\n");
return 0;
}
magicString = file.getBytes(5); /* %vsm% */
some = file.getUint8(); /* 0 */
someString = vp3ReadString(file);
someShort = file.getInt16();
someByte = file.getUint8();
bytesRemainingInFile = file.getInt32();
unknownByteString = vp3ReadString(file);
hoopConfigurationOffset = file.tell();
vp3ReadHoopSection(file);
unknownString2 = vp3ReadString(file);
file.seek(file.tell() + 18);
magicCode = file.getBytes(6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */
unknownString3 = vp3ReadString(file);
numberOfColors = file.getInt16();
colorSectionOffset = file.tell();
for (i = 0; i < numberOfColors; i += 1) {
file.seek(0x03 + colorSectionOffset);
colorSectionOffset = file.getInt32();
colorSectionOffset += file.tell();
unknownX = file.getInt32();
unknownY = file.getInt32();
tableSize = file.getUint8();
file.getUint8(); // changed this
r = file.getUint8();
g = file.getUint8();
b = file.getUint8(); // added this
pattern.addColor(new Color(r,b,g, ""));
file.seek(file.tell() + 6 * tableSize - 1); // changed this
str1 = vp3ReadString(file);
str2 = vp3ReadString(file);
str3 = vp3ReadString(file);
unknownX2 = file.getInt32();
unknownY2 = file.getInt32();
unknownThreadString = file.getInt16();
file.seek(file.tell() + unknownThreadString);
numberOfBytesInColor = file.getInt32();
file.seek(file.tell() + 0x3);
while (file.tell() < colorSectionOffset - 1) {
x = vp3Decode(file.getUint8());
y = vp3Decode(file.getUint8());
if (x === 0x80) {
switch (y) {
case 0x00:
case 0x03:
break;
case 0x01:
x = vp3DecodeInt16(file.getInt16());
y = vp3DecodeInt16(file.getInt16());
file.getInt16();
pattern.addStitchRel(x, y, stitchTypes.trim, true);
break;
default:
break;
}
} else {
pattern.addStitchRel(x, y, stitchTypes.normal, true);
}
}
if (i + 1 < numberOfColors) {
pattern.addStitchRel(0, 0, stitchTypes.stop, true);
}
}
pattern.addStitchRel(0, 0, stitchTypes.end, true);
}
global.vp3Read = vp3Read;
}(this));