Skip to content

Commit 8ce7dbd

Browse files
authored
Merge pull request #127 from EmbroidePy/1.4.30
Zhs Corrections, Implementation
2 parents ec1c154 + 7cf247e commit 8ce7dbd

File tree

4 files changed

+105
-19
lines changed

4 files changed

+105
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Pyembroidery will read:
155155
* .tbf
156156
* .u01
157157
* .xxx
158+
* .zhs
158159
* .zxy
159160
* .gcode
160161

pyembroidery/EmbPattern.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
import pyembroidery.XxxReader as XxxReader
6767
import pyembroidery.XxxWriter as XxxWriter
6868

69-
# import pyembroidery.ZhsReader as ZhsReader
69+
import pyembroidery.ZhsReader as ZhsReader
7070
import pyembroidery.ZxyReader as ZxyReader
7171

7272
from .EmbEncoder import Transcoder as Normalizer
@@ -923,7 +923,7 @@ def supported_formats():
923923
)
924924
yield (
925925
{
926-
"description": "Melco Embroidery Format",
926+
"description": "Melco Expanded Embroidery Format",
927927
"extension": "exp",
928928
"extensions": ("exp",),
929929
"mimetype": "application/x-exp",
@@ -932,6 +932,16 @@ def supported_formats():
932932
"writer": ExpWriter,
933933
}
934934
)
935+
# yield (
936+
# {
937+
# "description": "Melco Condensed Embroidery Format",
938+
# "extension": "cnd",
939+
# "extensions": ("cnd",),
940+
# "mimetype": "application/x-cnd",
941+
# "category": "embroidery",
942+
# "reader": CndReader,
943+
# }
944+
# )
935945
yield (
936946
{
937947
"description": "Tajima Embroidery Format",
@@ -1317,13 +1327,13 @@ def supported_formats():
13171327
"reader": StcReader,
13181328
}
13191329
)
1320-
# yield ({
1321-
# "description": "Zeng Hsing Embroidery Format",
1322-
# "extension": "zhs",
1323-
# "mimetype": "application/x-zhs",
1324-
# "category": "embroidery",
1325-
# "reader": ZhsReader
1326-
# })
1330+
yield ({
1331+
"description": "Zeng Hsing Embroidery Format",
1332+
"extension": "zhs",
1333+
"mimetype": "application/x-zhs",
1334+
"category": "embroidery",
1335+
"reader": ZhsReader
1336+
})
13271337
yield (
13281338
{
13291339
"description": "ZSK TC Embroidery Format",

pyembroidery/ZhsReader.py

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,109 @@
1-
from .ReadHelper import read_int_32le, signed8
1+
from .ReadHelper import read_int_32le, read_int_16le, read_int_8, read_int_24be, signed8
22

33

44
def read_zhs_stitches(f, out):
55
count = 0
6+
7+
xx = 0
8+
yy = 0
69
while True:
710
count += 1
811
b = bytearray(f.read(3))
912
if len(b) != 3:
1013
break
1114
ctrl = b[0]
1215
if ctrl == 0x10:
16+
# Checksum
17+
continue
18+
# x
19+
x = 0
20+
x += b[1] & 0b00000001
21+
x += b[2] & 0b00000010
22+
x += b[1] & 0b00000100
23+
x += b[2] & 0b00001000
24+
x += b[1] & 0b00010000
25+
x += b[2] & 0b00100000
26+
x += b[1] & 0b01000000
27+
x += b[2] & 0b10000000
28+
x = signed8(x)
29+
if x >= 63:
30+
x += 1
31+
if x <= -63:
32+
x -= 1
33+
34+
# y
35+
y = 0
36+
y += b[2] & 0b00000001
37+
y += b[1] & 0b00000010
38+
y += b[2] & 0b00000100
39+
y += b[1] & 0b00001000
40+
y += b[2] & 0b00010000
41+
y += b[1] & 0b00100000
42+
y += b[2] & 0b01000000
43+
y += b[1] & 0b10000000
44+
45+
y = signed8(y)
46+
if y >= 63:
47+
y += 1
48+
if y <= -63:
49+
y -= 1
50+
51+
xx += x
52+
yy += y
53+
if ctrl == 0x41:
54+
# Still unmapped.
1355
pass
14-
x = signed8(b[1])
15-
y = signed8(b[2])
16-
if ctrl == 0x02:
17-
out.stitch(x, y)
56+
elif ctrl == 0x02:
57+
out.stitch(xx, -yy)
58+
xx = 0
59+
yy = 0
1860
continue
19-
if ctrl == 0x01:
20-
out.move(x, y)
61+
elif ctrl == 0x01:
62+
print(xx,yy,"move")
63+
out.move(xx, -yy)
64+
xx = 0
65+
yy = 0
2166
continue
22-
if ctrl == 0x04:
67+
elif ctrl == 0x04:
68+
xx = 0
69+
yy = 0
2370
out.color_change()
2471
continue
25-
if ctrl == 0x80:
72+
elif ctrl == 0x80:
2673
break
2774
out.end()
2875

2976

77+
def read_zhz_header(f, out):
78+
color_count = read_int_8(f)
79+
for i in range(color_count):
80+
out.add_thread(read_int_24be(f))
81+
length = read_int_16le(f)
82+
b = bytearray(f.read(length))
83+
thread_data = b.decode('utf8')
84+
threads = thread_data.split("&$")
85+
try:
86+
for i, data in enumerate(threads[1:]):
87+
thread = out.threadlist[i]
88+
parts = data.split("&#")
89+
try:
90+
if len(parts[0]):
91+
thread.chart = parts[0]
92+
if len(parts[1]):
93+
thread.description = parts[1]
94+
if len(parts[2]) > 3:
95+
thread.catalog_number = parts[2][:-2]
96+
except IndexError:
97+
pass
98+
except IndexError:
99+
pass
100+
101+
30102
def read(f, out, settings=None):
31103
f.seek(0x0F, 0)
32104
stitch_start_position = read_int_32le(f)
105+
header_start_position = read_int_32le(f)
106+
f.seek(header_start_position, 0)
107+
read_zhz_header(f, out)
33108
f.seek(stitch_start_position, 0)
34109
read_zhs_stitches(f, out)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pyembroidery",
8-
version="1.4.29",
8+
version="1.4.30",
99
author="Tatarize",
1010
author_email="[email protected]",
1111
description="Embroidery IO library",

0 commit comments

Comments
 (0)