@zieka-tools/pxl
v0.2.0
Published
GPU-accelerated image processing CLI tool
Maintainers
Readme
PXL - GPU-Accelerated Image Processing Tool
A high-performance command-line image processing tool written in Zig with GPU acceleration support.
Features
✅ Implemented
- Fast CPU-based image resizing with bilinear interpolation
- Support for multiple image formats (JPEG, PNG, PPM, PGM) via stb_image
- Batch processing of multiple images
- Aspect ratio preservation
- Comprehensive test suite (unit, integration, performance)
- Performance benchmarks showing ~860 MP/s for 4K images on CPU
🚧 In Progress
- CUDA GPU acceleration (kernel implemented, integration pending)
- OpenCL support (kernel implemented, runtime integration pending)
Performance
CPU Performance (Apple Silicon M-series):
- Small images (100x100 → 50x50): ~14 µs
- HD images (1920x1080 → 1280x720): ~3.7 ms
- 4K images (3840x2160 → 1920x1080): ~9.7 ms
- Batch processing: ~1,720 images/second (800x600 → 400x300)
Installation
Prerequisites
- Zig 0.14.0 or later
- C compiler (for stb_image dependencies)
- (Optional) ImageMagick for test image generation
# macOS
brew install zig
# Linux (Ubuntu/Debian)
snap install zig --classic
# or
wget https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz
tar -xf zig-linux-x86_64-0.14.0.tar.xz
export PATH=$PATH:$(pwd)/zig-linux-x86_64-0.14.0
# Windows
winget install zig.zigBuilding from Source
# Clone the repository
git clone https://github.com/yourusername/pxl.git
cd pxl
# Build the project
zig build
# Build with optimizations
zig build -Doptimize=ReleaseFast
# Build as a library
zig build # Creates both executable and library
# Install to system (optional)
zig build install --prefix /usr/localRunning Tests
# Run all tests
zig build test
# Run benchmarks
zig build bench
# Run integration tests
zig build test-integration
# Run comprehensive test suite
./test_all_features.shUsage
Basic Resize
pxl resize -w 800 -h 600 input.jpg -o output.jpgMaintain Aspect Ratio
pxl resize -w 1920 --keep-aspect photo.png -o resized.pngBatch Processing
pxl resize -w 200 -h 200 *.jpg -o ./thumbnails/Force CPU Processing
pxl resize --cpu -w 1024 -h 768 image.pngArchitecture
pxl/
├── src/
│ ├── main.zig # CLI entry point
│ ├── cli.zig # Argument parsing
│ ├── commands/
│ │ └── resize.zig # Resize command implementation
│ ├── cpu/
│ │ └── resize.zig # CPU bilinear interpolation
│ ├── gpu/
│ │ ├── cuda.zig # CUDA wrapper
│ │ ├── opencl.zig # OpenCL wrapper
│ │ ├── detector.zig # GPU detection
│ │ ├── resize_kernel.cu # CUDA kernel
│ │ └── resize_kernel.cl # OpenCL kernel
│ └── image/
│ ├── image.zig # Image data structure
│ ├── loader.zig # Image loading (stb_image)
│ └── writer.zig # Image saving
└── test/
├── unit/ # Unit tests
├── integration/ # Integration tests
└── performance/ # BenchmarksDevelopment
Test-Driven Development
The project follows TDD principles with comprehensive test coverage:
- Unit tests for all core components
- Integration tests for end-to-end workflows
- Performance benchmarks with targets
Adding New Features
- Write tests first (TDD)
- Implement feature to pass tests
- Run benchmarks to ensure performance
- Update documentation
GPU Acceleration
CUDA Support
- Kernel implemented for NVIDIA GPUs
- Provides 10-100x speedup for batch operations
- Automatic fallback to CPU when unavailable
OpenCL Support
- Cross-platform GPU support
- Works with AMD, Intel, and other GPUs
- Kernel implemented, runtime integration in progress
Future Enhancements
- [ ] Metal support for macOS
- [ ] Additional image operations (blur, sharpen, rotate)
- [ ] Video processing support
- [ ] Distributed processing for large batches
- [ ] WebAssembly build for browser usage
License
MIT
Contributing
Contributions welcome! Please ensure:
- All tests pass (
zig build test) - Benchmarks show no regression (
zig build bench) - Code follows Zig style guidelines
- New features include tests
