纯 MoonBit 图像编解码(18 种格式:PNG/JPEG/BMP/GIF/QOI/TGA/PSD/HDR/PNM/TIFF/ICO/CUR/ICNS/APNG/WebP/AVIF/HEIF/JPEG-XL)
| 项目 | 数量 |
|---|---|
| 公开函数 | 54 |
| 公开类型 | 4 |
| 常量 | 0 |
| 错误类型 | 0 |
pub struct AvifInfo {
pub struct HeifInfo {
pub struct JpegXlInfo {
pub struct Vp8ReferenceFrames {pub fn avif_decode(Bytes) -> @types.Image raise @types.LoadError
pub fn avif_info(Bytes) -> AvifInfo raise @types.LoadError
pub fn decode_apng_pure(Bytes) -> @types.PngAnimation raise @types.LoadError
pub fn decode_bmp_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_cur_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_gif_animation_pure(Bytes) -> @types.GifAnimation raise @types.LoadError
pub fn decode_gif_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_hdr_pure(Bytes) -> @types.ImageF raise @types.LoadError
pub fn decode_icns_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_ico_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_jpeg_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_png_16_pure(Bytes, req_channels? : Int?) -> @types.Image16 raise @types.LoadError
pub fn decode_png_pure(Bytes, req_channels? : Int?) -> @types.Image raise @types.LoadError
pub fn decode_pnm_16_pure(Bytes) -> @types.Image16 raise @types.LoadError
pub fn decode_pnm_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_psd_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_qoi_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_tga_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_tiff_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn decode_vp8_frame(Bytes, Int) -> @types.Image raise @types.LoadError
pub fn decode_vp8_inter_frame(Bytes, Int, Vp8ReferenceFrames) -> (@types.Image, Vp8ReferenceFrames) raise @types.LoadError
pub fn decode_webp_pure(Bytes) -> @types.Image raise @types.LoadError
pub fn encode_apng_pure(@types.PngAnimation) -> Bytes raise @types.LoadError
pub fn encode_bmp_pure(@types.Image) -> Bytes
pub fn encode_cur_pure(@types.Image) -> Bytes
pub fn encode_cur_with_hotspot_pure(@types.Image, Int, Int) -> Bytes
pub fn encode_gif_animation_pure(@types.GifAnimation) -> Bytes raise @types.LoadError
pub fn encode_gif_pure(@types.Image) -> Bytes raise @types.LoadError
pub fn encode_hdr_pure(@types.ImageF) -> Bytes raise @types.LoadError
pub fn encode_icns_pure(@types.Image) -> Bytes
pub fn encode_ico_pure(@types.Image) -> Bytes
pub fn encode_ico_with_sizes_pure(Array[@types.Image]) -> Bytes
pub fn encode_jpeg_pure(@types.Image) -> Bytes raise @types.LoadError
pub fn encode_pgm_pure(@types.Image) -> Bytes
pub fn encode_png_pure(@types.Image) -> Bytes
pub fn encode_pnm_pure(@types.Image) -> Bytes
pub fn encode_ppm_pure(@types.Image) -> Bytes
pub fn encode_qoi_pure(@types.Image) -> Bytes raise @types.LoadError
pub fn encode_tga_pure(@types.Image) -> Bytes
pub fn encode_tiff_pure(@types.Image) -> Bytes raise @types.LoadError
pub fn encode_webp_lossy_full(@types.Image, quality? : Int) -> Bytes raise @types.LoadError
pub fn encode_webp_lossy_pure(@types.Image, quality? : Int) -> Bytes raise @types.LoadError
pub fn heif_decode(Bytes) -> @types.Image raise @types.LoadError
pub fn heif_info(Bytes) -> HeifInfo raise @types.LoadError
pub fn is_avif_format(Bytes) -> Bool
pub fn is_heif_format(Bytes) -> Bool
pub fn is_jpegxl_codestream(Bytes) -> Bool
pub fn is_jpegxl_container(Bytes) -> Bool
pub fn is_jpegxl_format(Bytes) -> Bool
pub fn jpegxl_decode(Bytes) -> @types.Image raise @types.LoadError
pub fn jpegxl_info(Bytes) -> JpegXlInfo raise @types.LoadError
pub fn tiff_deflate_decode(Bytes) -> Array[Byte] raise @types.LoadError
pub fn tiff_lzw_decode(Bytes) -> Array[Byte] raise @types.LoadError
pub fn tiff_packbits_decode(Bytes) -> Array[Byte] raise @types.LoadErrorpub trait Codec {
fn format_name(Self) -> String
fn can_encode(Self) -> Bool
fn can_decode(Self) -> Bool
fn is_lossless(Self) -> Bool
fn encode(Self, core/types.AnyImage) -> Bytes raise core/types.LoadError
fn decode(Self, Bytes) -> core/types.AnyImage raise core/types.LoadError
}impl Codec for ImageFormatfn can_decode(self : core/types.ImageFormat) -> Boolfn can_encode(self : core/types.ImageFormat) -> Boolfn decode(self : core/types.ImageFormat, data : Bytes) -> core/types.AnyImage raise core/types.LoadErrorfn encode(self : core/types.ImageFormat, img : core/types.AnyImage) -> Bytes raise core/types.LoadErrorfn format_name(self : core/types.ImageFormat) -> Stringfn is_lossless(self : core/types.ImageFormat) -> Boolpub struct ApngInfoExtended {
width : Int
height : Int
bit_depth : Int
color_type : Int
color_type_name : String
num_channels : Int
has_alpha : Bool
num_frames : Int
num_plays : Int
is_animated : Bool
}pub struct AvifInfo {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
}pub struct AvifInfoExtended {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
rotation : Int
mirror : Int
color_type : String
color_primaries : Int
transfer_characteristics : Int
matrix_coefficients : Int
full_range : Bool
av1_profile : Int
av1_level : Int
av1_tier : Int
av1_monochrome : Bool
}pub struct BmpInfoExtended {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
compression : Int
compression_name : String
is_bottom_up : Bool
dib_size : Int
num_colors : Int
data_offset : Int
}pub struct GifInfoExtended {
width : Int
height : Int
version : String
has_global_color_table : Bool
global_color_table_size : Int
color_resolution : Int
is_sorted : Bool
background_color_index : Int
pixel_aspect_ratio : Int
num_channels : Int
has_alpha : Bool
}pub struct HdrInfoExtended {
width : Int
height : Int
num_channels : Int
has_alpha : Bool
format : String
}pub struct HeifInfo {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
}pub struct HeifInfoExtended {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
rotation : Int
mirror : Int
color_type : String
color_primaries : Int
transfer_characteristics : Int
matrix_coefficients : Int
full_range : Bool
hevc_profile : Int
hevc_level : Int
hevc_tier : Int
hevc_chroma_format : Int
hevc_bit_depth_luma : Int
hevc_bit_depth_chroma : Int
}pub enum ImageInfoExtended {
Avif(AvifInfoExtended)
Heif(HeifInfoExtended)
JpegXl(JpegXlInfoExtended)
Webp(WebpInfoExtended)
Tiff(TiffInfoExtended)
Psd(PsdInfoExtended)
Bmp(BmpInfoExtended)
Gif(GifInfoExtended)
Png(PngInfoExtended)
Jpeg(JpegInfoExtended)
Qoi(QoiInfoExtended)
Tga(TgaInfoExtended)
Hdr(HdrInfoExtended)
Pnm(PnmInfoExtended)
Ico(IcoInfoExtended)
Cur(CurInfoExtended)
Icns(IcnsInfoExtended)
Apng(ApngInfoExtended)
}pub struct JpegInfoExtended {
width : Int
height : Int
precision : Int
num_components : Int
is_grayscale : Bool
is_progressive : Bool
sof_marker : Int
sof_name : String
num_channels : Int
has_alpha : Bool
}pub struct JpegXlInfo {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
is_lossless : Bool
}pub struct JpegXlInfoExtended {
width : Int
height : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
is_lossless : Bool
is_codestream : Bool
orientation : Int
}pub struct PngInfoExtended {
width : Int
height : Int
bit_depth : Int
color_type : Int
color_type_name : String
num_channels : Int
has_alpha : Bool
is_palette : Bool
compression_method : Int
filter_method : Int
interlace_method : Int
}pub struct PnmInfoExtended {
width : Int
height : Int
format_type : String
maxval : Int
bit_depth : Int
num_channels : Int
has_alpha : Bool
is_binary : Bool
}pub struct PsdInfoExtended {
width : Int
height : Int
bit_depth : Int
channel_count : Int
num_channels : Int
has_alpha : Bool
color_mode : Int
color_mode_name : String
compression : Int
compression_name : String
version : Int
}pub struct QoiInfoExtended {
width : Int
height : Int
channels : Int
colorspace : Int
colorspace_name : String
num_channels : Int
has_alpha : Bool
}pub struct TgaInfoExtended {
width : Int
height : Int
image_type : Int
image_type_name : String
bit_depth : Int
num_channels : Int
has_alpha : Bool
is_bottom_up : Bool
id_length : Int
color_map_type : Int
x_origin : Int
y_origin : Int
}pub struct TiffInfoExtended {
width : Int
height : Int
bit_depth : Int
samples_per_pixel : Int
num_channels : Int
has_alpha : Bool
compression : Int
compression_name : String
photometric : Int
photometric_name : String
orientation : Int
resolution_unit : Int
is_little_endian : Bool
}pub struct WebpInfoExtended {
width : Int
height : Int
format : String
has_alpha : Bool
has_animation : Bool
has_icc_profile : Bool
has_exif : Bool
has_xmp : Bool
num_channels : Int
}fn avif_decode(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn codec_decode_auto(data : Bytes) -> core/types.AnyImage raise core/types.LoadErrorfn codec_detect_format(data : Bytes) -> core/types.ImageFormatfn decode_apng_pure(data : Bytes) -> core/types.PngAnimation raise core/types.LoadErrorfn decode_bmp_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrortest "doc_decode_bmp_pure" {
try {
let img = @codec.decode_bmp_pure(@types.DOC_TEST_BMP_1X1)
assert_eq(img.width, 1)
assert_eq(img.height, 1)
assert_eq(img.channels, 3)
} catch {
_ => assert_true(false)
}
}fn decode_bmp_region(data : Bytes, x : Int, y : Int, w : Int, h : Int) -> core/types.Image raise core/types.LoadErrorfn decode_cur_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_gif_animation_pure(data : Bytes) -> core/types.GifAnimation raise core/types.LoadErrorfn decode_gif_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_hdr_pure(data : Bytes) -> core/types.ImageF raise core/types.LoadErrorfn decode_icns_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_ico_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_jpeg_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_png_16_pure(data : Bytes, req_channels? : Int?) -> core/types.Image16 raise core/types.LoadErrorfn decode_png_pure(data : Bytes, req_channels? : Int?) -> core/types.Image raise core/types.LoadErrortest "doc_decode_png_pure" {
try {
let img = @codec.decode_png_pure(@types.DOC_TEST_PNG_1X1_RGBA)
assert_eq(img.width, 1)
assert_eq(img.height, 1)
assert_eq(img.channels, 4)
} catch {
_ => assert_true(false)
}
}fn decode_png_region(data : Bytes, x : Int, y : Int, w : Int, h : Int) -> core/types.Image raise core/types.LoadErrorfn decode_pnm_16_pure(data : Bytes) -> core/types.Image16 raise core/types.LoadErrorfn decode_pnm_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrortest "doc_decode_pnm_pure" {
try {
let img = @codec.decode_pnm_pure(@types.DOC_TEST_PNM_1X1)
assert_eq(img.width, 1)
assert_eq(img.height, 1)
assert_eq(img.channels, 3)
} catch {
_ => assert_true(false)
}
}fn decode_psd_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_qoi_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrortest "doc_decode_qoi_pure" {
try {
let img = @codec.decode_qoi_pure(@types.DOC_TEST_QOI_1X1)
assert_eq(img.width, 1)
assert_eq(img.height, 1)
assert_eq(img.channels, 4)
} catch {
_ => assert_true(false)
}
}fn decode_qoi_region(data : Bytes, x : Int, y : Int, w : Int, h : Int) -> core/types.Image raise core/types.LoadErrorfn decode_tga_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrortest "doc_decode_tga_pure" {
try {
let data = Bytes::from_array([b'\xff', b'\x00', b'\x00'])
let img = @types.Image::{ width: 1, height: 1, channels: 3, data, }
let tga_bytes = @codec.encode_tga_pure(img)
let decoded = @codec.decode_tga_pure(tga_bytes)
assert_eq(decoded.width, 1)
assert_eq(decoded.height, 1)
assert_eq(decoded.channels, 3)
} catch {
_ => assert_true(false)
}
}fn decode_tiff_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_vp8_frame(data : Bytes, offset : Int) -> core/types.Image raise core/types.LoadErrorfn decode_vp8_inter_frame(data : Bytes, offset : Int, refs : Vp8ReferenceFrames) -> (core/types.Image, Vp8ReferenceFrames) raise core/types.LoadErrorfn decode_webp_pure(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn decode_webp_vp8l_rfc(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn encode_apng_pure(anim : core/types.PngAnimation) -> Bytes raise core/types.LoadErrorfn encode_cur_pure(img : core/types.Image) -> Bytesfn encode_cur_with_hotspot_pure(img : core/types.Image, hotspot_x : Int, hotspot_y : Int) -> Bytesfn encode_gif_animation_pure(anim : core/types.GifAnimation) -> Bytes raise core/types.LoadErrorfn encode_gif_pure(img : core/types.Image) -> Bytes raise core/types.LoadErrortest "doc_encode_gif_pure" {
try {
let data = Bytes::from_array([b'\xff', b'\x00', b'\x00'])
let img = @types.Image::{ width: 1, height: 1, channels: 3, data, }
let encoded = @codec.encode_gif_pure(img)
assert_true(encoded.length() > 0)
} catch {
_ => assert_true(false)
}
}fn encode_hdr_pure(img : core/types.ImageF) -> Bytes raise core/types.LoadErrorfn encode_icns_pure(img : core/types.Image) -> Bytesfn encode_ico_pure(img : core/types.Image) -> Bytesfn encode_jpeg_progressive(img : core/types.Image, quality : Int) -> Bytes raise core/types.LoadErrorfn encode_jpeg_progressive_420(img : core/types.Image, quality : Int) -> Bytes raise core/types.LoadErrorfn encode_jpeg_progressive_420_scripted(img : core/types.Image, quality : Int, script : Array[JpegProgScan]) -> Bytes raise core/types.LoadErrorfn encode_jpeg_pure(img : core/types.Image) -> Bytes raise core/types.LoadErrorfn encode_jpeg_with_quality(img : core/types.Image, quality : Int) -> Bytes raise core/types.LoadErrorfn encode_pgm_pure(img : core/types.Image) -> Bytesfn encode_png_pure(img : core/types.Image) -> Bytesfn encode_pnm_pure(img : core/types.Image) -> Bytesfn encode_ppm_pure(img : core/types.Image) -> Bytesfn encode_qoi_pure(img : core/types.Image) -> Bytes raise core/types.LoadErrortest "doc_encode_qoi_pure" {
try {
let data = Bytes::from_array([b'\xff', b'\x00', b'\x00'])
let img = @types.Image::{ width: 1, height: 1, channels: 3, data, }
let encoded = @codec.encode_qoi_pure(img)
assert_true(encoded.length() > 0)
let decoded = @codec.decode_qoi_pure(encoded)
assert_eq(decoded.width, 1)
} catch {
_ => assert_true(false)
}
}fn encode_tga_pure(img : core/types.Image) -> Bytesfn encode_tiff_pure(img : core/types.Image) -> Bytes raise core/types.LoadErrorfn encode_webp_lossless(img : core/types.Image) -> Bytes raise core/types.LoadError#deprecated("产物不符合 VP8 规范,请改用 encode_webp_lossless")
fn encode_webp_lossy_full(img : core/types.Image, quality? : Int) -> Bytes raise core/types.LoadError#deprecated("产物不符合 VP8 规范,请改用 encode_webp_lossless")
fn encode_webp_lossy_pure(img : core/types.Image, quality? : Int) -> Bytes raise core/types.LoadErrorfn encode_webp_vp8l_literal(img : core/types.Image) -> Bytes raise core/types.LoadErrorlet bytes = @codec.encode_webp_vp8l_literal(img)fn encode_webp_vp8l_lz77(img : core/types.Image) -> Bytes raise core/types.LoadErrorfn heif_decode(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn is_apng_format(data : Bytes) -> Boolfn is_avif_format(data : Bytes) -> Boolfn is_cur_format(data : Bytes) -> Boolfn is_heif_format(data : Bytes) -> Boolfn is_ico_format(data : Bytes) -> Boolfn is_jpegxl_format(data : Bytes) -> Boolfn jpegxl_decode(data : Bytes) -> core/types.Image raise core/types.LoadErrorfn zlib_compress(data : Bytes) -> BytesInstall
Download zipMoonBit image codec: pure MoonBit backend for 18+ image formats, color, metadata, barcode.