Merge pull request #131 from EmbroidePy/ZHS

Zhs Reader
pull/135/head
tatarize 2021-12-20 02:19:44 -08:00 zatwierdzone przez GitHub
commit 86f10396d7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 1789 dodań i 1775 usunięć

Wyświetl plik

@ -600,4 +600,3 @@ Thanks to,
---
This software is in no way derived from or based on Jackson Yee's abandoned 2006 "pyembroidery" project. The name was simply taken from libEmbroidery and written in python and thus a portmanteau of those. I was unaware of the project until after the all the principal work on this project was complete. I apologize for any confusion this may cause.

Plik diff jest za duży Load Diff

Wyświetl plik

@ -31,8 +31,8 @@ def read_pec(f, out, pes_chart=None):
stitch_block_end = read_int_24le(f) - 5 + f.tell()
# The end of this value is already 5 into the stitchblock.
# 3 bytes, '\x31\xff\xf0', 6 2-byte shorts. 15 total.
f.seek(0x0F, 1)
# 3 bytes, '\x31\xff\xf0', 4 2-byte shorts. 11 total.
f.seek(0x0B, 1)
read_pec_stitches(f, out)
f.seek(stitch_block_end, 0)

Wyświetl plik

@ -4,7 +4,6 @@ from .EmbThreadPec import get_thread_set
from .PecGraphics import draw_scaled, get_blank
from .WriteHelper import (
write_int_8,
write_int_16be,
write_int_16le,
write_int_24le,
write_string_utf8,
@ -23,6 +22,8 @@ FLAG_LONG = 0b10000000
PEC_ICON_WIDTH = 48
PEC_ICON_HEIGHT = 38
GROUP_LONG = False
def write(pattern, f, settings=None):
pattern.fix_color_count()
@ -60,7 +61,11 @@ def write_pec_header(pattern, f, threadlist):
f.write(b"\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20")
add_value = current_thread_count - 1
color_index_list.insert(0, add_value)
assert color_index_list[0] < 255, 'too many color changes, ({0}) out of bounds (0, 255)'.format(len(color_index_list))
assert (
color_index_list[0] < 255
), "too many color changes, ({0}) out of bounds (0, 255)".format(
len(color_index_list)
)
f.write(bytes(bytearray(color_index_list)))
else:
f.write(b"\x20\x20\x20\x20\x64\x20\x00\x20\x00\x20\x20\x20\xFF")
@ -82,10 +87,6 @@ def write_pec_block(pattern, f, extends):
write_int_16le(f, int(round(height)))
write_int_16le(f, 0x1E0)
write_int_16le(f, 0x1B0)
write_int_16be(f, 0x9000 | -int(round(extends[0])))
write_int_16be(f, 0x9000 | -int(round(extends[1])))
pec_encode(pattern, f)
stitch_block_length = f.tell() - stitch_block_start_position
@ -110,23 +111,39 @@ def write_pec_graphics(pattern, f, extends):
f.write(bytes(bytearray(blank)))
def encode_long_form(value):
value &= 0b0000111111111111
value |= 0b1000000000000000
return value
def write_value(f, value, long=False, flag=0):
data = []
if not long and -64 < value < 63:
data.append(value & MASK_07_BIT)
else:
value &= 0b0000111111111111
value |= 0b1000000000000000
value |= flag << 8
data.append((value >> 8) & 0xFF)
data.append(value & 0xFF)
f.write(bytes(bytearray(data)))
def flag_jump(long_form):
return long_form | (JUMP_CODE << 8)
def write_trimjump(f, dx, dy):
write_value(f, dx, long=True, flag=TRIM_CODE)
write_value(f, dy, long=True, flag=TRIM_CODE)
def flag_trim(long_form):
return long_form | (TRIM_CODE << 8)
def write_jump(f, dx, dy):
write_value(f, dx, long=True, flag=JUMP_CODE)
write_value(f, dy, long=True, flag=JUMP_CODE)
def write_stitch(f, dx, dy):
long = GROUP_LONG and -64 < dx < 63 and -64 < dy < 63
write_value(f, dx, long)
write_value(f, dy, long)
def pec_encode(pattern, f):
color_two = True
jumping = False
jumping = True
init = True
stitches = pattern.stitches
xx = 0
yy = 0
@ -141,33 +158,18 @@ def pec_encode(pattern, f):
if data == STITCH:
if jumping:
if dx != 0 and dy != 0:
f.write(b"\x00\x00")
write_stitch(f, 0, 0)
jumping = False
if -64 < dx < 63 and -64 < dy < 63:
f.write(bytes(bytearray([dx & MASK_07_BIT, dy & MASK_07_BIT])))
else:
dx = encode_long_form(dx)
dy = encode_long_form(dy)
data = [(dx >> 8) & 0xFF, dx & 0xFF, (dy >> 8) & 0xFF, dy & 0xFF]
f.write(bytes(bytearray(data)))
continue
write_stitch(f, dx, dy)
elif data == JUMP:
jumping = True
dx = encode_long_form(dx)
dx = flag_trim(dx)
dy = encode_long_form(dy)
dy = flag_trim(dy)
f.write(
bytes(
bytearray(
[(dx >> 8) & 0xFF, dx & 0xFF, (dy >> 8) & 0xFF, dy & 0xFF]
)
)
)
continue
if init:
write_jump(f, dx, dy)
else:
write_trimjump(f, dx, dy)
elif data == COLOR_CHANGE:
if jumping:
f.write(b"\x00\x00")
write_stitch(f, 0, 0)
jumping = False
f.write(b"\xfe\xb0")
if color_two:
@ -175,11 +177,11 @@ def pec_encode(pattern, f):
else:
f.write(b"\x01")
color_two = not color_two
continue
elif data == STOP:
continue # These will already be processed into duplicate colors.
pass # These will already be processed into duplicate colors.
elif data == TRIM:
continue
pass
elif data == END:
f.write(b"\xff")
break
init = False

Wyświetl plik

@ -73,7 +73,7 @@ def read_zhs_stitches(f, out):
out.end()
def read_zhz_header(f, out):
def read_zhs_header(f, out):
color_count = read_int_8(f)
for i in range(color_count):
out.add_thread(read_int_24be(f))
@ -103,6 +103,6 @@ def read(f, out, settings=None):
stitch_start_position = read_int_32le(f)
header_start_position = read_int_32le(f)
f.seek(header_start_position, 0)
read_zhz_header(f, out)
read_zhs_header(f, out)
f.seek(stitch_start_position, 0)
read_zhs_stitches(f, out)

Wyświetl plik

@ -204,6 +204,14 @@ def get_simple_stop():
return pattern
def get_long_jump():
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")
pattern.add_block([(3000, 3000), (3000, 3100), (3100, 3100), (3100, 3000), (3000, 3000)], "red")
return pattern
def get_simple_pattern():
pattern = EmbPattern()
pattern.add_block([(0, 0), (0, 100), (100, 100), (100, 0), (0, 0)], "red")

Wyświetl plik

@ -168,4 +168,9 @@ class TestConverts(unittest.TestCase):
self.position_equals(t_pattern.stitches, 0, -1)
print("pes->xxx: ", t_pattern.stitches)
self.addCleanup(os.remove, file1)
self.addCleanup(os.remove, file2)
self.addCleanup(os.remove, file2)
def test_write_pes_long(self):
file1 = "long.pes"
write_pes(get_long_jump(), file1)
self.addCleanup(os.remove, file1)