image.vision\imgir\ir_op.mbt

76.1% · 54 / 71 points · 173 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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