all\all.mbt
0% · 0 / 20 points · 171 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 门面包:`walkzzz/image.mbt/all` - 3
/// - 4
/// 目的只有一个:**下游只 `moon add walkzzz/image.mbt` 一条,就能 `import "walkzzz/image.mbt/all"` 拿到常用的全部东西**。 - 5
/// - 6
/// MoonBit 的规则是"依赖会传递、import 不传递"——`moon add walkzzz/image.mbt` 会把六个子模块全部下载好, - 7
/// 但下游包直接 `import "walkzzz/image.codec/lib"` 会报 - 8
/// `exists in global environment, but its containing module is not imported by <你的包>`。 - 9
/// 本包用 `pub using` 把这些名字从子模块**再导出**一次:下游 import 的是一个**直接依赖(根模块)**里的包, - 10
/// 于是不需要额外 add 任何子模块。 - 11
/// - 12
/// 想要更多函数(filter / vision / photography / domain 的上百个 API),照旧显式 add 对应子模块——本包只覆盖"高频起步面"。 - 13
pub using @types { - 14
type Image, - 15
type Image16, - 16
type ImageF, - 17
type AnyImage, - 18
type LoadError, - 19
type ImageError, - 20
type ErrorCode, - 21
type ImageFormat, - 22
type DecodeLimits, - 23
type Region, - 24
type ImageRegion, - 25
type AllocBudget, - 26
} - 27
- 28
///| - 29
/// 区域视图(ROI):`pub using` 只能再导出类型,方法要在这里包一层薄函数, - 30
/// 否则下游拿到类型却调不到 `Image::region` / `ImageRegion::to_image`。 - 31
- 32
///| - 33
/// 取一块区域的零复制视图(越界自动裁剪)。失败不会发生,空区域返回空视图。 - 34
pub fn region( - 35
img : @types.Image, - 36
x : Int32, - 37
y : Int32, - 38
w : Int32, - 39
h : Int32, - 40
) -> @types.ImageRegion { - 41○
img.region(x, y, w, h) - 42
} - 43
- 44
///| - 45
/// 用现成 `Region` 取零复制视图。 - 46
pub fn region_with(img : @types.Image, r : @types.Region) -> @types.ImageRegion { - 47○
img.region_with(r) - 48
} - 49
- 50
///| - 51
/// 区域视图宽度(裁剪后的有效宽度)。 - 52
pub fn region_width(v : @types.ImageRegion) -> Int32 { - 53○
v.width() - 54
} - 55
- 56
///| - 57
/// 区域视图高度(裁剪后的有效高度)。 - 58
pub fn region_height(v : @types.ImageRegion) -> Int32 { - 59○
v.height() - 60
} - 61
- 62
///| - 63
/// 区域视图通道数。 - 64
pub fn region_channels(v : @types.ImageRegion) -> Int32 { - 65○
v.channels() - 66
} - 67
- 68
///| - 69
/// 读区域内单通道字节(坐标相对区域左上角,越界返回 0)。 - 70
pub fn region_get( - 71
v : @types.ImageRegion, - 72
x : Int32, - 73
y : Int32, - 74
c : Int32, - 75
) -> Byte { - 76○
v.get(x, y, c) - 77
} - 78
- 79
///| - 80
/// 读区域内一个像素的全部通道。 - 81
pub fn region_pixel( - 82
v : @types.ImageRegion, - 83
x : Int32, - 84
y : Int32, - 85
) -> Array[Byte] { - 86○
v.pixel(x, y) - 87
} - 88
- 89
///| - 90
/// 默认分配预算(512 MiB)。 - 91
pub fn alloc_budget_default() -> @types.AllocBudget { - 92○
@types.AllocBudget::default_budget() - 93
} - 94
- 95
///| - 96
/// 大图直接出缩略图(面积平均重采样,唯一分配 = 输出图)。 - 97
pub fn thumbnail( - 98
img : @types.Image, - 99
max_side : Int32, - 100
) -> @types.Image raise @types.LoadError { - 101○
@transform.thumbnail(img, max_side) - 102
} - 103
- 104
///| - 105
/// 带预算的缩略图:输出超预算直接拒(不分配)。 - 106
pub fn thumbnail_budgeted( - 107
img : @types.Image, - 108
max_side : Int32, - 109
budget : @types.AllocBudget, - 110
) -> @types.Image raise @types.ImageError { - 111○
@transform.thumbnail_budgeted(img, max_side, budget) - 112
} - 113
- 114
///| - 115
/// 缩略图输出尺寸(先算后分配)。 - 116
pub fn thumbnail_dims( - 117
width : Int32, - 118
height : Int32, - 119
max_side : Int32, - 120
) -> (Int32, Int32) { - 121○
@transform.thumbnail_dims(width, height, max_side) - 122
} - 123
- 124
///| - 125
/// 把区域视图物化为独立 `Image`(唯一一次分配)。 - 126
pub fn region_to_image(v : @types.ImageRegion) -> @types.Image { - 127○
v.to_image() - 128
} - 129
- 130
///| - 131
/// 编解码(格式自动识别、按格式输出、WebP 无损) - 132
pub using @lib { - 133
type EncodedImage, - 134
has_alpha, - 135
best_format, - 136
encode_best, - 137
encode_best_limited, - 138
load_from_bytes_auto, - 139
load_16_from_bytes_auto, - 140
load_any_f, - 141
save_image_auto, - 142
save_image_with_quality, - 143
detect_format, - 144
decode_with_limits, - 145
check_decode_budget, - 146
get_image_summary, - 147
encode_png, - 148
encode_jpeg, - 149
encode_bmp, - 150
encode_qoi, - 151
encode_tga, - 152
encode_gif, - 153
encode_webp_lossless, - 154
decode_webp, - 155
} - 156
- 157
///| - 158
/// 变换(缩放 / 裁切 / 旋转 / 翻转 / 区域裁剪) - 159
pub using @transform { - 160
resize_to_cover, - 161
resize_to_contain, - 162
crop, - 163
crop_region, - 164
resize_subsample, - 165
rotate, - 166
rotate_90, - 167
rotate_180, - 168
rotate_270, - 169
flip_horizontal, - 170
flip_vertical, - 171
}