9 Commits

Author SHA1 Message Date
nvrl 4e05428d83 Merge pull request 'added testfiles' (#4) from release/0.1.1 into main
Release / Build and Release (push) Successful in 35s
Reviewed-on: #4
2026-03-30 00:48:52 +02:00
nvrl de363276b2 version bump, cursor implementation + dependencies upgrade
CI / Lint and Test (pull_request) Successful in 36s
CI / Version Check (pull_request) Successful in 4s
2026-03-30 00:48:03 +02:00
nvrl 1f952b8e03 added testfiles
CI / Lint and Test (pull_request) Successful in 37s
CI / Version Check (pull_request) Failing after 3s
2026-03-30 00:44:16 +02:00
nvrl b155830118 Merge pull request 'fixed tooling in ci' (#3) from release/0.1.0 into main
Release / Build and Release (push) Successful in 37s
Reviewed-on: #3
2026-03-30 00:32:41 +02:00
nvrl 27b97a69a7 fixed tooling in ci
CI / Lint and Test (pull_request) Successful in 36s
CI / Version Check (pull_request) Failing after 3s
2026-03-30 00:32:24 +02:00
nvrl a74d504bca Merge pull request 'cargo fmt' (#2) from release/0.1.0 into main
Release / Build and Release (push) Failing after 15s
Reviewed-on: #2
2026-03-30 00:31:22 +02:00
nvrl e98ff143a1 cargo fmt
CI / Lint and Test (pull_request) Successful in 37s
CI / Version Check (pull_request) Failing after 3s
2026-03-30 00:30:51 +02:00
nvrl ff6f279ff5 Merge pull request 'release/0.1.0' (#1) from release/0.1.0 into main
Release / Build and Release (push) Failing after 19s
Reviewed-on: #1
2026-03-30 00:29:56 +02:00
nvrl ecc7ef519f fixed workflow
CI / Lint and Test (pull_request) Failing after 53s
CI / Version Check (pull_request) Failing after 3s
2026-03-30 00:29:38 +02:00
12 changed files with 378 additions and 162 deletions
+29 -35
View File
@@ -2,30 +2,29 @@ name: CI
on: on:
pull_request: pull_request:
branches: [main] branches:
- main
jobs: jobs:
check: check:
runs-on: linux-amd64 name: Lint and Test
container: runs-on: ubuntu-latest
image: rust:1-bookworm
steps: steps:
- uses: actions/checkout@v4 - name: Checkout code
uses: actions/checkout@v4
- name: Cache cargo registry and build - name: Install Rust
uses: actions/cache@v3 uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
path: | toolchain: stable
~/.cargo/registry components: rustfmt, clippy
~/.cargo/git cache: false
target
key: cargo-ci-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting - name: Check formatting
run: rustup component add rustfmt && cargo fmt --check run: cargo fmt --check
- name: Clippy - name: Clippy
run: rustup component add clippy && cargo clippy -- -D warnings run: cargo clippy -- -D warnings
- name: Test rustitch - name: Test rustitch
run: cargo test -p rustitch run: cargo test -p rustitch
@@ -37,33 +36,28 @@ jobs:
run: cargo build --release run: cargo build --release
version-check: version-check:
runs-on: linux-amd64 name: Version Check
container: runs-on: ubuntu-latest
image: rust:1-bookworm
steps: steps:
- uses: actions/checkout@v4 - name: Checkout repository
uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Verify version was bumped - name: Compare versions
shell: bash
run: | run: |
PR_VERSION=$(grep -m1 '^version' stitch-peek/Cargo.toml | sed 's/.*"\(.*\)"/\1/') NEW_VERSION=$(grep -m1 '^version =' stitch-peek/Cargo.toml | cut -d '"' -f 2)
git fetch origin main
MAIN_VERSION=$(git show origin/main:stitch-peek/Cargo.toml | grep -m1 '^version' | sed 's/.*"\(.*\)"/\1/')
echo "PR version: $PR_VERSION" git fetch origin ${{ github.base_ref }}
echo "Main version: $MAIN_VERSION" OLD_VERSION=$(git show origin/${{ github.base_ref }}:stitch-peek/Cargo.toml | grep -m1 '^version =' | cut -d '"' -f 2)
if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then echo "Old version (main): $OLD_VERSION"
echo "::error::Version in stitch-peek/Cargo.toml ($PR_VERSION) was not bumped. Please update the version before merging." echo "New version (PR): $NEW_VERSION"
if [ "$NEW_VERSION" = "$OLD_VERSION" ]; then
echo "Error: stitch-peek/Cargo.toml version has not been updated in this PR!"
exit 1 exit 1
else
echo "Success: Version updated from $OLD_VERSION to $NEW_VERSION"
fi fi
# Ensure the new version is actually newer (basic semver compare)
printf '%s\n%s' "$MAIN_VERSION" "$PR_VERSION" | sort -V | tail -1 | grep -qx "$PR_VERSION"
if [ $? -ne 0 ]; then
echo "::error::PR version ($PR_VERSION) is not newer than main ($MAIN_VERSION)."
exit 1
fi
echo "Version bump verified: $MAIN_VERSION -> $PR_VERSION"
+61 -39
View File
@@ -2,44 +2,67 @@ name: Release
on: on:
push: push:
branches: [main] branches:
- main
tags:
- 'v*'
jobs: jobs:
build-deb: build:
runs-on: linux-amd64 name: Build and Release
container: runs-on: ubuntu-latest
image: rust:1-bookworm
steps: steps:
- uses: actions/checkout@v4 - name: Checkout code
uses: actions/checkout@v4
- name: Cache cargo registry and build - name: Install Rust
uses: actions/cache@v3 uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
path: | toolchain: stable
~/.cargo/registry cache: false
~/.cargo/git
target
key: cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Install packaging tools - name: Install packaging tools
run: apt-get update && apt-get install -y dpkg-dev run: apt-get update && apt-get install -y dpkg-dev
- name: Extract version - name: Get Version
id: version id: get_version
run: | run: |
VERSION=$(grep -m1 '^version' stitch-peek/Cargo.toml | sed 's/.*"\(.*\)"/\1/') VERSION=$(grep -m1 '^version =' stitch-peek/Cargo.toml | cut -d '"' -f 2)
echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Building version $VERSION" if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "TAG=${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
echo "TAG=v$VERSION" >> $GITHUB_OUTPUT
fi
- name: Build release binary - name: Check if Release Exists
id: check_release
shell: bash
run: |
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.TAG }}")
if [ "$HTTP_STATUS" = "200" ]; then
echo "EXISTS=true" >> $GITHUB_OUTPUT
echo "Release already exists for tag ${{ steps.get_version.outputs.TAG }}. Skipping."
else
echo "EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Build
if: steps.check_release.outputs.EXISTS == 'false'
run: cargo build --release -p stitch-peek run: cargo build --release -p stitch-peek
- name: Run tests - name: Test
run: cargo test --release if: steps.check_release.outputs.EXISTS == 'false'
run: cargo test
- name: Package .deb - name: Package .deb
if: steps.check_release.outputs.EXISTS == 'false'
env: env:
VERSION: ${{ steps.version.outputs.version }} VERSION: ${{ steps.get_version.outputs.VERSION }}
TAG: ${{ steps.get_version.outputs.TAG }}
run: | run: |
PKG="stitch-peek_${VERSION}_amd64" PKG="stitch-peek_${VERSION}_amd64"
@@ -53,7 +76,6 @@ jobs:
cp data/stitch-peek.thumbnailer "${PKG}/usr/share/thumbnailers/" cp data/stitch-peek.thumbnailer "${PKG}/usr/share/thumbnailers/"
cp data/pes.xml "${PKG}/usr/share/mime/packages/" cp data/pes.xml "${PKG}/usr/share/mime/packages/"
# Control file -- fields must start at column 0, continuation lines start with a space
printf '%s\n' \ printf '%s\n' \
"Package: stitch-peek" \ "Package: stitch-peek" \
"Version: ${VERSION}" \ "Version: ${VERSION}" \
@@ -70,26 +92,26 @@ jobs:
printf '#!/bin/sh\nset -e\nif command -v update-mime-database >/dev/null 2>&1; then\n update-mime-database /usr/share/mime\nfi\n' \ printf '#!/bin/sh\nset -e\nif command -v update-mime-database >/dev/null 2>&1; then\n update-mime-database /usr/share/mime\nfi\n' \
> "${PKG}/DEBIAN/postinst" > "${PKG}/DEBIAN/postinst"
chmod 755 "${PKG}/DEBIAN/postinst" chmod 755 "${PKG}/DEBIAN/postinst"
cp "${PKG}/DEBIAN/postinst" "${PKG}/DEBIAN/postrm" cp "${PKG}/DEBIAN/postinst" "${PKG}/DEBIAN/postrm"
chmod 755 "${PKG}/DEBIAN/postrm" chmod 755 "${PKG}/DEBIAN/postrm"
dpkg-deb --build "${PKG}" dpkg-deb --build "${PKG}"
echo "Built: ${PKG}.deb"
- name: Create git tag mv "${PKG}.deb" "stitch-peek-${TAG}-amd64.deb"
env: echo "Built: stitch-peek-${TAG}-amd64.deb"
VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "Gitea CI"
git config user.email "ci@noreply.localhost"
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
- name: Create release - name: Create Release and Upload Asset
uses: actions/gitea-release@v1 if: steps.check_release.outputs.EXISTS == 'false'
uses: https://github.com/softprops/action-gh-release@v1
with: with:
token: ${{ secrets.RELEASE_TOKEN }} tag_name: ${{ steps.get_version.outputs.TAG }}
tag_name: v${{ steps.version.outputs.version }} name: Release ${{ steps.get_version.outputs.TAG }}
title: v${{ steps.version.outputs.version }} body: |
files: stitch-peek_${{ steps.version.outputs.version }}_amd64.deb Automated release for version ${{ steps.get_version.outputs.VERSION }}
Commit: ${{ github.sha }}
Branch: ${{ github.ref_name }}
files: stitch-peek-${{ steps.get_version.outputs.TAG }}-amd64.deb
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Generated
+10 -10
View File
@@ -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",
+7 -4
View File
@@ -1,9 +1,12 @@
[package] [package]
name = "rustitch" name = "rustitch"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2024"
[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"
+1 -5
View File
@@ -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))
} }
} }
Binary file not shown.
Binary file not shown.
Binary file not shown.
+201
View File
@@ -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
}
+2 -2
View File
@@ -1,7 +1,7 @@
[package] [package]
name = "stitch-peek" name = "stitch-peek"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2024"
[dependencies] [dependencies]
rustitch = { path = "../rustitch" } rustitch = { path = "../rustitch" }
+2 -2
View File
@@ -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()))?;