Embroidermodder / libembroidery

Library for reading/writing/manipulating machine and design embroidery files
https://www.libembroidery.org
zlib License
45 stars 13 forks source link

Realistic render #121

Closed robin-swift closed 2 years ago

robin-swift commented 2 years ago

See the issue 106 from Embroiddermodder.

tatarize commented 2 years ago

Embroidermodder/Embroidermodder#106

tatarize commented 2 years ago

Much of the Render stuff is done in QT. Pyembroidery does this by writing a quickie PNG writer directly.

https://github.com/EmbroidePy/pyembroidery/blob/master/pyembroidery/PngWriter.py

Which is probably the only way a suite like this should implement an output render like this. Doing anything else makes the interoperability considerably reduced since requiring the packages for QT rendering in libembroidery seems to be in error.

robin-swift commented 2 years ago

That file closes the gap somewhat (and it is what I meant by doing the render in libembroidery instead), can you open a pull request with that file so you get credited and I can hand translate it to C?

tatarize commented 2 years ago

It's a bit of a tricky enterprise, not the bresenham line drawing algorithm but I don't know the C libraries or have coded any since college. Though the only really important part of that is zlib, which I'm sure has version kicking around but I wouldn't really know where it would be located. And there might be some that already write PNG in C.

I don't know that a dependency to libpng would be unacceptable.


I'm not too worried about credit. As you've seemed to be getting this project moving again, I'm following your work here, and I'm an expert with regard to embroidery formats. I'm sure we'll be seeing a lot of each other. C just isn't a language I know much at all, though it is the grand-daddy of half a dozen I can and do write. I wrote and maintain the Python and Java descendants of this code.

robin-swift commented 2 years ago

Okay, well I'll just use this as a reference then.

As for the libraries, I'm planning to have libembroidery work on a generic EmbImage structure and the caller is responsible for converting it to a format. The embroider CLI tool will just spit out a ppm since I can then use imagemagick convert to get to other formats.

tatarize commented 2 years ago

There are a couple built in images that matter within embroidery formats. For example PEC block of PES files includes little graphics that can are embedded in the file, these are 1 bit graphics on a bit level and in the pes writer in libembroidery it does a trick where it takes needle penetrations and shrinks them down very tiny and uses that to generate the image.

I have seen one example of a program that takes these graphics and ran it through a genuine dithering algorithm to show the representative image, and it looked great. I think .SEW images also have a large set of raw bit images in them too. These tend to actually get displayed on the embroidery machine itself. Including the default built in blanks, the outline of the frame there is shown on screen.

I'm not sure how much effort I'd put into this stuff, but they are, at times relevant. I built the reader into for that into pyembroidery and I think embroidepy uses it. pip install embroidepy and then embroidepy -g <file>.pes displays some of those graphics. I recall Josh wrote me a .exe file that spat out the .pngs from the pes files and it was a huge help in making sure I got the graphics locations right.