inkstitch / pyembroidery

libembroidery/EmbroideryFormats converted to python
MIT License
71 stars 28 forks source link

enumerate formats supported #35

Closed lexelby closed 5 years ago

lexelby commented 5 years ago

It looks to me like pyembroidery is almost ready for me to start trying to integrate it with Ink/Stitch.

One of the features of libembroidery that I make use of is enumerating file formats. I use this in a couple of scripts to generate various option lists and plugin definitions to tell Inkscape what formats Ink/Stitch can save and load (example).

Can we have an API call like this in pyembroidery?

I'm trying to decide whether to switch to pyembroidery entirely or have a transition period with both pyembroidery and libembroidery. I'd much rather get rid of libembroidery, but of course we'd have to remove "reads 48 embroidery file formats" from our documentation. :) Thing is, I don't think libembroidery necessarily can successfully read a lot of those formats. Certainly writing a lot of them leaves something to be desired...

Perhaps I'll create a simple web service that uses libembroidery to convert designs to DST or somesuch.

tatarize commented 5 years ago

I created a simple web service that used libembroidery to convert designs to a variety of formats. Before I wrote my android app doing embroidery, I wrote a program that converts raster images automatically to fully realized embroidery that is literally picture perfect. We (my brother and I) had photoembroidery output dst files and converted them to other formats with libembroidery. It was actually bad enough that we quickly had to drop it.

It's one of the reasons why I ended up writing my own versions of the formats. It is literally not a thing I wanted to do. Embroidery formats are a clusterfrack, and there's a bunch of them and they all sort of suck in various and obscure ways. But, having done this work. I sort of knew you'd need it if you wanted your project to be successful, you'd need a version of that. It would have been faster but I had to work out all of VP3 including some previously unknown parts like how multiple designs in the same file work, etc. And wrote the python code to actually reflect how the formats actually work.


But, I digress. The other things you actually need though are the options for the formats and an enumeration of them. Take, for example, PES files. The PesWriter actually writes 2 different versions in 2 different forms. Namely you can write Version 1 and Version 6 of the format (I could also write the other mapped out versions too (2,3,4,5)), and you can write them truncated (without the pes blocks, machines don't read them, only brother software cares). Versions above 4 includes metadata (name, author, category, comment, keywords). Versions above 5 include fullcolor RGB thread, with name, catalog number, and brand, (there's also a bunch of other stuff like feather-patterns and programmable stitches and motifs but nobody would care about that stuff). If you specifically select exact colors you loved, then these might get these pigeon-holed below version 5 into whatever was available in the PEC palette. There's also an option in DST to write them with extended headers.

