image.vision\imgir\ir_op.mbt
76.1% · 54 / 71 points · 173 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # IR 操作 imgir/ir_op - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// ImgIR 操作类型 + 管道:统一图像/场/时空操作的表达式。 - 7
// IR operation types + pipeline: unified image/field/spatiotemporal operations. - 8
// - 9
// 操作分类: - 10
// 图像变换: Resize / Rotate90 / FlipH / FlipV / Crop / ToGray - 11
// 色彩调整: Brightness / GaussianBlur / BoxBlur / Sharpen - 12
// 场操作: ToScalarField / FieldGradient / FieldLaplacian / FieldIntegrate / - 13
// FieldClamp / FieldMask / ScalarFieldToImage - 14
// 时空操作: STSnapshot / STInterpolate - 15
- 16
///| - 17
/// IR 操作:统一图像/场/时空操作枚举。 - 18
/// IR 操作:统一图像/场/时空操作枚举 IR operation: unified image/field/spatiotemporal operation enum. - 19
/// `#non_exhaustive` 表示未来可能添加新构造器 - 20
#derive(Eq, @debug.Debug) - 21
#non_exhaustive - 22
pub(all) enum IROp { - 23
// 图像变换 - 24
Resize(Int32, Int32) // 缩放到 (w, h) - 25
Rotate90 // 旋转 90° - 26
FlipH // 水平翻转 - 27
FlipV // 垂直翻转 - 28
Crop(Int32, Int32, Int32, Int32) // 裁剪 (x, y, w, h) - 29
ToGray // 转灰度 - 30
// 色彩/滤波 - 31
Brightness(Int32) // 亮度调整 delta - 32
GaussianBlur(Int32, Float) // 高斯模糊 (radius, sigma) - 33
BoxBlur(Int32) // 均值模糊 (radius) - 34
Sharpen(Float) // 锐化 (amount) - 35
// 场操作 - 36
ToScalarField // Image → ScalarField - 37
FieldGradient // ScalarField → VectorField - 38
FieldLaplacian // ScalarField → ScalarField - 39
FieldIntegrate // ScalarField → Float - 40
FieldClamp(Float, Float) // ScalarField → ScalarField (lo, hi) - 41
FieldMask(Float) // ScalarField → ScalarField (threshold) - 42
ScalarFieldToImage // ScalarField → Image - 43
// 时空操作 - 44
STSnapshot(Float) // TImage → Image (time) - 45
STInterpolate(Float) // TImage → Image (time) - 46
} - 47
- 48
///| - 49
pub extend IROp with @debug.Debug::{to_repr} - 50
- 51
///| - 52
pub extend IROp with Eq::{not_equal, equal} - 53
- 54
///| - 55
/// IR 管道:线性操作序列,按顺序执行。 - 56
/// IR 管线 IR pipeline - 57
#derive(Eq, @debug.Debug) - 58
pub(all) struct IRPipeline { - 59
ops : Array[IROp] - 60
} - 61
- 62
///| - 63
pub extend IRPipeline with @debug.Debug::{to_repr} - 64
- 65
///| - 66
pub extend IRPipeline with Eq::{not_equal, equal} - 67
- 68
///| - 69
/// 创建空管道。 - 70
/// 创建空管线 Create an empty pipeline. - 71
pub fn IRPipeline::new() -> IRPipeline { - 72●
{ ops: [], } - 73
} - 74
- 75
///| - 76
/// 管道操作数。 - 77
/// 管线中操作数 Number of operations in the pipeline. - 78
pub fn IRPipeline::length(self : IRPipeline) -> Int32 { - 79●
self.ops.length() - 80
} - 81
- 82
///| - 83
/// 追加操作到管道末尾,返回新管道。 - 84
/// 追加操作到管线,返回新管线 Append an operation to the pipeline, returns a new pipeline. - 85
pub fn IRPipeline::add(self : IRPipeline, op : IROp) -> IRPipeline { - 86●
let new_ops = [] - 87●
for i in 0..<self.ops.length() { - 88●
new_ops.push(self.ops[i]) - 89
} - 90●
new_ops.push(op) - 91
{ ops: new_ops, } - 92
} - 93
- 94
///| - 95
/// 获取操作类型标签字符串。 - 96
/// 获取操作类型标签字符串 Get operation type tag string. - 97
pub fn IROp::tag(self : IROp) -> String { - 98●
match self { - 99●
Resize(_, _) => "Resize" - 100●
Rotate90 => "Rotate90" - 101●
FlipH => "FlipH" - 102●
FlipV => "FlipV" - 103●
Crop(_, _, _, _) => "Crop" - 104●
ToGray => "ToGray" - 105●
Brightness(_) => "Brightness" - 106●
GaussianBlur(_, _) => "GaussianBlur" - 107●
BoxBlur(_) => "BoxBlur" - 108●
Sharpen(_) => "Sharpen" - 109●
ToScalarField => "ToScalarField" - 110●
FieldGradient => "FieldGradient" - 111●
FieldLaplacian => "FieldLaplacian" - 112●
FieldIntegrate => "FieldIntegrate" - 113●
FieldClamp(_, _) => "FieldClamp" - 114●
FieldMask(_) => "FieldMask" - 115●
ScalarFieldToImage => "ScalarFieldToImage" - 116●
STSnapshot(_) => "STSnapshot" - 117●
STInterpolate(_) => "STInterpolate" - 118
} - 119
} - 120
- 121
///| - 122
/// 获取操作的输入类型标签。 - 123
/// 获取操作的预期输入类型标签 Get expected input type tag for an operation. - 124
pub fn IROp::input_tag(self : IROp) -> String { - 125●
match self { - 126●
Resize(_, _) => "Image" - 127○
Rotate90 => "Image" - 128●
FlipH => "Image" - 129○
FlipV => "Image" - 130○
Crop(_, _, _, _) => "Image" - 131●
ToGray => "Image" - 132○
Brightness(_) => "Image" - 133●
GaussianBlur(_, _) => "Image" - 134○
BoxBlur(_) => "Image" - 135●
Sharpen(_) => "Image" - 136●
ToScalarField => "Image" - 137●
FieldGradient => "ScalarField" - 138●
FieldLaplacian => "ScalarField" - 139○
FieldIntegrate => "ScalarField" - 140●
FieldClamp(_, _) => "ScalarField" - 141○
FieldMask(_) => "ScalarField" - 142●
ScalarFieldToImage => "ScalarField" - 143●
STSnapshot(_) => "TImage" - 144○
STInterpolate(_) => "TImage" - 145
} - 146
} - 147
- 148
///| - 149
/// 获取操作的输出类型标签。 - 150
/// 获取操作的预期输出类型标签 Get expected output type tag for an operation. - 151
pub fn IROp::output_tag(self : IROp) -> String { - 152●
match self { - 153●
Resize(_, _) => "Image" - 154○
Rotate90 => "Image" - 155○
FlipH => "Image" - 156○
FlipV => "Image" - 157○
Crop(_, _, _, _) => "Image" - 158●
ToGray => "Image" - 159○
Brightness(_) => "Image" - 160●
GaussianBlur(_, _) => "Image" - 161○
BoxBlur(_) => "Image" - 162●
Sharpen(_) => "Image" - 163●
ToScalarField => "ScalarField" - 164●
FieldGradient => "VectorField" - 165●
FieldLaplacian => "ScalarField" - 166○
FieldIntegrate => "Float" - 167●
FieldClamp(_, _) => "ScalarField" - 168○
FieldMask(_) => "ScalarField" - 169●
ScalarFieldToImage => "Image" - 170●
STSnapshot(_) => "Image" - 171○
STInterpolate(_) => "Image" - 172
} - 173
}