Skip to content

Commit ce5d5d2

Browse files
authored
Hus Functional
1 parent 78a1e85 commit ce5d5d2

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void read() throws IOException {
5252
ByteBuffer x_decompressed = EmbCompress.expand(ByteBuffer.wrap(x_bytes), number_of_stitches);
5353

5454
seek(y_offset);
55-
byte[] y_bytes = new byte[100000]; //readfully
55+
byte[] y_bytes = this.stream.readAllBytes(); //readfully
5656
readFully(y_bytes);
5757
ByteBuffer y_decompressed = EmbCompress.expand(ByteBuffer.wrap(y_bytes), number_of_stitches);
5858

@@ -61,30 +61,36 @@ public void read() throws IOException {
6161
command_decompressed.capacity(), x_decompressed.capacity()
6262
), y_decompressed.capacity());
6363

64+
OUTER:
6465
for (int i = 0; i < stitch_count; i++) {
65-
int cmd = command_decompressed.get(i);
66-
int x = signed8(x_decompressed.get(i));
67-
int y = -signed8(y_decompressed.get(i));
68-
if (cmd == 0x80) { //# STITCH
69-
pattern.stitch(x, y);
70-
}
71-
else if (cmd == 0x81) { // # JUMP
72-
pattern.move(x, y);
73-
}
74-
else if (cmd == 0x84) { // # COLOR_CHANGE
75-
pattern.color_change(x, y);
76-
}
77-
else if (cmd == 0x88) { //# TRIM
78-
if ((x != 0) || (y != 0)) {
66+
int cmd = (int)(command_decompressed.get(i) & 0xFF);
67+
int x = signed8((int)(x_decompressed.get(i) & 0xFF));
68+
int y = -signed8((int)(y_decompressed.get(i) & 0xFF));
69+
switch (cmd) {
70+
case 0x80:
71+
//# STITCH
72+
pattern.stitch(x, y);
73+
break;
74+
case 0x81:
75+
// # JUMP
7976
pattern.move(x, y);
80-
}
81-
pattern.trim();
82-
}
83-
else if (cmd == 0x90) { // # END
84-
break;
85-
}
86-
else { //# UNMAPPED COMMAND
87-
break;
77+
break;
78+
case 0x84:
79+
// # COLOR_CHANGE
80+
pattern.color_change(x, y);
81+
break;
82+
case 0x88:
83+
//# TRIM
84+
if ((x != 0) || (y != 0)) {
85+
pattern.move(x, y);
86+
} pattern.trim();
87+
break;
88+
case 0x90:
89+
// # END
90+
break OUTER;
91+
default:
92+
//# UNMAPPED COMMAND
93+
break OUTER;
8894
}
8995
}
9096
pattern.end();

0 commit comments

Comments
 (0)