Initial SewWriter implementation#135
Conversation
|
After a bit more testing (and hair loss), I noticed two issues: Stitch CountThe stitch count values always appeared to be slightly incorrect, even when produced via Janome's own software. Splitting the stitch data on for index in range(len(pattern.threadlist)):
len(data.split(b"\x80\x01")[index].split(b"\x80\x10")[0]) // 2The value for the last thread was (more) wrong as it didn't remove data after Missing End StitchWhen looking at original SEW files, in the last thread block, there was often an Reverse engineering with Ghidra of TestingAfter writing the file to disk and attempting the pattern on a physical embroidery machine, it was not able to read the file until I copied the remaining, unknown data from the header of another SEW file generated from official software. As I am not sure what this data is, I am unable to produce it in the writer at the moment, but I suspect it may relate to hoop size. After copying the header over, it did (partially to my surprise) actually stitch the pattern. P.S. I appreciate this format is ancient and likely no longer used by anyone, but we have recently inherited a Memory Craft 9000 and wanted to print custom patterns. |
|
Thank you for your pull request. |
|
@kaalleen README has been updated. Thanks! As a side-note, when converting between formats, I noticed that the pattern was displayed rather close to the top-left corner in the Customizer 2000 software, causing some of the stitches to repeatedly use the same location. OFFSET = 192
pattern = pystitch.read(path)
for stitch in pattern.stitches:
stitch[0] += OFFSET # x-coordinate
pystitch.write(pattern, output)To copy the header from a working pattern: HEADER_SIZE = 0x1D78
with open(path, "rb") as original:
header = original.read(HEADER_SIZE)
with open(output, "rb") as patched:
data = patched.read()
with open(output, "wb") as file:
file.write(header + data[HEADER_SIZE:])Where |
You can pass a translate value directly to the writer (or converter). |
This is a draft implementation of
SewWriter.pystitch.SewWritermodulewritertosupported_formatsforsewextensionTesting
Patterns have been tested by:
pystitch.SewReaderpystitch.SewWriter(this PR)It has not yet been tested on a Janome Memory Craft machine, but likely will be in due time.
Format
The format is a simplified version of JEF, with similar control sequences but with less metadata (see header from KDE Liberty community project documentation below).
The stitch data seems to be correct, matching the original data, with the exception of occasional
\x80\x10control sequences, which are read bySewReaderas a normal stitch. As this data is lost, it is not possible to reinsert these sequences when writing.Currently, the writer does not obtain the correct values for the number of stitches per thread/colour (offset
0x32), causing part of the design not to be displayed in Customizer 2000 (although displayed correctly in InkStitch). When overwritten manually, the patterns display correctly. Any assistance with this would be greatly appreciated. By splitting the original bytes by control sequence\x80\x02\x00\x00, I could replicate the original numbers for one pattern (four colours) but not another (one colour). The original bytes are not available in anEmbPatternobject either, so it would be ideal to get these values from available methods, e.g.EmbPattern.get_as_colorblocks.The bitmap data described in the resources below is not implemented, but does not appear to be necessary.
Resources
https://edutechwiki.unige.ch/en/Embroidery_format
https://community.kde.org/Projects/Liberty/File_Formats/Janome_Embroidery_Format#SEW_Format