fixed rotation issues + updated readme
All checks were successful
CI / Lint and Test (pull_request) Successful in 38s
CI / Version Check (pull_request) Successful in 3s

This commit is contained in:
2026-03-31 12:41:36 +02:00
parent 08aafaa3c3
commit 473da90b01
9 changed files with 112 additions and 50 deletions

View File

@@ -4,7 +4,9 @@
[![docs.rs](https://img.shields.io/docsrs/rustitch)](https://docs.rs/rustitch)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](../LICENSE)
A Rust library for parsing **PES embroidery files** and rendering stitch data to images.
A Rust library for parsing **embroidery files** and rendering stitch data to images.
Supported formats: **PES**, **DST**, **EXP**, **JEF**, **VP3**
Part of the [stitch-peek-rs](https://git.narl.io/nvrl/stitch-peek-rs) project.
@@ -14,18 +16,24 @@ Add `rustitch` to your `Cargo.toml`:
```toml
[dependencies]
rustitch = "0.1"
rustitch = "0.2"
```
### Generate a thumbnail
```rust
// PES files (backward-compatible API)
let pes_data = std::fs::read("design.pes")?;
let png_bytes = rustitch::thumbnail(&pes_data, 256)?;
std::fs::write("preview.png", &png_bytes)?;
// Any supported format
let dst_data = std::fs::read("pattern.dst")?;
let png_bytes = rustitch::thumbnail_format(&dst_data, 256, rustitch::Format::Dst)?;
std::fs::write("preview.png", &png_bytes)?;
```
### Parse and inspect a design
### Parse and inspect a PES design
```rust
use rustitch::pes::{self, StitchCommand};
@@ -61,15 +69,39 @@ let png_bytes = rustitch::render_thumbnail(&resolved, 512)?;
std::fs::write("large_preview.png", &png_bytes)?;
```
### Format detection
```rust
use rustitch::format::{self, Format};
use std::path::Path;
// Detect from file extension
let fmt = format::detect_from_extension(Path::new("design.jef"));
assert_eq!(fmt, Some(Format::Jef));
// Detect from file content (magic bytes)
let data = std::fs::read("design.pes")?;
let fmt = format::detect_from_bytes(&data);
assert_eq!(fmt, Some(Format::Pes));
```
## Supported formats
**PES** (Brother PE-Design) embroidery files, versions 1 through 10. The PEC section containing stitch data is consistent across versions.
| Format | Manufacturer | Colors | Notes |
|--------|-------------|--------|-------|
| **PES** | Brother PE-Design | Embedded (PEC palette) | Versions 1-10 |
| **DST** | Tajima | Default palette | 3-byte bit-packed records |
| **EXP** | Melco/Bernina | Default palette | Simple 2-byte encoding |
| **JEF** | Janome | Embedded (Janome palette) | Structured header with color table |
| **VP3** | Pfaff/Viking | Embedded (RGB) | Hierarchical format with per-section colors |
Formats without embedded color info (DST, EXP) use a default palette of 12 high-contrast colors, cycling on each color change.
## How it works
1. **Parse** the PES binary header to locate the PEC section
2. **Decode** the PEC stitch byte stream (7-bit and 12-bit encoded relative movements, jumps, trims, color changes)
3. **Resolve** relative movements into absolute coordinate segments grouped by thread color, using the 65-color Brother PEC palette
1. **Detect** the file format from magic bytes or extension
2. **Parse** the format-specific binary encoding into a common `StitchCommand` stream (stitch, jump, trim, color change, end)
3. **Resolve** relative movements into absolute coordinate segments grouped by thread color
4. **Render** anti-aliased line segments with [tiny-skia](https://github.com/nickel-org/tiny-skia), scaled to fit the requested size
5. **Encode** as PNG with proper alpha handling