-
Notifications
You must be signed in to change notification settings - Fork 10
Writing PES
We can read PES and PEC for all versions by reading the color data and stitch data from the PEC block. But, the typical use case is going to be writing a successful PES file. [all writes should be done Little Endian].
We must write the following things to disk.
- 8 bytes: "#PES0001"
- 4 bytes: Location of PEC block.
- 2 bytes: 1 (scale to fit)
- 2 bytes: 1 (hoop size, 130mm 180mm)
- 2 bytes: 1 (we are going to write only one stitchblock object).
- 4 bytes: FF FF 00 00, end the header.
- 2 bytes: 7 (length of text "EmbOne")
- 7 bytes: "EmbOne"
- 2 bytes: 0, minX (we're passing on this)
- 2 bytes: 0, minY (we're passing on this)
- 2 bytes: 0, maxX (we're passing on this)
- 2 bytes: 0, maxY (we're passing on this). (Starting StitchGroup definition)
- 2 bytes: 0, minX (we're passing on this)
- 2 bytes: 0, minY (we're passing on this)
- 2 bytes: 0, maxX (we're passing on this)
- 2 bytes: 0, maxY (we're passing on this).
- 4 bytes: float 1, 00 00 80 3F (Scale X)
- 4 bytes: float 0, 00 00 00 00 (Skew_X)
- 4 bytes: float 0, 00 00 00 00 (Skew_Y)
- 4 bytes: float 1, 00 00 80 3F (Scale_Y)
- 4 bytes: float (350 + HoopWidth/2 - WidthOfDesign/2), 350 is the distance from 0,0 that the 130mm x 180mm hoop is stored, if we add half the HoopWidth (1300 / 2) and subtract half our design's width. The embroidery will be centered in the hoop.
- 4 bytes float (100 + HoopHeight/2 - HeightOfDesign/2), 100 is the distance from 0,0 that our 130mm x 180mm hoop is stored, if we add half the HoopHeight (1800 / 2) and subtract half our design's height. The embroidery will be centered in the hoop.
- 2 bytes: 1, unknown.
- 2 bytes: 0, X-location (we're passing on this).
- 2 bytes 0, Y-location (we're passing on this).
- 2 bytes width, WidthOfDesign
- 2 bytes height, WidthOfDesign.
- 4 bytes, 0, unknown.
- 4 bytes, 0 unknown.
- 2 bytes, number of segments + (2 * colorChanges), this is going to be the number of segments we will need to use.
- (End StitchGroup definition)
- 4 bytes FF FF 00 00, end block.
- 2 bytes: 7, length of "CSewSeg"
- 7 bytes: "CSewSeg"
For these, we must ensure our segments are flagged 0,1,0,1,0,1,0. That our jumps are 0, that our stitches are 1, that our color changes are 0, we pad with jumps and stitches to nowhere to maintain this. We assume that we jump to the location, then color change, then stitch as relevant.
- 2 bytes: 1 this is a stitch.
- 2 bytes color, color index.
- 2 bytes 2, needs a length of at least two to not be a color change.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 bytes 0x8001, 01 80. End Segment
- 2 bytes: 0, non-stitching.
- 2 bytes, color, color index.
- 2 bytes, 2, needs a length of at least two to not be a color change.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 bytes 0x8001, 01 80. End Segment (We didn't call a color change event, but we ensured that the initial color is established)
- 2 bytes: 0, we are not sewing this
- 2 bytes: Color, color index. Index of old color.
- 2 byte: 1, length of stitches.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 bytes 0x8001, 01 80. End Segment
- 2 bytes: 1, we are sewing this.
- 2 bytes: Color, color index. Index of new color.
- 2 bytes: 2, length two.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 byes: X, current position X.
- 2 bytes: Y, current position Y.
- 2 bytes 0x8001, 01 80. End Segment (We invoked a color change, and then a sewable event that went nowhere, to make sure the color is established.)
- 2 bytes, 0, we are not stitching.
- 2 bytes, Color, whatever color we're on.
- 2 bytes, length, the number of stitches in this jump, including start and end (minimum 2).
- NN bytes, X position, Y position (relative to the position given to the StitchGroup description).
- 2 bytes 0x8001, 01 80. End Segment
- 2 bytes, 1, we are stitching.
- 2 bytes, Color, whatever color we're on.
- 2 bytes, length, the number of stitches in this block, including start and end (minimum 2).
- NN bytes, X position, Y position (relative to the position given to the StitchGroup description).
- 2 bytes 0x8001, 01 80. End Segment
We now write the color change log.
- 2 bytes: Number of color changes
For each color change:
- 2 bytes: Section at which this change occurred. (Note this must account for the initialization and the padding sections we added.
- 2 bytes: Color Change, old index value.
Continue to Write PEC Elements.
File should end with .pec Write "#PEC0001" Continue to Write PEC Elements.
In accordance to hacking PES files document: Write #PES0001 Write 0x1C 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Write PEC Elements.
Write "LA:" Write name of file, this is typically truncated at 8. Write some more stuff.
1 copy of blank. N copies of blank. (where N is the number of colors used).
Where blank is defined as: (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xF0, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0F, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0xF0, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
PES format
- PES format overview
- PES section
- PEC section
- PEC thread palette
- Write PES
- Write PEC
- Unknowns