Compare commits
12 Commits
ff6f279ff5
..
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| fc2abb9524 | |||
| 7ae9abd338 | |||
| 0a6448c68a | |||
| ea74aaa666 | |||
| ad8738e6dd | |||
| 4e05428d83 | |||
| de363276b2 | |||
| 1f952b8e03 | |||
| b155830118 | |||
| 27b97a69a7 | |||
| a74d504bca | |||
| e98ff143a1 |
@@ -22,7 +22,7 @@ jobs:
|
|||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
- name: Install packaging tools
|
- name: Install packaging tools
|
||||||
run: sudo apt-get update && sudo apt-get install -y dpkg-dev
|
run: apt-get update && apt-get install -y dpkg-dev
|
||||||
|
|
||||||
- name: Get Version
|
- name: Get Version
|
||||||
id: get_version
|
id: get_version
|
||||||
|
|||||||
Generated
+10
-10
@@ -78,9 +78,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "2.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytemuck"
|
name = "bytemuck"
|
||||||
@@ -204,9 +204,9 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "png"
|
name = "png"
|
||||||
version = "0.17.16"
|
version = "0.18.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526"
|
checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
@@ -235,7 +235,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustitch"
|
name = "rustitch"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"png",
|
"png",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
@@ -250,7 +250,7 @@ checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stitch-peek"
|
name = "stitch-peek"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@@ -302,9 +302,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiny-skia"
|
name = "tiny-skia"
|
||||||
version = "0.11.4"
|
version = "0.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab"
|
checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
@@ -317,9 +317,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiny-skia-path"
|
name = "tiny-skia-path"
|
||||||
version = "0.11.4"
|
version = "0.12.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93"
|
checksum = "edca365c3faccca67d06593c5980fa6c57687de727a03131735bb85f01fdeeb9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
# stitch-peek
|
# stitch-peek-rs
|
||||||
|
|
||||||
|
[](https://git.narl.io/nvrl/stitch-peek-rs/actions/workflows/ci.yml)
|
||||||
|
[](https://crates.io/crates/rustitch)
|
||||||
|
[](https://crates.io/crates/stitch-peek)
|
||||||
|
[](https://docs.rs/rustitch)
|
||||||
|
[](LICENSE)
|
||||||
|
|
||||||
A Nautilus/GNOME thumbnailer for **PES embroidery files**. Browse your embroidery designs in the file manager with automatic thumbnail previews.
|
A Nautilus/GNOME thumbnailer for **PES embroidery files**. Browse your embroidery designs in the file manager with automatic thumbnail previews.
|
||||||
|
|
||||||
Built as two crates:
|
Built as two crates:
|
||||||
|
|
||||||
- **rustitch** -- library for parsing PES files and rendering stitch data to images
|
| Crate | Description |
|
||||||
- **stitch-peek** -- CLI thumbnailer that integrates with GNOME/Nautilus via the freedesktop thumbnail spec
|
|-------|-------------|
|
||||||
|
| [**rustitch**](rustitch/) | Library for parsing PES files and rendering stitch data to images |
|
||||||
|
| [**stitch-peek**](stitch-peek/) | CLI thumbnailer that integrates with GNOME/Nautilus |
|
||||||
|
|
||||||
<!-- TODO: Add screenshot of Nautilus showing PES thumbnails -->
|
<!-- TODO: Add screenshot of Nautilus showing PES thumbnails -->
|
||||||
|
|
||||||
@@ -13,7 +21,7 @@ Built as two crates:
|
|||||||
|
|
||||||
### From .deb (Debian/Ubuntu)
|
### From .deb (Debian/Ubuntu)
|
||||||
|
|
||||||
Download the latest `.deb` from the [Releases](../../releases) page:
|
Download the latest `.deb` from the [Releases](https://git.narl.io/nvrl/stitch-peek-rs/releases) page:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo dpkg -i stitch-peek_*_amd64.deb
|
sudo dpkg -i stitch-peek_*_amd64.deb
|
||||||
@@ -25,12 +33,27 @@ This installs the binary, thumbnailer entry, and MIME type definition. Restart N
|
|||||||
nautilus -q
|
nautilus -q
|
||||||
```
|
```
|
||||||
|
|
||||||
### From source
|
### From crates.io
|
||||||
|
|
||||||
Requires Rust 1.70+.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/YOUR_USER/stitch-peek-rs.git
|
cargo install stitch-peek
|
||||||
|
```
|
||||||
|
|
||||||
|
Then install the data files:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo install -Dm644 data/stitch-peek.thumbnailer /usr/share/thumbnailers/stitch-peek.thumbnailer
|
||||||
|
sudo install -Dm644 data/pes.xml /usr/share/mime/packages/pes.xml
|
||||||
|
sudo update-mime-database /usr/share/mime
|
||||||
|
nautilus -q
|
||||||
|
```
|
||||||
|
|
||||||
|
### From source
|
||||||
|
|
||||||
|
Requires Rust 1.85+.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://git.narl.io/nvrl/stitch-peek-rs.git
|
||||||
cd stitch-peek-rs
|
cd stitch-peek-rs
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|
||||||
@@ -67,7 +90,7 @@ Add `rustitch` to your project:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustitch = { git = "https://github.com/YOUR_USER/stitch-peek-rs.git" }
|
rustitch = "0.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
@@ -76,17 +99,11 @@ let png_bytes = rustitch::thumbnail(&pes_data, 256)?;
|
|||||||
std::fs::write("preview.png", &png_bytes)?;
|
std::fs::write("preview.png", &png_bytes)?;
|
||||||
```
|
```
|
||||||
|
|
||||||
## How it works
|
See the [rustitch README](rustitch/README.md) for more API examples.
|
||||||
|
|
||||||
1. **Parse** the PES binary format -- extract the PEC section containing stitch commands and thread color indices
|
|
||||||
2. **Decode** the stitch byte stream into movement commands (stitches, jumps, trims, color changes)
|
|
||||||
3. **Resolve** relative movements into absolute coordinates grouped by thread color
|
|
||||||
4. **Render** anti-aliased line segments onto a transparent canvas using [tiny-skia](https://github.com/nickel-org/tiny-skia), scaled to fit the requested thumbnail size
|
|
||||||
5. **Encode** the result as a PNG image
|
|
||||||
|
|
||||||
## Supported formats
|
## Supported formats
|
||||||
|
|
||||||
Currently supports **PES** (Brother PE-Design) embroidery files, versions 1 through 6. The PEC section -- which contains the actual stitch data -- is consistent across versions.
|
**PES** (Brother PE-Design) embroidery files, versions 1 through 10. The PEC section containing stitch data is consistent across versions.
|
||||||
|
|
||||||
## Project structure
|
## Project structure
|
||||||
|
|
||||||
@@ -128,4 +145,4 @@ Pull requests must bump the version in `stitch-peek/Cargo.toml` -- CI will rejec
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
[MIT](LICENSE)
|
||||||
|
|||||||
+14
-4
@@ -1,9 +1,19 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rustitch"
|
name = "rustitch"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
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]
|
[dependencies]
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
tiny-skia = "0.11"
|
tiny-skia = "0.12"
|
||||||
png = "0.17"
|
png = "0.18"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
png = "0.18"
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# rustitch
|
||||||
|
|
||||||
|
[](https://crates.io/crates/rustitch)
|
||||||
|
[](https://docs.rs/rustitch)
|
||||||
|
[](../LICENSE)
|
||||||
|
|
||||||
|
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
|
||||||
+65
-65
@@ -1,69 +1,69 @@
|
|||||||
/// Brother PEC thread color palette (65 entries).
|
/// Brother PEC thread color palette (65 entries).
|
||||||
/// Index 0 is a fallback; indices 1–64 correspond to standard Brother thread colors.
|
/// Index 0 is a fallback; indices 1–64 correspond to standard Brother thread colors.
|
||||||
pub const PEC_PALETTE: [(u8, u8, u8); 65] = [
|
pub const PEC_PALETTE: [(u8, u8, u8); 65] = [
|
||||||
(0, 0, 0), // 0: Unknown
|
(0, 0, 0), // 0: Unknown
|
||||||
(14, 31, 124), // 1: Prussian Blue
|
(14, 31, 124), // 1: Prussian Blue
|
||||||
(10, 85, 163), // 2: Blue
|
(10, 85, 163), // 2: Blue
|
||||||
(0, 135, 119), // 3: Teal Green
|
(0, 135, 119), // 3: Teal Green
|
||||||
(75, 107, 175), // 4: Cornflower Blue
|
(75, 107, 175), // 4: Cornflower Blue
|
||||||
(237, 23, 31), // 5: Red
|
(237, 23, 31), // 5: Red
|
||||||
(209, 92, 0), // 6: Reddish Brown
|
(209, 92, 0), // 6: Reddish Brown
|
||||||
(145, 54, 151), // 7: Magenta
|
(145, 54, 151), // 7: Magenta
|
||||||
(228, 154, 203), // 8: Light Lilac
|
(228, 154, 203), // 8: Light Lilac
|
||||||
(145, 95, 172), // 9: Lilac
|
(145, 95, 172), // 9: Lilac
|
||||||
(158, 214, 125), // 10: Mint Green
|
(158, 214, 125), // 10: Mint Green
|
||||||
(232, 169, 0), // 11: Deep Gold
|
(232, 169, 0), // 11: Deep Gold
|
||||||
(254, 186, 53), // 12: Orange
|
(254, 186, 53), // 12: Orange
|
||||||
(255, 255, 0), // 13: Yellow
|
(255, 255, 0), // 13: Yellow
|
||||||
(112, 188, 31), // 14: Lime Green
|
(112, 188, 31), // 14: Lime Green
|
||||||
(186, 152, 0), // 15: Brass
|
(186, 152, 0), // 15: Brass
|
||||||
(168, 168, 168), // 16: Silver
|
(168, 168, 168), // 16: Silver
|
||||||
(125, 111, 0), // 17: Russet Brown
|
(125, 111, 0), // 17: Russet Brown
|
||||||
(255, 255, 179), // 18: Cream Brown
|
(255, 255, 179), // 18: Cream Brown
|
||||||
(79, 85, 86), // 19: Pewter
|
(79, 85, 86), // 19: Pewter
|
||||||
(0, 0, 0), // 20: Black
|
(0, 0, 0), // 20: Black
|
||||||
(11, 61, 145), // 21: Ultramarine
|
(11, 61, 145), // 21: Ultramarine
|
||||||
(119, 1, 118), // 22: Royal Purple
|
(119, 1, 118), // 22: Royal Purple
|
||||||
(41, 49, 51), // 23: Dark Gray
|
(41, 49, 51), // 23: Dark Gray
|
||||||
(42, 19, 1), // 24: Dark Brown
|
(42, 19, 1), // 24: Dark Brown
|
||||||
(246, 74, 138), // 25: Deep Rose
|
(246, 74, 138), // 25: Deep Rose
|
||||||
(178, 118, 36), // 26: Light Brown
|
(178, 118, 36), // 26: Light Brown
|
||||||
(252, 187, 197), // 27: Salmon Pink
|
(252, 187, 197), // 27: Salmon Pink
|
||||||
(254, 55, 15), // 28: Vermilion
|
(254, 55, 15), // 28: Vermilion
|
||||||
(240, 240, 240), // 29: White
|
(240, 240, 240), // 29: White
|
||||||
(106, 28, 138), // 30: Violet
|
(106, 28, 138), // 30: Violet
|
||||||
(168, 221, 196), // 31: Seacrest
|
(168, 221, 196), // 31: Seacrest
|
||||||
(37, 132, 187), // 32: Sky Blue
|
(37, 132, 187), // 32: Sky Blue
|
||||||
(254, 179, 67), // 33: Pumpkin
|
(254, 179, 67), // 33: Pumpkin
|
||||||
(255, 243, 107), // 34: Cream Yellow
|
(255, 243, 107), // 34: Cream Yellow
|
||||||
(208, 166, 96), // 35: Khaki
|
(208, 166, 96), // 35: Khaki
|
||||||
(209, 84, 0), // 36: Clay Brown
|
(209, 84, 0), // 36: Clay Brown
|
||||||
(102, 186, 73), // 37: Leaf Green
|
(102, 186, 73), // 37: Leaf Green
|
||||||
(19, 74, 70), // 38: Peacock Blue
|
(19, 74, 70), // 38: Peacock Blue
|
||||||
(135, 135, 135), // 39: Gray
|
(135, 135, 135), // 39: Gray
|
||||||
(216, 204, 198), // 40: Warm Gray
|
(216, 204, 198), // 40: Warm Gray
|
||||||
(67, 86, 7), // 41: Dark Olive
|
(67, 86, 7), // 41: Dark Olive
|
||||||
(253, 217, 222), // 42: Flesh Pink
|
(253, 217, 222), // 42: Flesh Pink
|
||||||
(249, 147, 188), // 43: Pink
|
(249, 147, 188), // 43: Pink
|
||||||
(0, 56, 34), // 44: Deep Green
|
(0, 56, 34), // 44: Deep Green
|
||||||
(178, 175, 212), // 45: Lavender
|
(178, 175, 212), // 45: Lavender
|
||||||
(104, 106, 176), // 46: Wisteria Violet
|
(104, 106, 176), // 46: Wisteria Violet
|
||||||
(239, 227, 185), // 47: Beige
|
(239, 227, 185), // 47: Beige
|
||||||
(247, 56, 102), // 48: Carmine
|
(247, 56, 102), // 48: Carmine
|
||||||
(181, 75, 100), // 49: Amber Red
|
(181, 75, 100), // 49: Amber Red
|
||||||
(19, 43, 26), // 50: Olive Green
|
(19, 43, 26), // 50: Olive Green
|
||||||
(199, 1, 86), // 51: Dark Fuchsia
|
(199, 1, 86), // 51: Dark Fuchsia
|
||||||
(254, 158, 50), // 52: Tangerine
|
(254, 158, 50), // 52: Tangerine
|
||||||
(168, 222, 235), // 53: Light Blue
|
(168, 222, 235), // 53: Light Blue
|
||||||
(0, 103, 62), // 54: Emerald Green
|
(0, 103, 62), // 54: Emerald Green
|
||||||
(78, 41, 144), // 55: Purple
|
(78, 41, 144), // 55: Purple
|
||||||
(47, 126, 32), // 56: Moss Green
|
(47, 126, 32), // 56: Moss Green
|
||||||
(255, 204, 204), // 57: Flesh Pink
|
(255, 204, 204), // 57: Flesh Pink
|
||||||
(255, 217, 17), // 58: Harvest Gold
|
(255, 217, 17), // 58: Harvest Gold
|
||||||
(9, 91, 166), // 59: Electric Blue
|
(9, 91, 166), // 59: Electric Blue
|
||||||
(240, 249, 112), // 60: Lemon Yellow
|
(240, 249, 112), // 60: Lemon Yellow
|
||||||
(227, 243, 91), // 61: Fresh Green
|
(227, 243, 91), // 61: Fresh Green
|
||||||
(255, 153, 0), // 62: Orange
|
(255, 153, 0), // 62: Orange
|
||||||
(255, 240, 141), // 63: Cream Yellow
|
(255, 240, 141), // 63: Cream Yellow
|
||||||
(255, 200, 200), // 64: Applique
|
(255, 200, 200), // 64: Applique
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -173,11 +173,7 @@ fn decode_coordinate(data: &[u8], pos: usize) -> Result<(i16, u8, usize), Error>
|
|||||||
Ok((value, flags, 2))
|
Ok((value, flags, 2))
|
||||||
} else {
|
} else {
|
||||||
// 7-bit encoding (1 byte)
|
// 7-bit encoding (1 byte)
|
||||||
let value = if b > 0x3F {
|
let value = if b > 0x3F { b as i16 - 0x80 } else { b as i16 };
|
||||||
b as i16 - 0x80
|
|
||||||
} else {
|
|
||||||
b as i16
|
|
||||||
};
|
|
||||||
Ok((value, 0, 1))
|
Ok((value, 0, 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,201 @@
|
|||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
use rustitch::pes::{self, StitchCommand};
|
||||||
|
|
||||||
|
const GNOME_BARFS: &[u8] = include_bytes!("fixtures/JLS_Gnome Barfs.PES");
|
||||||
|
const URSULA_ONE: &[u8] = include_bytes!("fixtures/UrsulaOne.PES");
|
||||||
|
const UFRONT: &[u8] = include_bytes!("fixtures/UFront.PES");
|
||||||
|
|
||||||
|
// -- Header parsing ----------------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_header_gnome_barfs() {
|
||||||
|
let design = pes::parse(GNOME_BARFS).unwrap();
|
||||||
|
assert_eq!(&design.header.version, b"0100");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_header_ursula_one() {
|
||||||
|
let design = pes::parse(URSULA_ONE).unwrap();
|
||||||
|
assert_eq!(&design.header.version, b"0060");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_header_ufront() {
|
||||||
|
let design = pes::parse(UFRONT).unwrap();
|
||||||
|
assert_eq!(&design.header.version, b"0060");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- PEC color table ---------------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gnome_barfs_has_colors() {
|
||||||
|
let design = pes::parse(GNOME_BARFS).unwrap();
|
||||||
|
assert!(
|
||||||
|
design.pec_header.color_count > 0,
|
||||||
|
"expected at least one color"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
design.pec_header.color_indices.len(),
|
||||||
|
design.pec_header.color_count as usize
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ursula_one_has_colors() {
|
||||||
|
let design = pes::parse(URSULA_ONE).unwrap();
|
||||||
|
assert!(design.pec_header.color_count > 0);
|
||||||
|
// All color indices should be valid palette entries (0..65)
|
||||||
|
for &idx in &design.pec_header.color_indices {
|
||||||
|
assert!(
|
||||||
|
(idx as usize) < pes::PEC_PALETTE.len(),
|
||||||
|
"color index {idx} out of palette range"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Stitch commands ---------------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gnome_barfs_commands_end_properly() {
|
||||||
|
let design = pes::parse(GNOME_BARFS).unwrap();
|
||||||
|
let last = design.commands.last().unwrap();
|
||||||
|
assert!(
|
||||||
|
matches!(last, StitchCommand::End),
|
||||||
|
"expected End command as last, got {last:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ursula_one_commands_end_properly() {
|
||||||
|
let design = pes::parse(URSULA_ONE).unwrap();
|
||||||
|
let last = design.commands.last().unwrap();
|
||||||
|
assert!(
|
||||||
|
matches!(last, StitchCommand::End),
|
||||||
|
"expected End command as last, got {last:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ufront_has_stitches() {
|
||||||
|
let design = pes::parse(UFRONT).unwrap();
|
||||||
|
let stitch_count = design
|
||||||
|
.commands
|
||||||
|
.iter()
|
||||||
|
.filter(|c| matches!(c, StitchCommand::Stitch { .. }))
|
||||||
|
.count();
|
||||||
|
assert!(
|
||||||
|
stitch_count > 100,
|
||||||
|
"expected many stitches, got {stitch_count}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gnome_barfs_has_color_changes() {
|
||||||
|
let design = pes::parse(GNOME_BARFS).unwrap();
|
||||||
|
let changes = design
|
||||||
|
.commands
|
||||||
|
.iter()
|
||||||
|
.filter(|c| matches!(c, StitchCommand::ColorChange))
|
||||||
|
.count();
|
||||||
|
// Multi-color design should have at least one color change
|
||||||
|
assert!(changes > 0, "expected color changes, got none");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Resolve to segments -----------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resolve_gnome_barfs() {
|
||||||
|
let design = pes::parse(GNOME_BARFS).unwrap();
|
||||||
|
let resolved = pes::resolve(&design).unwrap();
|
||||||
|
|
||||||
|
assert!(!resolved.segments.is_empty());
|
||||||
|
assert!(!resolved.colors.is_empty());
|
||||||
|
|
||||||
|
// Bounding box should be non-degenerate
|
||||||
|
assert!(resolved.bounds.max_x > resolved.bounds.min_x);
|
||||||
|
assert!(resolved.bounds.max_y > resolved.bounds.min_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resolve_ursula_one() {
|
||||||
|
let design = pes::parse(URSULA_ONE).unwrap();
|
||||||
|
let resolved = pes::resolve(&design).unwrap();
|
||||||
|
|
||||||
|
assert!(!resolved.segments.is_empty());
|
||||||
|
assert!(resolved.bounds.max_x > resolved.bounds.min_x);
|
||||||
|
assert!(resolved.bounds.max_y > resolved.bounds.min_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resolve_ufront() {
|
||||||
|
let design = pes::parse(UFRONT).unwrap();
|
||||||
|
let resolved = pes::resolve(&design).unwrap();
|
||||||
|
|
||||||
|
assert!(!resolved.segments.is_empty());
|
||||||
|
|
||||||
|
// All segment color indices should be within the resolved color list
|
||||||
|
let max_ci = resolved
|
||||||
|
.segments
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.color_index)
|
||||||
|
.max()
|
||||||
|
.unwrap();
|
||||||
|
assert!(
|
||||||
|
max_ci < resolved.colors.len(),
|
||||||
|
"segment references color {max_ci} but only {} colors resolved",
|
||||||
|
resolved.colors.len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Full thumbnail pipeline -------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn thumbnail_gnome_barfs_128() {
|
||||||
|
let png = rustitch::thumbnail(GNOME_BARFS, 128).unwrap();
|
||||||
|
assert_png_dimensions(&png, 128, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn thumbnail_ursula_one_256() {
|
||||||
|
let png = rustitch::thumbnail(URSULA_ONE, 256).unwrap();
|
||||||
|
assert_png_dimensions(&png, 256, 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn thumbnail_ufront_64() {
|
||||||
|
let png = rustitch::thumbnail(UFRONT, 64).unwrap();
|
||||||
|
assert_png_dimensions(&png, 64, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn thumbnail_gnome_barfs_not_blank() {
|
||||||
|
let png = rustitch::thumbnail(GNOME_BARFS, 128).unwrap();
|
||||||
|
let pixels = decode_png_pixels(&png);
|
||||||
|
// At least some pixels should have non-zero alpha (not fully transparent)
|
||||||
|
let opaque_count = pixels.chunks_exact(4).filter(|px| px[3] > 0).count();
|
||||||
|
assert!(
|
||||||
|
opaque_count > 100,
|
||||||
|
"thumbnail looks blank, only {opaque_count} non-transparent pixels"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Helpers -----------------------------------------------------------------
|
||||||
|
|
||||||
|
fn assert_png_dimensions(png_data: &[u8], expected_w: u32, expected_h: u32) {
|
||||||
|
let decoder = png::Decoder::new(Cursor::new(png_data));
|
||||||
|
let reader = decoder.read_info().unwrap();
|
||||||
|
let info = reader.info();
|
||||||
|
assert_eq!(info.width, expected_w, "unexpected PNG width");
|
||||||
|
assert_eq!(info.height, expected_h, "unexpected PNG height");
|
||||||
|
assert_eq!(info.color_type, png::ColorType::Rgba);
|
||||||
|
assert_eq!(info.bit_depth, png::BitDepth::Eight);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decode_png_pixels(png_data: &[u8]) -> Vec<u8> {
|
||||||
|
let decoder = png::Decoder::new(Cursor::new(png_data));
|
||||||
|
let mut reader = decoder.read_info().unwrap();
|
||||||
|
let mut buf = vec![0u8; reader.output_buffer_size().unwrap()];
|
||||||
|
reader.next_frame(&mut buf).unwrap();
|
||||||
|
buf
|
||||||
|
}
|
||||||
+10
-3
@@ -1,9 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "stitch-peek"
|
name = "stitch-peek"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
description = "Nautilus thumbnail generator for PES embroidery files"
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://git.narl.io/nvrl/stitch-peek-rs"
|
||||||
|
authors = ["Nils Pukropp <nils@narl.io>"]
|
||||||
|
keywords = ["embroidery", "pes", "thumbnailer", "nautilus"]
|
||||||
|
categories = ["graphics", "command-line-utilities"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustitch = { path = "../rustitch" }
|
rustitch = { version = "0.1.1", path = "../rustitch" }
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# stitch-peek
|
||||||
|
|
||||||
|
[](https://crates.io/crates/stitch-peek)
|
||||||
|
[](../LICENSE)
|
||||||
|
|
||||||
|
A CLI tool and **Nautilus/GNOME thumbnailer** for PES embroidery files. Generates PNG previews of embroidery designs directly in your file manager.
|
||||||
|
|
||||||
|
Part of the [stitch-peek-rs](https://git.narl.io/nvrl/stitch-peek-rs) project. Uses [rustitch](https://crates.io/crates/rustitch) for PES parsing and rendering.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### From .deb (Debian/Ubuntu)
|
||||||
|
|
||||||
|
Download the latest `.deb` from the [Releases](https://git.narl.io/nvrl/stitch-peek-rs/releases) page:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo dpkg -i stitch-peek_*_amd64.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
### From crates.io
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo install stitch-peek
|
||||||
|
```
|
||||||
|
|
||||||
|
Then install the thumbnailer and MIME type files manually:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo install -Dm644 data/stitch-peek.thumbnailer /usr/share/thumbnailers/stitch-peek.thumbnailer
|
||||||
|
sudo install -Dm644 data/pes.xml /usr/share/mime/packages/pes.xml
|
||||||
|
sudo update-mime-database /usr/share/mime
|
||||||
|
```
|
||||||
|
|
||||||
|
### From source
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://git.narl.io/nvrl/stitch-peek-rs.git
|
||||||
|
cd stitch-peek-rs
|
||||||
|
cargo install --path stitch-peek
|
||||||
|
```
|
||||||
|
|
||||||
|
After installing, restart Nautilus to pick up the thumbnailer:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nautilus -q
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### As a thumbnailer
|
||||||
|
|
||||||
|
Once installed with the `.thumbnailer` file in place, Nautilus automatically generates thumbnails for `.pes` files. No manual action needed.
|
||||||
|
|
||||||
|
### Standalone CLI
|
||||||
|
|
||||||
|
```sh
|
||||||
|
stitch-peek -i design.pes -o preview.png -s 256
|
||||||
|
```
|
||||||
|
|
||||||
|
| Flag | Description | Default |
|
||||||
|
|------|-------------|---------|
|
||||||
|
| `-i` | Input PES file | required |
|
||||||
|
| `-o` | Output PNG path | required |
|
||||||
|
| `-s` | Thumbnail size (pixels) | 128 |
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
The tool follows the [freedesktop thumbnail specification](https://specifications.freedesktop.org/thumbnail/latest/). Nautilus calls it with an input file, output path, and requested size. It parses the PES file, renders the stitch pattern as anti-aliased colored lines on a transparent background, and writes a PNG.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
@@ -24,8 +24,8 @@ fn main() -> Result<()> {
|
|||||||
let data = fs::read(&args.input)
|
let data = fs::read(&args.input)
|
||||||
.with_context(|| format!("failed to read {}", args.input.display()))?;
|
.with_context(|| format!("failed to read {}", args.input.display()))?;
|
||||||
|
|
||||||
let png = rustitch::thumbnail(&data, args.size)
|
let png =
|
||||||
.with_context(|| "failed to generate thumbnail")?;
|
rustitch::thumbnail(&data, args.size).with_context(|| "failed to generate thumbnail")?;
|
||||||
|
|
||||||
fs::write(&args.output, &png)
|
fs::write(&args.output, &png)
|
||||||
.with_context(|| format!("failed to write {}", args.output.display()))?;
|
.with_context(|| format!("failed to write {}", args.output.display()))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user