PREMIER+2™ for VP3 software has a number of export options, namely "ColorSort" optimizes colors into various groups (outside the scope of pyembroidery), "Optimize Stitch Lengths" with low, medium, and high sensitivity removing minimum significant stitch length of 0.6mm, 0.8mm and 1.0mm (this actually seems like it falls within what pyembroidery should do), and Flip design for felting or reverse embroidery (this is covered in scale, literally scale by -1, 1 and you'll have that (also I added scale). But, if you switch to saving PES files suddenly you get options for saving file version and the hoop to use. SHV will suddenly let you format a floppy disk or USB stick, in addition to the basic options. JEF will let you change the hoop.

Wilcom will gives PES extra options for version. JEF files get to save for a particular machine (MC12000, MC11000, MC10001, MC10000 V3 or higher, (MC9700, MC9500 or MC330E), MC350E, MC200E, MB-4. CSD format, has a switch between "Poem, Viking Huskygram TYPE I" and "Poem, Viking Huskygram, Singer EU TYPE II"

Brother version 6, gives you an option in DST to specify how many jumps results in a trim. Version 10 has no options.


But, a simple list of formats with their read/write support, description, and general stability known, as well as options particular specific options available seems entirely reasonable. ["pes", "pec", "jef", "vp3", "dst", "exp"] (omitting .svg)

Also, some of the lib-embroidery stuff isn't embroidery formats, he has some stuff for like .plt which is HPGL or basically the standard for plotter devices. These basically can take XY plotters and make them draw a picture if you give them a pen, or to cut vinyl with a vinyl cutter. They aren't strictly speaking embroidery formats.

I guess really the API extension of this should actually categorize them too. So if I added say writing CSV files, (they might be really useful for debugging for example) I could give flag it properly as not being an embroidery file.

tatarize commented 5 years ago

Also, a lot of the work was for good bones. It should not be hard to go from LibEmbroidery C++ files to additional readers. Readers usually just skip through the file and pick up relevant data and then toss it into the pattern file. It's quite doable to add a reader without mapping out the format, the Embroidermodder team did the hard work of what means what in the file (generally). It's just that sometimes it won't work. But, it's entirely doable to write a few of the readers in rather short order. They just aren't part of the mandate. I slapped one together to respond to an inkstitch issue.

A bunch of these readers with quality on par with libembroidery is not that much work. The real work is when you need quality beyond that of libembroidery. If the reader is wrong in some way. It's often hard to figure out why, and requires mapping the format out. When the writer is wrong in some way, you need to get examples of the file, compare a bunch of converted versions from other software, and try to make it as close as possible and hope that the software isn't missing an error that an embroidery machine would crash on.

tatarize commented 5 years ago

Where blank means nothing, and U means unstable. I'll figure a quick way to setup the relevant data, and let you skip things like claiming it saves svg when you ask which embroidery formats it loads. Might needs a short hand for format specific features that also gives the permitted values.

heapFormatList = embFormatList_add(heapFormatList, ".100", "Toyota Embroidery Format",           'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".art", "Bernina Embroidery Format",          ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".bmc", "Bitmap Cache Embroidery Format",     ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".bro", "Bits & Volts Embroidery Format",     'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".cnd", "Melco Embroidery Format",            ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".col", "Embroidery Thread Color Format",     'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".csd", "Singer Embroidery Format",           'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".csv", "Comma Separated Values Format",      'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dat", "Barudan Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dem", "Melco Embroidery Format",            ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dsb", "Barudan Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dst", "Tajima Embroidery Format",           'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dsz", "ZSK USA Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".dxf", "Drawing Exchange Format",            ' ', ' ', EMBFORMAT_OBJECTONLY);
heapFormatList = embFormatList_add(heapFormatList, ".edr", "Embird Embroidery Format",           'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".emd", "Elna Embroidery Format",             'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".exp", "Melco Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".exy", "Eltac Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".eys", "Sierra Expanded Embroidery Format",  ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".fxy", "Fortron Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".gc",  "Smoothie G-Code Format",             ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".gnc", "Great Notions Embroidery Format",    ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".gt",  "Gold Thread Embroidery Format",      'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".hus", "Husqvarna Viking Embroidery Format", 'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".inb", "Inbro Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".inf", "Embroidery Color Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".jef", "Janome Embroidery Format",           'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".ksm", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".max", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".mit", "Mitsubishi Embroidery Format",       'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".new", "Ameco Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".ofm", "Melco Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pcd", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pcm", "Pfaff Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pcq", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pcs", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pec", "Brother Embroidery Format",          'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pel", "Brother Embroidery Format",          ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pem", "Brother Embroidery Format",          ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".pes", "Brother Embroidery Format",          'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".phb", "Brother Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".phc", "Brother Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".plt", "AutoCAD Plot Drawing Format",        'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".rgb", "RGB Embroidery Format",              'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".sew", "Janome Embroidery Format",           'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".shv", "Husqvarna Viking Embroidery Format", 'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".sst", "Sunstar Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".stx", "Data Stitch Embroidery Format",      'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".svg", "Scalable Vector Graphics",           'U', 'U', EMBFORMAT_OBJECTONLY);
heapFormatList = embFormatList_add(heapFormatList, ".t01", "Pfaff Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".t09", "Pfaff Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".tap", "Happy Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".thr", "ThredWorks Embroidery Format",       'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".txt", "Text File",                          ' ', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".u00", "Barudan Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".u01", "Barudan Embroidery Format",          ' ', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".vip", "Pfaff Embroidery Format",            'U', ' ', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".vp3", "Pfaff Embroidery Format",            'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".xxx", "Singer Embroidery Format",           'U', 'U', EMBFORMAT_STITCHONLY);
heapFormatList = embFormatList_add(heapFormatList, ".zsk", "ZSK USA Embroidery Format",          'U', ' ', EMBFORMAT_STITCHONLY);
tatarize commented 5 years ago

Yeah. Added supported_formats() with all the potential useful data I could think of. Setup a pretty reasonable scheme for defining options. And changed PES writer better fit with that.

lexelby commented 5 years ago

Thanks! I'll check it out later today.

lexelby commented 5 years ago

Looks great! I love how it lists the settings that the format takes.