Define common pixel format types and conversion utilities in the image crate.
Requirements#
- Define
Imagestruct: width, height, pixel data in RGBA8 format (Vec, 4 bytes per pixel) - Conversion functions:
- Grayscale (1 channel) → RGBA8
- Grayscale + Alpha (2 channels) → RGBA8
- RGB (3 channels) → RGBA8
- RGBA (4 channels) → RGBA8 (identity/validation)
- Indexed color (palette + indices) → RGBA8
ImageErrorenum for decoding failures
Acceptance Criteria#
- All conversion functions produce correct RGBA8 output
- Unit tests for each conversion path
- Edge cases: zero-dimension images, empty pixel data
- No external dependencies, no
unsafe
Context#
Common infrastructure used by PNG, JPEG, and GIF decoders. Should be implemented early so decoders can target a uniform output format.
Phase 7 — Image Decoders