A comprehensive image decoding library written entirely in MoonBit, supporting multiple popular image formats with zero external dependencies.
Supported Formats
Format
Status
Description
BMP
✅ Complete
1/4/8/24/32-bit, top-down & bottom-up
QOI
✅ Complete
RGB & RGBA, full spec compliance
TGA
✅ Complete
Uncompressed & RLE, 8/16/24/32-bit
PNG
✅ Complete
8-bit grayscale/RGB/RGBA, DEFLATE decompression
Installation
moon add lws/image
Quick Start
fn main {
// Auto-detect format and decode
let data = read_file("photo.png")
let img = @image.decode(data)?
println("Image: \(img.width) x \(img.height)")
println("Format: \(img.format)")
// Access individual pixels
let pixel = img.get_pixel(10, 20)
println("Pixel at (10,20): 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) -> Result[Image, String]!
// Decode with known format
pub fn decode_by_format(data : Bytes, format : ImageFormat) -> Result[Image, String]!
// Detect format from magic bytes
pub fn detect_format(data : Bytes) -> Option[ImageFormat]
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
Limitations (Future Work)
License
MIT
Contributing
This library aims to build out the MoonBit image processing ecosystem. Planned future additions: