fn main {
// Auto-detect format and decode
let img = @image.decode(data)
println("Image: \{img.width} x \{img.height}")
println("Format: \{pixel_format_name(img.format)}")
// Access individual pixels
let pixel = img.get_pixel(10, 20)
println("Pixel: R=\{pixel.r} G=\{pixel.g} B=\{pixel.b} A=\{pixel.a}")
}
API Reference
Unified Decode
// Auto-detect format and decode
pub fn decode(data : Bytes) -> Image raise Failure
// Decode with known format
pub fn decode_by_format(data : Bytes, format : ImageFormat) -> Image raise Failure
// Detect format from magic bytes
pub fn detect_format(data : Bytes) -> Option[ImageFormat]
// Check if data matches any supported format
pub fn is_supported_format(data : Bytes) -> Bool
// Get human-readable pixel format name
pub fn pixel_format_name(format : PixelFormat) -> String
image - Pure MoonBit Image Decoding Library
A comprehensive image decoding library written entirely in MoonBit, supporting multiple popular image formats with zero external dependencies.
Supported Formats
Installation
Quick Start
API Reference
Unified Decode
Format-Specific Decoders
Image Type
PixelFormat
Architecture
Supported BMP Features
Supported QOI Features
Supported TGA Features
Supported PNG Features
Supported GIF Features
Supported JPEG Features
Limitations (Future Work)
License
MIT
Testing
The project includes 162 tests across 7 test files:
Tests cover:
decode_bmp()/decode_png()/decode_tga()/decode_qoi()/decode_gif()/decode_jpeg()with pixel-accurate checksums. Covers landscape, realistic, complex, blurry, and texture photos (1080p–3840px originals)Contributing
This library aims to build out the MoonBit image processing ecosystem. Planned future additions: