Skip to content

Commit ea73a34

Browse files
authored
PES Reader Header 7-10
PES Reader for the headers in versions 7 through 10
1 parent 78d84cb commit ea73a34

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

core/src/main/java/org/embroideryio/embroideryio/PesReader.java

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ public void readPESHeader() throws IOException {
1818
switch (signature) {
1919
case "#PES0100":
2020
pattern.setMetadata(PROP_VERSION, Float.toString(10));
21+
readPESHeaderV10();
2122
break;
2223
case "#PES0090":
2324
pattern.setMetadata(PROP_VERSION, Float.toString(9));
25+
readPESHeaderV9();
2426
break;
2527
case "#PES0080":
2628
pattern.setMetadata(PROP_VERSION, Float.toString(8));
29+
readPESHeaderV8();
2730
break;
2831
case "#PES0070":
2932
pattern.setMetadata(PROP_VERSION, Float.toString(7));
33+
readPESHeaderV7();
3034
break;
3135
case "#PES0060":
3236
pattern.setMetadata(PROP_VERSION, Float.toString(6));
@@ -165,7 +169,151 @@ public void readPESHeaderV6() throws IOException {
165169
}
166170
seek(pecStart);
167171
}
172+
173+
public void readPESHeaderV7() throws IOException {
174+
int pecStart = readInt32LE();
175+
skip(4);
176+
readDescriptions();
177+
skip(36);
178+
int fromImageStringLength = readInt8();
179+
String fromImageString = readString(fromImageStringLength);
180+
if (fromImageString.length() != 0) {
181+
pattern.setMetadata("image_file", fromImageString);
182+
}
183+
skip(24);
184+
int numberOfProgrammableFillPatterns = readInt16LE();
185+
if (numberOfProgrammableFillPatterns != 0) {
186+
seek(pecStart);
187+
return;
188+
}
189+
int numberOfMotifPatterns = readInt16LE();
190+
if (numberOfMotifPatterns != 0) {
191+
seek(pecStart);
192+
return;
193+
}
194+
int featherPatternCount = readInt16LE();
195+
if (featherPatternCount != 0) {
196+
seek(pecStart);
197+
return;
198+
}
199+
int numberOfColors = readInt16LE();
200+
for (int i = 0; i < numberOfColors; i++) {
201+
readThread();
202+
}
203+
seek(pecStart);
204+
}
205+
206+
public void readPESHeaderV8() throws IOException {
207+
int pecStart = readInt32LE();
208+
skip(4);
209+
readDescriptions();
210+
skip(38);
211+
int fromImageStringLength = readInt8();
212+
String fromImageString = readString(fromImageStringLength);
213+
if (fromImageString.length() != 0) {
214+
pattern.setMetadata("image_file", fromImageString);
215+
}
216+
skip(26);
217+
int numberOfProgrammableFillPatterns = readInt16LE();
218+
if (numberOfProgrammableFillPatterns != 0) {
219+
seek(pecStart);
220+
return;
221+
}
222+
int numberOfMotifPatterns = readInt16LE();
223+
if (numberOfMotifPatterns != 0) {
224+
seek(pecStart);
225+
return;
226+
}
227+
int featherPatternCount = readInt16LE();
228+
if (featherPatternCount != 0) {
229+
seek(pecStart);
230+
return;
231+
}
232+
int numberOfColors = readInt16LE();
233+
for (int i = 0; i < numberOfColors; i++) {
234+
readThread();
235+
}
236+
seek(pecStart);
237+
}
168238

239+
public void readPESHeaderV9() throws IOException {
240+
int pecStart = readInt32LE();
241+
skip(4);
242+
readDescriptions();
243+
skip(14);
244+
int hoopNameStringLength = readInt8();
245+
String hoopNameString = readString(hoopNameStringLength);
246+
if (hoopNameString.length() != 0) {
247+
pattern.setMetadata("hoop_name", hoopNameString);
248+
}
249+
skip(30);
250+
int fromImageStringLength = readInt8();
251+
String fromImageString = readString(fromImageStringLength);
252+
if (fromImageString.length() != 0) {
253+
pattern.setMetadata("image_file", fromImageString);
254+
}
255+
skip(34);
256+
int numberOfProgrammableFillPatterns = readInt16LE();
257+
if (numberOfProgrammableFillPatterns != 0) {
258+
seek(pecStart);
259+
return;
260+
}
261+
int numberOfMotifPatterns = readInt16LE();
262+
if (numberOfMotifPatterns != 0) {
263+
seek(pecStart);
264+
return;
265+
}
266+
int featherPatternCount = readInt16LE();
267+
if (featherPatternCount != 0) {
268+
seek(pecStart);
269+
return;
270+
}
271+
int numberOfColors = readInt16LE();
272+
for (int i = 0; i < numberOfColors; i++) {
273+
readThread();
274+
}
275+
seek(pecStart);
276+
}
277+
278+
public void readPESHeaderV10() throws IOException {
279+
int pecStart = readInt32LE();
280+
skip(4);
281+
readDescriptions();
282+
skip(14);
283+
int hoopNameStringLength = readInt8();
284+
String hoopNameString = readString(hoopNameStringLength);
285+
if (hoopNameString.length() != 0) {
286+
pattern.setMetadata("hoop_name", hoopNameString);
287+
}
288+
skip(38);
289+
int fromImageStringLength = readInt8();
290+
String fromImageString = readString(fromImageStringLength);
291+
if (fromImageString.length() != 0) {
292+
pattern.setMetadata("image_file", fromImageString);
293+
}
294+
skip(34);
295+
int numberOfProgrammableFillPatterns = readInt16LE();
296+
if (numberOfProgrammableFillPatterns != 0) {
297+
seek(pecStart);
298+
return;
299+
}
300+
int numberOfMotifPatterns = readInt16LE();
301+
if (numberOfMotifPatterns != 0) {
302+
seek(pecStart);
303+
return;
304+
}
305+
int featherPatternCount = readInt16LE();
306+
if (featherPatternCount != 0) {
307+
seek(pecStart);
308+
return;
309+
}
310+
int numberOfColors = readInt16LE();
311+
for (int i = 0; i < numberOfColors; i++) {
312+
readThread();
313+
}
314+
seek(pecStart);
315+
}
316+
169317
public void readThread() throws IOException {
170318
int color_code_length = readInt8();
171319
String color_code = readString(color_code_length);

0 commit comments

Comments
 (0)