Sprite Compiler Advanced Features¶
Advanced features and options for the PixelRoot32 Sprite Compiler to optimize sprite conversion and handle complex scenarios.
Dithering¶
Dithering improves the visual quality of converted sprites by simulating intermediate colors through pixel patterns.
Basic Dithering¶
Enable dithering for better gradient handling:
Dithering Strength¶
Control dithering intensity:
Values: - 0.0: No dithering - 0.5: Moderate dithering (default) - 1.0: Maximum dithering
Dithering Algorithms¶
Choose dithering algorithm:
# Floyd-Steinberg (default)
pr32-sprite-compiler sprite.png output.h --dither --dither-algorithm floyd-steinberg
# Ordered (Bayer)
pr32-sprite-compiler sprite.png output.h --dither --dither-algorithm ordered
# Atkinson
pr32-sprite-compiler sprite.png output.h --dither --dither-algorithm atkinson
When to use: - Floyd-Steinberg: Best for most images, smooth gradients - Ordered: Faster, good for patterns - Atkinson: Softer, less noticeable patterns
Layer Merging (MultiSprite)¶
Combine compatible sprite layers to reduce draw calls and improve performance.
Basic Layer Merging¶
Merge layers with compatible colors:
Layer Compatibility¶
Control which layers can be merged:
Parameters: - --merge-threshold: Color similarity threshold (0.0-1.0)
Preserve Layer Colors¶
Keep per-layer color assignments:
Bounds & Packing¶
Auto-Trim Transparent Borders¶
Automatically remove transparent borders:
Benefits: - Reduces sprite size - Saves memory - Faster rendering
Manual Bounds¶
Specify custom bounds:
Format: left,top,right,bottom (in pixels)
Sprite Packing¶
Pack multiple sprites into pages:
Parameters: - --pack: Enable packing - --pack-size WxH: Page size (default: 256x256) - --pack-padding N: Padding between sprites (default: 1)
Output: - Packed sprite sheet image - Individual sprite headers with offsets - Packing metadata
Output Controls¶
Endianness¶
Specify byte order for multi-byte values:
# Little-endian (default for most systems)
pr32-sprite-compiler sprite.png output.h --endian little
# Big-endian
pr32-sprite-compiler sprite.png output.h --endian big
Alignment¶
Control data structure alignment:
Common values: - 1: No alignment (default) - 2: 2-byte alignment - 4: 4-byte alignment (recommended for ESP32) - 8: 8-byte alignment
Output Format¶
Choose output code style:
# C-style (default)
pr32-sprite-compiler sprite.png output.h --style c
# C++ style
pr32-sprite-compiler sprite.png output.h --style cpp
# Minimal (no comments)
pr32-sprite-compiler sprite.png output.h --style minimal
Custom Header Template¶
Use custom header template:
Template variables: - {NAME}: Sprite name - {DATA}: Sprite data array - {WIDTH}: Sprite width - {HEIGHT}: Sprite height
Metadata Generation¶
Generate Metadata¶
Include sprite metadata:
Output includes: - Original image dimensions - Conversion parameters - Color information - Format details
JSON Metadata¶
Export metadata as JSON:
pr32-sprite-compiler sprite.png output.h \
--metadata \
--metadata-format json \
--metadata-file sprite.json
JSON structure:
{
"name": "SPRITE",
"width": 8,
"height": 8,
"format": "1bpp",
"originalSize": {"width": 8, "height": 8},
"colors": 2,
"dataSize": 8
}
Color Processing¶
Color Quantization¶
Reduce colors intelligently:
Parameters: - --quantize: Enable quantization - --colors N: Target color count
Color Mapping¶
Custom color mapping:
Map JSON format:
{
"mappings": [
{"from": [255, 0, 0], "to": [255, 255, 255]},
{"from": [0, 255, 0], "to": [0, 0, 0]}
]
}
Gamma Correction¶
Apply gamma correction:
Common values: - 1.0: No correction - 2.2: Standard (sRGB) - 1.8: Mac standard
Performance Optimization¶
Parallel Processing¶
Process multiple files in parallel:
Parameters: - --parallel N: Number of parallel workers (default: CPU cores)
Caching¶
Enable conversion caching:
Benefits: - Faster re-compilation - Skips unchanged files - Cache stored in .sprite-compiler-cache/
Incremental Builds¶
Only process changed files:
Validation¶
Validate Output¶
Verify generated sprite data:
Checks: - Data array correctness - Size constraints - Format compliance - Memory usage
Preview Mode¶
Preview conversion without generating file:
Output: - Console preview of sprite data - Statistics (size, colors, etc.) - Validation results
Multi-Format Output¶
Generate Multiple Formats¶
Output in multiple formats simultaneously:
Outputs: - output_1bpp.h - output_2bpp.h - output_4bpp.h
Custom Scripts¶
Pre-Processing Script¶
Run custom script before conversion:
Post-Processing Script¶
Run custom script after conversion:
Script receives: - Input file path - Output file path - Conversion parameters - Metadata
Advanced Batch Options¶
Filter by Size¶
Process only sprites matching size:
Filter by Format¶
Process only specific formats:
Exclude Patterns¶
Exclude files matching pattern:
Integration Examples¶
Watch Mode¶
Automatically recompile on file changes:
CI/CD Integration¶
Example GitHub Actions workflow:
name: Compile Sprites
on: [push]
jobs:
compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm install -g pr32-sprite-compiler
- run: pr32-sprite-compiler --batch assets/sprites/*.png --output-dir src/sprites/
Best Practices¶
When to Use Advanced Features¶
Dithering: - Use for gradients and smooth transitions - Avoid for sharp, pixel-art style graphics
Layer Merging: - Use for complex sprites with multiple layers - Test performance impact first
Packing: - Use for large sprite collections - Consider memory vs. performance trade-off
Trimming: - Always use for sprites with transparent borders - Saves memory and improves performance
Performance Tips¶
- Use
--parallelfor batch processing - Enable
--cachefor development - Use
--incrementalfor large projects - Validate output with
--validate
Troubleshooting Advanced Features¶
Dithering Issues¶
Too much noise: - Reduce --dither-strength - Try different algorithm - Consider manual color reduction
Packing Issues¶
Sprites don't fit: - Increase --pack-size - Reduce sprite sizes - Adjust --pack-padding
Performance Issues¶
Slow compilation: - Use --parallel for batch - Enable --cache - Reduce image sizes - Use --incremental
See Also¶
- Usage Guide - Basic usage examples
- Overview - Compiler overview
- Manual - Sprites - Using sprites in games