image.codec\barcode\linear_barcodes.mbt
92.1% · 139 / 151 points · 581 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 线性条码 barcode/linear_barcodes - 3
/// - 4
/// 编解码工具模块 - 5
/// 编解码工具模块 Codec utility module - 6
// 更多一维码支持(v11.3.0) - 7
// Code128 / UPC-A / Code39 解码 - 8
- 9
///| - 10
/// Code128 字符集类型 - 11
#derive(Eq, @debug.Debug) - 12
pub(all) enum Code128Charset { - 13
CodeA - 14
CodeB - 15
CodeC - 16
} - 17
- 18
///| - 19
pub extend Code128Charset with Eq::{not_equal, equal} - 20
- 21
///| - 22
pub extend Code128Charset with @debug.Debug::{to_repr} - 23
- 24
///| - 25
/// Code128 编码表(107个码字) - 26
/// 每个码字对应 11 位的条空模式(3条3空,宽度1-4) - 27
let code128_patterns : Array[Array[Int32]] = [ - 28
[2, 1, 2, 2, 2, 2], // 0 - 29
[2, 2, 2, 1, 2, 2], // 1 - 30
[2, 2, 2, 2, 2, 1], // 2 - 31
[1, 2, 1, 2, 2, 3], // 3 - 32
[1, 2, 1, 3, 2, 2], // 4 - 33
[1, 3, 1, 2, 2, 2], // 5 - 34
[1, 2, 2, 2, 1, 3], // 6 - 35
[1, 2, 2, 3, 1, 2], // 7 - 36
[1, 3, 2, 2, 1, 2], // 8 - 37
[2, 2, 1, 2, 1, 3], // 9 - 38
[2, 2, 1, 3, 1, 2], // 10 - 39
[2, 3, 1, 2, 1, 2], // 11 - 40
[1, 1, 2, 2, 3, 2], // 12 - 41
[1, 2, 2, 1, 3, 2], // 13 - 42
[1, 2, 2, 2, 3, 1], // 14 - 43
[1, 1, 3, 2, 2, 2], // 15 - 44
[1, 2, 3, 1, 2, 2], // 16 - 45
[1, 2, 3, 2, 2, 1], // 17 - 46
[2, 2, 3, 2, 1, 1], // 18 - 47
[2, 2, 1, 1, 3, 2], // 19 - 48
[2, 2, 1, 2, 3, 1], // 20 - 49
[2, 1, 3, 2, 1, 2], // 21 - 50
[2, 2, 3, 1, 1, 2], // 22 - 51
[3, 1, 2, 1, 3, 1], // 23 - 52
[3, 1, 1, 2, 2, 2], // 24 - 53
[3, 2, 1, 1, 2, 2], // 25 - 54
[3, 2, 1, 2, 2, 1], // 26 - 55
[3, 1, 2, 2, 1, 2], // 27 - 56
[3, 2, 2, 1, 1, 2], // 28 - 57
[3, 2, 2, 2, 1, 1], // 29 - 58
[2, 1, 2, 1, 2, 3], // 30 - 59
[2, 1, 2, 3, 2, 1], // 31 - 60
[2, 3, 2, 1, 2, 1], // 32 - 61
[1, 1, 1, 3, 2, 3], // 33 - 62
[1, 3, 1, 1, 2, 3], // 34 - 63
[1, 3, 1, 3, 2, 1], // 35 - 64
[1, 1, 2, 3, 1, 3], // 36 - 65
[1, 3, 2, 1, 1, 3], // 37 - 66
[1, 3, 2, 3, 1, 1], // 38 - 67
[2, 1, 1, 3, 1, 3], // 39 - 68
[2, 3, 1, 1, 1, 3], // 40 - 69
[2, 3, 1, 3, 1, 1], // 41 - 70
[1, 1, 2, 1, 3, 3], // 42 - 71
[1, 1, 2, 3, 3, 1], // 43 - 72
[1, 3, 2, 1, 3, 1], // 44 - 73
[1, 1, 3, 1, 2, 3], // 45 - 74
[1, 1, 3, 3, 2, 1], // 46 - 75
[1, 3, 3, 1, 2, 1], // 47 - 76
[3, 1, 3, 1, 2, 1], // 48 - 77
[2, 1, 1, 3, 3, 1], // 49 - 78
[2, 3, 1, 1, 3, 1], // 50 - 79
[2, 1, 3, 1, 1, 3], // 51 - 80
[2, 1, 3, 3, 1, 1], // 52 - 81
[2, 1, 3, 1, 3, 1], // 53 - 82
[3, 1, 1, 1, 2, 3], // 54 - 83
[3, 1, 1, 3, 2, 1], // 55 - 84
[3, 3, 1, 1, 2, 1], // 56 - 85
[3, 1, 2, 1, 1, 3], // 57 - 86
[3, 1, 2, 3, 1, 1], // 58 - 87
[3, 3, 2, 1, 1, 1], // 59 - 88
[3, 1, 4, 1, 1, 1], // 60 - 89
[2, 2, 1, 4, 1, 1], // 61 - 90
[4, 3, 1, 1, 1, 1], // 62 - 91
[1, 1, 1, 2, 2, 4], // 63 - 92
[1, 1, 1, 4, 2, 2], // 64 - 93
[1, 2, 1, 1, 2, 4], // 65 - 94
[1, 2, 1, 4, 2, 1], // 66 - 95
[1, 4, 1, 1, 2, 2], // 67 - 96
[1, 4, 1, 2, 2, 1], // 68 - 97
[1, 1, 2, 2, 1, 4], // 69 - 98
[1, 1, 2, 4, 1, 2], // 70 - 99
[1, 2, 2, 1, 1, 4], // 71 - 100
[1, 2, 2, 4, 1, 1], // 72 - 101
[1, 4, 2, 1, 1, 2], // 73 - 102
[1, 4, 2, 2, 1, 1], // 74 - 103
[2, 4, 1, 2, 1, 1], // 75 - 104
[2, 2, 1, 1, 1, 4], // 76 - 105
[4, 1, 3, 1, 1, 1], // 77 - 106
[2, 4, 1, 1, 1, 2], // 78 - 107
[1, 3, 4, 1, 1, 1], // 79 - 108
[1, 1, 1, 2, 4, 2], // 80 - 109
[1, 2, 1, 1, 4, 2], // 81 - 110
[1, 2, 1, 2, 4, 1], // 82 - 111
[1, 1, 4, 2, 1, 2], // 83 - 112
[1, 2, 4, 1, 1, 2], // 84 - 113
[1, 2, 4, 2, 1, 1], // 85 - 114
[4, 1, 1, 2, 1, 2], // 86 - 115
[4, 2, 1, 1, 1, 2], // 87 - 116
[4, 2, 1, 2, 1, 1], // 88 - 117
[2, 1, 2, 1, 4, 1], // 89 - 118
[2, 1, 4, 1, 2, 1], // 90 - 119
[4, 1, 2, 1, 2, 1], // 91 - 120
[1, 1, 1, 1, 4, 3], // 92 - 121
[1, 1, 1, 3, 4, 1], // 93 - 122
[1, 3, 1, 1, 4, 1], // 94 - 123
[1, 1, 4, 1, 1, 3], // 95 - 124
[1, 1, 4, 3, 1, 1], // 96 - 125
[4, 1, 1, 1, 1, 3], // 97 - 126
[4, 1, 1, 3, 1, 1], // 98 - 127
[1, 1, 3, 1, 4, 1], // 99 - 128
[1, 1, 4, 1, 3, 1], // 100 - 129
[3, 1, 1, 1, 4, 1], // 101 - 130
[4, 1, 1, 1, 3, 1], // 102 - 131
[2, 1, 1, 4, 1, 2], // 103 (Start A) - 132
[2, 1, 1, 2, 1, 4], // 104 (Start B) - 133
[2, 1, 1, 2, 3, 2], // 105 (Start C) - 134
] - 135
- 136
///| - 137
/// Code128 Stop 符(码字 106)——7 段 13 模块,与数据符的 6 段 11 模块不同形, - 138
/// 因此不能塞进上面的 6 段表。旧实现曾用 [2,1,1,2,2,3](11 模块)冒充 Stop, - 139
/// 生成的条码对标准扫码器不可读(S22 修复)。 - 140
let code128_stop_pattern : Array[Int32] = [2, 3, 3, 1, 1, 1, 2] - 141
- 142
///| - 143
/// Code128 字符集 A 的字符映射(0-95) - 144
fn code128_char_a(code : Int32) -> String { - 145●
if code >= 0 && code <= 95 { - 146●
if code < 64 { - 147●
(code + 32).to_char().map(c => c.to_string()).unwrap_or("") - 148
} else { - 149
// 控制字符 - 150●
(code - 64).to_char().map(c => c.to_string()).unwrap_or("") - 151
} - 152
} else { - 153○
"?" - 154
} - 155
} - 156
- 157
///| - 158
/// Code128 字符集 B 的字符映射(0-95) - 159
fn code128_char_b(code : Int32) -> String { - 160●
if code >= 0 && code <= 95 { - 161●
(code + 32).to_char().map(c => c.to_string()).unwrap_or("") - 162
} else { - 163●
"?" - 164
} - 165
} - 166
- 167
///| - 168
/// 识别 Code128 条形码 - 169
pub fn decode_code128( - 170
img : @types.Image, - 171
) -> BarcodeResult? raise @types.LoadError { - 172
// 输入验证 - 173●
if img.width <= 0 || img.height <= 0 { - 174●
raise @types.LoadError::DecodeFailed( - 175
"decode_code128: 图像尺寸必须大于0", - 176
) - 177
} - 178
if img.channels < 1 || img.channels > 4 { - 179●
raise @types.LoadError::DecodeFailed( - 180
"decode_code128: 通道数必须在1-4之间", - 181
) - 182
} - 183
let expected_size = img.width * img.height * img.channels - 184●
if img.data.length() != expected_size { - 185●
raise @types.LoadError::DecodeFailed( - 186
"decode_code128: 数据大小不匹配", - 187
) - 188
} - 189
let w = img.width - 190
let h = img.height - 191
let data = img.data - 192
// 在中间扫描线尝试解码 - 193
let y = h / 2 - 194
let scan_line : Array[Int32] = [] - 195
for x in 0..<w { - 196●
scan_line.push(if data[y * w + x].to_int() < 128 { 1 } else { 0 }) - 197
} - 198
// 寻找起始符(Code A/B/C) - 199
let start_patterns = [ - 200
(103, code128_patterns[103]), // Start A - 201
(104, code128_patterns[104]), // Start B - 202
(105, code128_patterns[105]), // Start C - 203
] - 204
let mut start_idx = -1 - 205
let mut start_code = 0 - 206
for i in 0..<(w - 20) { - 207●
for _tup0 in start_patterns { - 208●
let (code, pattern) = _tup0 - 209●
if match_bar_pattern(scan_line, i, pattern) { - 210●
start_idx = i - 211
start_code = code - 212
break - 213
} - 214
} - 215
if start_idx >= 0 { - 216●
break - 217
} - 218
} - 219
if start_idx < 0 { - 220●
return None - 221
} - 222
// 确定字符集 - 223●
let charset = match start_code { - 224●
103 => Code128Charset::CodeA - 225●
104 => Code128Charset::CodeB - 226●
105 => Code128Charset::CodeC - 227○
_ => Code128Charset::CodeB - 228
} - 229
// 解码数据码字 - 230
let mut pos = start_idx + 11 // 起始符占 11 个模块 - 231
let codes : Array[Int32] = [] - 232
let mut checksum = start_code - 233
let mut code_count = 0 - 234
while pos < w - 13 { - 235
// Stop 是 7 段 13 模块,比数据符长,必须先匹配,否则会被当成数据符或直接漏掉 - 236●
if match_bar_pattern(scan_line, pos, code128_stop_pattern) { - 237●
pos += 13 - 238
break - 239
} - 240
// 匹配一个码字(6 个条空,11 个模块) - 241●
let (matched_code, matched_width) = match_code128_symbol(scan_line, pos) - 242
if matched_code < 0 { - 243●
break - 244
} - 245●
codes.push(matched_code) - 246
code_count += 1 - 247
checksum += matched_code * code_count - 248
pos += matched_width - 249
} - 250●
if codes.length() < 2 { - 251●
return None - 252
} - 253
// 验证校验位 - 254
let expected_checksum = checksum % 103 - 255●
let actual_checksum = codes[codes.length() - 1] - 256
let valid = expected_checksum == actual_checksum - 257
// 解码数据 - 258
let mut result = "" - 259
let mut current_charset = charset - 260●
for i in 0..<(codes.length() - 1) { - 261●
let code = codes[i] - 262
// 处理字符集切换 - 263
if code == 101 { // Code A - 264●
current_charset = Code128Charset::CodeA - 265
continue - 266●
} else if code == 100 { // Code B - 267●
current_charset = Code128Charset::CodeB - 268
continue - 269●
} else if code == 99 { // Code C - 270●
current_charset = Code128Charset::CodeC - 271
continue - 272
} - 273●
match current_charset { - 274●
Code128Charset::CodeA => result += code128_char_a(code) - 275●
Code128Charset::CodeB => result += code128_char_b(code) - 276●
Code128Charset::CodeC => { - 277
// Code C: 两个数字一个码字 - 278
let d1 = code / 10 - 279
let d2 = code % 10 - 280●
result += d1.to_string() - 281●
result += d2.to_string() - 282
} - 283
} - 284
} - 285●
let confidence = if valid { 0.9 } else { 0.5 } - 286
Some(BarcodeResult::{ - 287
barcode_type: BarcodeType::Code128, - 288
data: result, - 289
confidence, - 290
x: start_idx, - 291
y, - 292
width: pos - start_idx, - 293
height: 1, - 294
}) - 295
} - 296
- 297
///| - 298
/// 匹配条空模式 - 299
fn match_bar_pattern( - 300
scan_line : Array[Int32], - 301
start : Int32, - 302
pattern : Array[Int32], - 303
) -> Bool { - 304●
let mut pos = start - 305
let mut is_bar = true - 306
for width in pattern { - 307●
for _ in 0..<width { - 308●
if pos >= scan_line.length() { - 309○
return false - 310
} - 311●
let expected = if is_bar { 1 } else { 0 } - 312
if scan_line[pos] != expected { - 313●
return false - 314
} - 315
pos += 1 - 316
} - 317
is_bar = !is_bar - 318
} - 319
true - 320
} - 321
- 322
///| - 323
/// 匹配 Code128 码字 - 324
fn match_code128_symbol( - 325
scan_line : Array[Int32], - 326
start : Int32, - 327
) -> (Int32, Int32) { - 328
// 尝试匹配 106 个数据/起始/切换码字(0–105);Stop 不在此表,见 code128_stop_pattern - 329●
for code in 0..<106 { - 330●
let pattern = code128_patterns[code] - 331
let mut total_width = 0 - 332
for w in pattern { - 333●
total_width += w - 334
} - 335●
if match_bar_pattern(scan_line, start, pattern) { - 336●
return (code, total_width) - 337
} - 338
} - 339
(-1, 0) - 340
} - 341
- 342
///| - 343
/// 识别 UPC-A 条形码 - 344
pub fn decode_upca(img : @types.Image) -> BarcodeResult? raise @types.LoadError { - 345
// 输入验证 - 346●
if img.width <= 0 || img.height <= 0 { - 347●
raise @types.LoadError::DecodeFailed( - 348
"decode_upca: 图像尺寸必须大于0", - 349
) - 350
} - 351
if img.channels < 1 || img.channels > 4 { - 352●
raise @types.LoadError::DecodeFailed( - 353
"decode_upca: 通道数必须在1-4之间", - 354
) - 355
} - 356
let expected_size = img.width * img.height * img.channels - 357●
if img.data.length() != expected_size { - 358●
raise @types.LoadError::DecodeFailed("decode_upca: 数据大小不匹配") - 359
} - 360
// UPC-A 与 EAN-13 兼容(UPC-A 是 EAN-13 第一位为 0 的特例) - 361●
let result = decode_ean13(img) - 362●
match result { - 363
Some(r) => - 364●
if r.data.length() == 13 && r.data[0:1].to_owned() == "0" { - 365
// 去掉前导 0,转换为 UPC-A(用切片避免 String 索引的 Byte/Char 差异) - 366●
let upca = r.data[1:13].to_owned() - 367
Some(BarcodeResult::{ - 368
barcode_type: BarcodeType::UpcA, - 369
data: upca, - 370
confidence: r.confidence, - 371
x: r.x, - 372
y: r.y, - 373
width: r.width, - 374
height: r.height, - 375
}) - 376
} else { - 377○
None - 378
} - 379●
None => None - 380
} - 381
} - 382
- 383
///| - 384
/// Code39 编码表 - 385
let code39_chars : Array[String] = [ - 386
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", - 387
"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", - 388
"W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", - 389
] - 390
- 391
///| - 392
/// Code39 条空模式(9个元素:5条4空,3宽6窄) - 393
let code39_patterns : Array[Array[Int32]] = [ - 394
[1, 1, 1, 2, 2, 1, 2, 1, 1], // 0 - 395
[2, 1, 1, 2, 1, 1, 1, 1, 2], // 1 - 396
[1, 1, 2, 2, 1, 1, 1, 1, 2], // 2 - 397
[2, 1, 2, 2, 1, 1, 1, 1, 1], // 3 - 398
[1, 1, 1, 2, 2, 1, 1, 1, 2], // 4 - 399
[2, 1, 1, 2, 2, 1, 1, 1, 1], // 5 - 400
[1, 1, 2, 2, 2, 1, 1, 1, 1], // 6 - 401
[1, 1, 1, 2, 1, 1, 2, 1, 2], // 7 - 402
[2, 1, 1, 2, 1, 1, 2, 1, 1], // 8 - 403
[1, 1, 2, 2, 1, 1, 2, 1, 1], // 9 - 404
[2, 1, 1, 1, 1, 2, 1, 1, 2], // A - 405
[1, 1, 2, 1, 1, 2, 1, 1, 2], // B - 406
[2, 1, 2, 1, 1, 2, 1, 1, 1], // C - 407
[1, 1, 1, 1, 2, 2, 1, 1, 2], // D - 408
[2, 1, 1, 1, 2, 2, 1, 1, 1], // E - 409
[1, 1, 2, 1, 2, 2, 1, 1, 1], // F - 410
[1, 1, 1, 1, 1, 2, 2, 1, 2], // G - 411
[2, 1, 1, 1, 1, 2, 2, 1, 1], // H - 412
[1, 1, 2, 1, 1, 2, 2, 1, 1], // I - 413
[1, 1, 1, 1, 2, 2, 2, 1, 1], // J - 414
[2, 1, 1, 1, 1, 1, 1, 2, 2], // K - 415
[1, 1, 2, 1, 1, 1, 1, 2, 2], // L - 416
[2, 1, 2, 1, 1, 1, 1, 2, 1], // M - 417
[1, 1, 1, 1, 2, 1, 1, 2, 2], // N - 418
[2, 1, 1, 1, 2, 1, 1, 2, 1], // O - 419
[1, 1, 2, 1, 2, 1, 1, 2, 1], // P - 420
[1, 1, 1, 1, 1, 1, 2, 2, 2], // Q - 421
[2, 1, 1, 1, 1, 1, 2, 2, 1], // R - 422
[1, 1, 2, 1, 1, 1, 2, 2, 1], // S - 423
[1, 1, 1, 1, 2, 1, 2, 2, 1], // T - 424
[2, 2, 1, 1, 1, 1, 1, 1, 2], // U - 425
[1, 2, 2, 1, 1, 1, 1, 1, 2], // V - 426
[2, 2, 2, 1, 1, 1, 1, 1, 1], // W - 427
[1, 2, 1, 1, 2, 1, 1, 1, 2], // X - 428
[2, 2, 1, 1, 2, 1, 1, 1, 1], // Y - 429
[1, 2, 2, 1, 2, 1, 1, 1, 1], // Z - 430
[1, 2, 1, 1, 1, 1, 2, 1, 2], // - - 431
[2, 2, 1, 1, 1, 1, 2, 1, 1], // . - 432
[1, 2, 2, 1, 1, 1, 2, 1, 1], // (space) - 433
[1, 2, 1, 2, 1, 2, 1, 1, 1], // $ - 434
[1, 2, 1, 2, 1, 1, 1, 2, 1], // / - 435
[1, 2, 1, 1, 1, 2, 1, 2, 1], // + - 436
[1, 1, 1, 2, 1, 2, 1, 2, 1], // % - 437
] - 438
- 439
///| - 440
/// Code39 起始/终止符模式(*) - 441
let code39_start_pattern : Array[Int32] = [1, 2, 1, 1, 2, 1, 2, 1, 1] - 442
- 443
///| - 444
/// 识别 Code39 条形码 - 445
pub fn decode_code39( - 446
img : @types.Image, - 447
) -> BarcodeResult? raise @types.LoadError { - 448
// 输入验证 - 449●
if img.width <= 0 || img.height <= 0 { - 450●
raise @types.LoadError::DecodeFailed( - 451
"decode_code39: 图像尺寸必须大于0", - 452
) - 453
} - 454
if img.channels < 1 || img.channels > 4 { - 455●
raise @types.LoadError::DecodeFailed( - 456
"decode_code39: 通道数必须在1-4之间", - 457
) - 458
} - 459
let expected_size = img.width * img.height * img.channels - 460●
if img.data.length() != expected_size { - 461●
raise @types.LoadError::DecodeFailed("decode_code39: 数据大小不匹配") - 462
} - 463
let w = img.width - 464
let h = img.height - 465
let data = img.data - 466
let y = h / 2 - 467
let scan_line : Array[Int32] = [] - 468
for x in 0..<w { - 469●
scan_line.push(if data[y * w + x].to_int() < 128 { 1 } else { 0 }) - 470
} - 471
// 寻找起始符 * - 472
let mut start_idx = -1 - 473
for i in 0..<(w - 20) { - 474●
if match_bar_pattern(scan_line, i, code39_start_pattern) { - 475●
start_idx = i - 476
break - 477
} - 478
} - 479
if start_idx < 0 { - 480●
return None - 481
} - 482
// 解码数据字符 - 483
let mut pos = start_idx + 10 // 起始符 + 间隔 - 484
let result_chars : Array[String] = [] - 485
while pos < w - 15 { - 486
// 跳过空白间隔 - 487●
while pos < w && scan_line[pos] == 0 { - 488●
pos += 1 - 489
} - 490
if pos >= w - 9 { - 491●
break - 492
} - 493
// 检查是否是终止符 - 494●
if match_bar_pattern(scan_line, pos, code39_start_pattern) { - 495○
break - 496
} - 497
// 匹配数据字符 - 498
let mut matched = false - 499●
for code in 0..<code39_patterns.length() { - 500●
if match_bar_pattern(scan_line, pos, code39_patterns[code]) { - 501●
result_chars.push(code39_chars[code]) - 502
let mut total_width = 0 - 503
for width in code39_patterns[code] { - 504●
total_width += width - 505
} - 506
pos += total_width + 1 // 字符 + 间隔 - 507
matched = true - 508
break - 509
} - 510
} - 511
if !matched { - 512●
pos += 1 - 513
} - 514
} - 515●
if result_chars.length() == 0 { - 516○
return None - 517
} - 518
let mut result = "" - 519
for c in result_chars { - 520●
result += c - 521
} - 522
Some(BarcodeResult::{ - 523
barcode_type: BarcodeType::Code128, // 复用类型 - 524
data: result, - 525
confidence: 0.8, - 526
x: start_idx, - 527
y, - 528
width: pos - start_idx, - 529
height: 1, - 530
}) - 531
} - 532
- 533
///| - 534
/// 通用一维码识别(自动尝试所有类型) - 535
pub fn decode_linear_barcode( - 536
img : @types.Image, - 537
) -> Array[BarcodeResult] raise @types.LoadError { - 538
// 输入验证 - 539●
if img.width <= 0 || img.height <= 0 { - 540●
raise @types.LoadError::DecodeFailed( - 541
"decode_linear_barcode: 图像尺寸必须大于0", - 542
) - 543
} - 544
if img.channels < 1 || img.channels > 4 { - 545●
raise @types.LoadError::DecodeFailed( - 546
"decode_linear_barcode: 通道数必须在1-4之间", - 547
) - 548
} - 549
let expected_size = img.width * img.height * img.channels - 550●
if img.data.length() != expected_size { - 551●
raise @types.LoadError::DecodeFailed( - 552
"decode_linear_barcode: 数据大小不匹配", - 553
) - 554
} - 555
let results : Array[BarcodeResult] = [] - 556
// 尝试 EAN-13 - 557●
let ean13 = decode_ean13(img) - 558●
match ean13 { - 559○
Some(r) => results.push(r) - 560●
None => ignore(()) - 561
} - 562
// 尝试 UPC-A - 563●
let upca = decode_upca(img) - 564●
match upca { - 565○
Some(r) => results.push(r) - 566●
None => ignore(()) - 567
} - 568
// 尝试 Code128 - 569●
let code128 = decode_code128(img) - 570●
match code128 { - 571○
Some(r) => results.push(r) - 572●
None => ignore(()) - 573
} - 574
// 尝试 Code39 - 575●
let code39 = decode_code39(img) - 576●
match code39 { - 577●
Some(r) => results.push(r) - 578●
None => ignore(()) - 579
} - 580
results - 581
}