Embroidery machines still rely on compact binary stitch formats designed decades ago. Two of the most common formats in home and commercial shops are Brother .PES (#PES0001) and Tajima .DST.
When we built the ImageToPES Free .PES & .DST Stitch Viewer and Rust digitization core at ImageToPES, we ran into several subtle binary parsing edge cases worth documenting for anyone working with stitch files.
1. Brother #PES0001 Header vs Embedded PEC Block
A .PES file starts with an 8-byte ASCII magic signature (#PES0001 through #PES0060) followed by a 32-bit little-endian offset pointing directly to the embedded PEC section. Most Brother machines actually read the PEC stitch block rather than the higher-level PES object tree:
- Normal stitches fit in 1 byte per axis (
-63to+63in 0.1 mm units). - Jump and trim stitches use a 12-bit signed displacement packed across 2 bytes when the high bit (
0x80) is set. - Color changes are signaled by the two-byte sequence
0xFE 0xB0followed by a control byte.
Validating that the PEC offset stays within file bounds and that stitch coordinates remain inside the target hoop prevents corrupted files from stalling a machine.
2. Tajima .DST Balanced-Ternary Displacement Encoding
Unlike .PES, a .DST file begins with a fixed 512-byte ASCII header containing metadata tags (LA:, ST:, CO:, +X:, -X:, +Y:, -Y:), followed by 3-byte stitch records. Each 3-byte triplet encodes dx and dy using balanced ternary (±1, ±3, ±9, ±27, ±81 in 0.1 mm increments) distributed across specific bits of all three bytes, with flag bits indicating normal stitch, jump, color stop, or end-of-file (0x00 0x00 0xF3).
Because .DST stores no RGB thread palette—only color-stop indices—a browser previewer needs either a deterministic fallback palette or user-editable thread colors.
3. Rendering Real-Time 3D Thread Previews in HTML5 Canvas
Once decoded into (x, y, op, colorIndex) trajectories in Rust/WASM, rendering realistic stitch previews on an HTML5 Canvas comes down to:
- Computing hoop bounding boxes and stitch density heatmaps to catch overly dense clusters before stitching.
- Drawing directional highlight/shadow passes per stitch segment so satin fills and running stitches look like physical thread rather than flat 1px lines.
- Supporting frame-by-frame playback so makers can inspect underlay order and trim jumps before exporting to
.PES,.DST,.JEF,.EXP, or.VP3.
If you want to inspect an existing .PES or .DST file's stitch count, hoop bounds, and trajectory directly in your browser without installing desktop software, try the free online viewer at imagetopes.com/pes-file-viewer.