added publishing metadata and seperated project readmes
Some checks failed
CI / Lint and Test (pull_request) Successful in 37s
CI / Version Check (pull_request) Failing after 3s

This commit is contained in:
2026-03-30 00:58:48 +02:00
parent de363276b2
commit ad8738e6dd
5 changed files with 187 additions and 19 deletions

View File

@@ -2,6 +2,13 @@
name = "rustitch"
version = "0.1.1"
edition = "2024"
description = "PES embroidery file parser and thumbnail renderer"
license = "MIT"
repository = "https://git.narl.io/nvrl/stitch-peek-rs"
authors = ["Nils Pukropp <nils@narl.io>"]
keywords = ["embroidery", "pes", "thumbnail", "stitch"]
categories = ["graphics", "parser-implementations"]
readme = "README.md"
[dependencies]
thiserror = "2"

74
rustitch/README.md Normal file
View File

@@ -0,0 +1,74 @@
# rustitch
A Rust library for parsing **PES embroidery files** and rendering stitch data to images.
Part of the [stitch-peek-rs](https://git.narl.io/nvrl/stitch-peek-rs) project.
## Usage
Add `rustitch` to your `Cargo.toml`:
```toml
[dependencies]
rustitch = "0.1"
```
### Generate a thumbnail
```rust
let pes_data = std::fs::read("design.pes")?;
let png_bytes = rustitch::thumbnail(&pes_data, 256)?;
std::fs::write("preview.png", &png_bytes)?;
```
### Parse and inspect a design
```rust
use rustitch::pes::{self, StitchCommand};
let data = std::fs::read("design.pes")?;
let design = pes::parse(&data)?;
println!("PES version: {}", std::str::from_utf8(&design.header.version).unwrap());
println!("Label: {}", design.pec_header.label);
println!("Colors: {}", design.pec_header.color_count);
let stitch_count = design.commands.iter()
.filter(|c| matches!(c, StitchCommand::Stitch { .. }))
.count();
println!("Stitches: {stitch_count}");
```
### Resolve and render manually
```rust
use rustitch::pes;
let data = std::fs::read("design.pes")?;
let design = pes::parse(&data)?;
let resolved = pes::resolve(&design)?;
println!("Segments: {}", resolved.segments.len());
println!("Bounding box: ({}, {}) to ({}, {})",
resolved.bounds.min_x, resolved.bounds.min_y,
resolved.bounds.max_x, resolved.bounds.max_y);
let png_bytes = rustitch::render_thumbnail(&resolved, 512)?;
std::fs::write("large_preview.png", &png_bytes)?;
```
## Supported formats
**PES** (Brother PE-Design) embroidery files, versions 1 through 10. The PEC section containing stitch data is consistent across versions.
## 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
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
## License
MIT