image.process\transform\transform_16f.mbt
100% · 72 / 72 points · 315 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 图像变换 16-bit/float 变体 Image transforms 16-bit/float variants - 3
/// - 4
/// 16位旋转/翻转 rotate_16 / flip_16 - 5
/// 16位/浮点旋转/翻转变换 16-bit/float rotate/flip transforms - 6
// 图像变换 16-bit/float 变体:rotate / flip - 7
// 支持 Image16 / ImageF 两种类型 - 8
- 9
///| - 10
/// @see rotate_90 8-bit 版本,本函数为 Image16 变体 - 11
pub fn rotate_90_16(img : @types.Image16) -> @types.Image16 { - 12●
let ch = img.channels - 13
let new_w = img.height - 14
let new_h = img.width - 15
let bpp = ch * 2 - 16●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 17
for y in 0..<img.height { - 18●
for x in 0..<img.width { - 19●
let nx = img.height - 1 - y - 20
let ny = x - 21
let src = (y * img.width + x) * bpp - 22
let dst = (ny * new_w + nx) * bpp - 23
for i in 0..<bpp { - 24●
out[dst + i] = img.data[src + i] - 25
} - 26
} - 27
} - 28
@types.Image16::{ - 29
width: new_w, - 30
height: new_h, - 31
channels: ch, - 32●
data: Bytes::from_array(out), - 33
} - 34
} - 35
- 36
///| - 37
/// @see rotate_90 8-bit 版本,本函数为 ImageF 变体 - 38
pub fn rotate_90_f(img : @types.ImageF) -> @types.ImageF { - 39●
let ch = img.channels - 40
let new_w = img.height - 41
let new_h = img.width - 42
let bpp = ch * 4 - 43●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 44
for y in 0..<img.height { - 45●
for x in 0..<img.width { - 46●
let nx = img.height - 1 - y - 47
let ny = x - 48
let src = (y * img.width + x) * bpp - 49
let dst = (ny * new_w + nx) * bpp - 50
for i in 0..<bpp { - 51●
out[dst + i] = img.data[src + i] - 52
} - 53
} - 54
} - 55
@types.ImageF::{ - 56
width: new_w, - 57
height: new_h, - 58
channels: ch, - 59●
data: Bytes::from_array(out), - 60
} - 61
} - 62
- 63
///| - 64
/// @see rotate_180 8-bit 版本,本函数为 Image16 变体 - 65
pub fn rotate_180_16(img : @types.Image16) -> @types.Image16 { - 66●
let ch = img.channels - 67
let bpp = ch * 2 - 68●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 69
for y in 0..<img.height { - 70●
for x in 0..<img.width { - 71●
let nx = img.width - 1 - x - 72
let ny = img.height - 1 - y - 73
let src = (y * img.width + x) * bpp - 74
let dst = (ny * img.width + nx) * bpp - 75
for i in 0..<bpp { - 76●
out[dst + i] = img.data[src + i] - 77
} - 78
} - 79
} - 80
@types.Image16::{ - 81
width: img.width, - 82
height: img.height, - 83
channels: ch, - 84●
data: Bytes::from_array(out), - 85
} - 86
} - 87
- 88
///| - 89
/// @see rotate_180 8-bit 版本,本函数为 ImageF 变体 - 90
pub fn rotate_180_f(img : @types.ImageF) -> @types.ImageF { - 91●
let ch = img.channels - 92
let bpp = ch * 4 - 93●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 94
for y in 0..<img.height { - 95●
for x in 0..<img.width { - 96●
let nx = img.width - 1 - x - 97
let ny = img.height - 1 - y - 98
let src = (y * img.width + x) * bpp - 99
let dst = (ny * img.width + nx) * bpp - 100
for i in 0..<bpp { - 101●
out[dst + i] = img.data[src + i] - 102
} - 103
} - 104
} - 105
@types.ImageF::{ - 106
width: img.width, - 107
height: img.height, - 108
channels: ch, - 109●
data: Bytes::from_array(out), - 110
} - 111
} - 112
- 113
///| - 114
/// @see rotate_270 8-bit 版本,本函数为 Image16 变体 - 115
pub fn rotate_270_16(img : @types.Image16) -> @types.Image16 { - 116●
let ch = img.channels - 117
let new_w = img.height - 118
let new_h = img.width - 119
let bpp = ch * 2 - 120●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 121
for y in 0..<img.height { - 122●
for x in 0..<img.width { - 123●
let nx = y - 124
let ny = img.width - 1 - x - 125
let src = (y * img.width + x) * bpp - 126
let dst = (ny * new_w + nx) * bpp - 127
for i in 0..<bpp { - 128●
out[dst + i] = img.data[src + i] - 129
} - 130
} - 131
} - 132
@types.Image16::{ - 133
width: new_w, - 134
height: new_h, - 135
channels: ch, - 136●
data: Bytes::from_array(out), - 137
} - 138
} - 139
- 140
///| - 141
/// @see rotate_270 8-bit 版本,本函数为 ImageF 变体 - 142
pub fn rotate_270_f(img : @types.ImageF) -> @types.ImageF { - 143●
let ch = img.channels - 144
let new_w = img.height - 145
let new_h = img.width - 146
let bpp = ch * 4 - 147●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 148
for y in 0..<img.height { - 149●
for x in 0..<img.width { - 150●
let nx = y - 151
let ny = img.width - 1 - x - 152
let src = (y * img.width + x) * bpp - 153
let dst = (ny * new_w + nx) * bpp - 154
for i in 0..<bpp { - 155●
out[dst + i] = img.data[src + i] - 156
} - 157
} - 158
} - 159
@types.ImageF::{ - 160
width: new_w, - 161
height: new_h, - 162
channels: ch, - 163●
data: Bytes::from_array(out), - 164
} - 165
} - 166
- 167
///| - 168
/// @see flip_horizontal 8-bit 版本,本函数为 Image16 变体 - 169
pub fn flip_horizontal_16(img : @types.Image16) -> @types.Image16 { - 170●
let ch = img.channels - 171
let bpp = ch * 2 - 172●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 173
for y in 0..<img.height { - 174●
for x in 0..<img.width { - 175●
let nx = img.width - 1 - x - 176
let src = (y * img.width + x) * bpp - 177
let dst = (y * img.width + nx) * bpp - 178
for i in 0..<bpp { - 179●
out[dst + i] = img.data[src + i] - 180
} - 181
} - 182
} - 183
@types.Image16::{ - 184
width: img.width, - 185
height: img.height, - 186
channels: ch, - 187●
data: Bytes::from_array(out), - 188
} - 189
} - 190
- 191
///| - 192
/// @see flip_horizontal 8-bit 版本,本函数为 ImageF 变体 - 193
pub fn flip_horizontal_f(img : @types.ImageF) -> @types.ImageF { - 194●
let ch = img.channels - 195
let bpp = ch * 4 - 196●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 197
for y in 0..<img.height { - 198●
for x in 0..<img.width { - 199●
let nx = img.width - 1 - x - 200
let src = (y * img.width + x) * bpp - 201
let dst = (y * img.width + nx) * bpp - 202
for i in 0..<bpp { - 203●
out[dst + i] = img.data[src + i] - 204
} - 205
} - 206
} - 207
@types.ImageF::{ - 208
width: img.width, - 209
height: img.height, - 210
channels: ch, - 211●
data: Bytes::from_array(out), - 212
} - 213
} - 214
- 215
///| - 216
/// 16-bit 垂直翻转。上下镜像。 - 217
/// @see flip_vertical 8-bit 版本,本函数为 Image16 变体 - 218
pub fn flip_vertical_16(img : @types.Image16) -> @types.Image16 { - 219●
let ch = img.channels - 220
let bpp = ch * 2 - 221●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 222
for y in 0..<img.height { - 223●
let ny = img.height - 1 - y - 224
for x in 0..<img.width { - 225●
let src = (y * img.width + x) * bpp - 226
let dst = (ny * img.width + x) * bpp - 227
for i in 0..<bpp { - 228●
out[dst + i] = img.data[src + i] - 229
} - 230
} - 231
} - 232
@types.Image16::{ - 233
width: img.width, - 234
height: img.height, - 235
channels: ch, - 236●
data: Bytes::from_array(out), - 237
} - 238
} - 239
- 240
///| - 241
/// float 垂直翻转。上下镜像。 - 242
/// @see flip_vertical 8-bit 版本,本函数为 ImageF 变体 - 243
pub fn flip_vertical_f(img : @types.ImageF) -> @types.ImageF { - 244●
let ch = img.channels - 245
let bpp = ch * 4 - 246●
let out : Array[Byte] = Array::make(img.width * img.height * bpp, b'\x00') - 247
for y in 0..<img.height { - 248●
let ny = img.height - 1 - y - 249
for x in 0..<img.width { - 250●
let src = (y * img.width + x) * bpp - 251
let dst = (ny * img.width + x) * bpp - 252
for i in 0..<bpp { - 253●
out[dst + i] = img.data[src + i] - 254
} - 255
} - 256
} - 257
@types.ImageF::{ - 258
width: img.width, - 259
height: img.height, - 260
channels: ch, - 261●
data: Bytes::from_array(out), - 262
} - 263
} - 264
- 265
///| - 266
/// 16-bit 转置。交换宽高,(x,y) -> (y,x)。 - 267
/// @see transpose 8-bit 版本,本函数为 Image16 变体 - 268
pub fn transpose_16(img : @types.Image16) -> @types.Image16 { - 269●
let ch = img.channels - 270
let new_w = img.height - 271
let new_h = img.width - 272
let bpp = ch * 2 - 273●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 274
for y in 0..<img.height { - 275●
for x in 0..<img.width { - 276●
let src = (y * img.width + x) * bpp - 277
let dst = (x * new_w + y) * bpp - 278
for i in 0..<bpp { - 279●
out[dst + i] = img.data[src + i] - 280
} - 281
} - 282
} - 283
@types.Image16::{ - 284
width: new_w, - 285
height: new_h, - 286
channels: ch, - 287●
data: Bytes::from_array(out), - 288
} - 289
} - 290
- 291
///| - 292
/// float 转置。交换宽高,(x,y) -> (y,x)。 - 293
/// @see transpose 8-bit 版本,本函数为 ImageF 变体 - 294
pub fn transpose_f(img : @types.ImageF) -> @types.ImageF { - 295●
let ch = img.channels - 296
let new_w = img.height - 297
let new_h = img.width - 298
let bpp = ch * 4 - 299●
let out : Array[Byte] = Array::make(new_w * new_h * bpp, b'\x00') - 300
for y in 0..<img.height { - 301●
for x in 0..<img.width { - 302●
let src = (y * img.width + x) * bpp - 303
let dst = (x * new_w + y) * bpp - 304
for i in 0..<bpp { - 305●
out[dst + i] = img.data[src + i] - 306
} - 307
} - 308
} - 309
@types.ImageF::{ - 310
width: new_w, - 311
height: new_h, - 312
channels: ch, - 313●
data: Bytes::from_array(out), - 314
} - 315
}