Pure MoonBit image processing library with filters, morphology, color-space operations, affine transforms, drawing, compositing, PNG/GIF/QOI/BMP codecs, TIFF and lossless WebP decoding, and JPEG/WebP encoding adapters. Backend-agnostic (js, wasm-gc, native) with a browser Playground.
moon new pixel-demo --user demo_user
cd pixel-demo
moon add 0717lee/pixelforge@0.19.0import {
"0717lee/pixelforge",
}
pkgtype(kind: "executable")///|
fn main {
let image = @pixelforge.Image::new(2, 1)
image.set_pixel(0, 0, b'\xFF', b'\x00', b'\x00', b'\xFF')
image.set_pixel(1, 0, b'\x00', b'\xFF', b'\x00', b'\xFF')
let pipeline = @pixelforge.Pipeline::new()
.append(@pixelforge.Filter::Grayscale)
.append(@pixelforge.Filter::Brightness(10))
let processed = image.apply_pipeline(pipeline)
let png = @pixelforge.png_encode(processed)
let decoded = match @pixelforge.png_decode(png) {
Some(value) => value
None => abort("PNG decoding failed")
}
if decoded.data != processed.data {
abort("PNG round-trip changed pixels")
}
println("\{decoded.width}x\{decoded.height} PNG round-trip OK")
}| 类别 | 主要能力 |
|---|---|
| 滤镜与色调 | 灰度、反色、亮度、对比度、阈值、棕褐色、像素化、中值、直方图均衡、色调分离、gamma、暗角、饱和度、色相、HSL 亮度、色阶、自动对比度 |
| 卷积与边缘 | 自定义 Kernel / convolve,高斯与盒式模糊、锐化、浮雕、Laplacian、Sobel、Scharr、Canny、双边滤波、锐化蒙版 |
| 几何与绘图 | 裁剪、填充、翻转、旋转、仿射矩阵、最近邻/双线性/双三次缩放,线/矩形/圆,5×7 位图文字,source-over 与八种混合模式 |
| 分析与特征 | RGB/luma 直方图与统计,Otsu/Sauvola/局部均值阈值,形态学、骨架、连通域/区域统计/轮廓、Harris、HOG、LBP、积分图、距离变换、泛洪填充 |
| 比较与噪声 | aHash/dHash/汉明距离,MSE/PSNR/SSIM,确定性高斯与椒盐噪声,Floyd–Steinberg 抖动 |
| 组合与遍历 | 类型化 Filter / Pipeline、数字 id 派发、共享像素的 for_each_tile / for_each_row |
| 格式 | 核心解码 | 核心编码 | 主要边界 |
|---|---|---|---|
| PNG | 支持 | 支持 | 非交错、8-bit 灰度/灰度透明/调色板/RGB/RGBA;tRNS;CRC-32/Adler-32 校验;输出 RGBA8 |
| GIF | 支持 | 支持 | LZW、交错、透明索引;编码单帧、最多 256 个调色板项,alpha < 128 视为透明,超限 abort |
| QOI | 支持 | 支持 | RGBA 无损往返 |
| BMP | 支持 | 支持 | 无压缩 24/32-bit;24-bit 输出不保留 alpha |
| JPEG | 支持 | 支持 | mizchi/image 的 baseline JPEG;有损,不保留 alpha;jpeg_encode(image, quality) |
| WebP | Lossless VP8L | Lossless VP8L | 解码 predictor、cross-color、subtract-green、color-indexing 变换;不解码有损 VP8 |
| TIFF | 支持子集 | 不支持 | classic:chunky 8-bit 灰度/RGB/RGBA,多条带或 tiles,未压缩/PackBits/LZW/Deflate,Predictor=2;BigTIFF:单条带,未压缩/PackBits/LZW,偏移和值在支持的 Int 范围内 |
| AVIF | 仅探测和 metadata | JS 宿主适配 | 无 AV1 像素解码;编码只接受不透明图像,浏览器需支持 Canvas AVIF 编码,依赖在 Node.js 中使用本地 ffmpeg;native/wasm-gc 编码 abort |
node serve.mjsnode scripts/benchmark.mjsmoon run --target native cmd/cli -- --help
moon run --target native cmd/cli -- info --input input.tiff
moon run --target native cmd/cli -- convert --from png --to qoi --pipeline grayscale,contrast:1.2 --input input.png --output output.qoipub(all) struct Affine {
a : Double
b : Double
c : Double
d : Double
e : Double
f : Double
}pub(all) enum BlendMode {
Normal
Multiply
Screen
Overlay
Darken
Lighten
Difference
Add
}pub(all) struct BoundingBox {
min_x : Int
min_y : Int
max_x : Int
max_y : Int
}pub(all) struct ComponentStats {
label : Int
area : Int
bbox : BoundingBox
centroid : (Double, Double)
min_x : Int
min_y : Int
max_x : Int
max_y : Int
centroid_x : Double
centroid_y : Double
}pub(all) struct ContourPoint {
x : Int
y : Int
}pub(all) struct Corner {
x : Int
y : Int
response : Double
}pub(all) enum Filter {
Grayscale
Invert
Brightness(Int)
Contrast(Double)
Blur
Sharpen
Emboss
Edges
Sobel
Sepia
Threshold(Int)
Pixelate(Int)
Median
HistogramEqualize
FlipHorizontal
FlipVertical
Posterize(Int)
Gamma(Double)
Vignette(Double)
Scharr
Canny(Int)
Otsu
DitherMono
}pub(all) struct GifFrame {
image : Image
left : Int
top : Int
delay_cs : Int
disposal : Int
transparent_index : Int
}pub(all) struct Image {
width : Int
height : Int
data : FixedArray[Byte]
}| id | filter | amount |
|---|---|---|
| 0 | grayscale | — |
| 1 | invert | — |
| 2 | brightness | delta (−255..255) |
| 3 | contrast | factor (0.0..3.0) |
| 4 | gaussian blur | — |
| 5 | sharpen | — |
| 6 | emboss | — |
| 7 | laplacian edges | — |
| 8 | sobel edges | — |
| 9 | sepia | — |
| 10 | threshold | level (default 128) |
| 11 | pixelate | block size (default 8) |
| 12 | median denoise | — |
| 13 | histogram equalize | — |
| 14 | flip horizontal | — |
| 15 | flip vertical | — |
| 16 | posterize | levels (default 4) |
| 17 | gamma | gamma value (default 2.2) |
| 18 | vignette | strength 0..1 (default 0.5) |
| 19 | scharr edges | — |
| 20 | canny edges | high threshold (default 100, low = high/2) |
| 21 | otsu auto threshold | — |
| 22 | floyd–steinberg dither (mono) | — |
pub(all) enum ImageFormat {
Png
Gif
Qoi
Bmp
Jpeg
Webp
Avif
Tiff
}pub(all) struct ImageTile {
image : Image
origin_x : Int
origin_y : Int
tile_width : Int
tile_height : Int
}pub struct Stats {
min_r : Int
max_r : Int
mean_r : Int
min_g : Int
max_g : Int
mean_g : Int
min_b : Int
max_b : Int
mean_b : Int
luma_min : Int
luma_max : Int
luma_mean : Int
}fn clamp_byte(value : Int) -> Bytefn hamming_distance(a : UInt64, b : UInt64) -> Int= 20 means "clearly different".
fn hsl_to_rgb(h : Double, s : Double, l : Double) -> (Int, Int, Int)fn hsv_to_rgb(h : Double, s : Double, v : Double) -> (Int, Int, Int)fn rgb_to_hsl(r : Int, g : Int, b : Int) -> (Double, Double, Double)fn rgb_to_hsv(r : Int, g : Int, b : Int) -> (Double, Double, Double)fn rgb_to_ycbcr(r : Int, g : Int, b : Int) -> (Int, Int, Int)fn ycbcr_to_rgb(y : Int, cb : Int, cr : Int) -> (Int, Int, Int)Install
Download zipPure MoonBit image processing library with filters, morphology, color-space operations, affine transforms, drawing, compositing, PNG/GIF/QOI/BMP codecs, TIFF and lossless WebP decoding, and JPEG/WebP encoding adapters. Backend-agnostic (js, wasm-gc, native) with a browser Playground.