rxing 0.8.5

A rust port of the zxing barcode library.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
use std::io::Read;

use image::DynamicImage;
use rxing::{Dimension, Reader, Writer};

#[test]
fn issue_27_part_2() {
    let mut data = Vec::new();
    std::fs::File::open("test_resources/blackbox/github_issue_cases/panic_data2_issue_27.bin")
        .unwrap()
        .read_to_end(&mut data)
        .unwrap();

    rxing::helpers::detect_multiple_in_luma(data, 720, 618).unwrap_or_default();
}

#[cfg(feature = "image")]
#[test]
fn issue_28() {
    use rxing::DecodeHints;

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    rxing::helpers::detect_multiple_in_file_with_hints("test_resources/blackbox/github_issue_cases/226611447-be6041dc-5b21-42fe-827b-068ccc59082c.png", &mut hints).unwrap_or_default();
}

#[cfg(feature = "image")]
#[test]
fn dynamsoft_all_supported_formats_image_fault() {
    use rxing::DecodeHints;

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    let results = rxing::helpers::detect_multiple_in_file_with_hints(
        "test_resources/blackbox/multi-1/AllSupportedBarcodeTypes.png",
        &mut hints,
    )
    .expect("must not fault during read");

    assert!(
        results.len() >= 11,
        "regression detection, base count of 11 codes"
    );

    // ToDo: This test is incomplete. Some that should be detected aren't, and some that are detected shouldn't be.
}

#[cfg(feature = "image")]
#[test]
fn zxing_bench_issue_1() {
    use rxing::BarcodeFormat;
    use rxing::DecodeHints;

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    let results = rxing::helpers::detect_multiple_in_file_with_hints(
        "test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png",
        &mut hints,
    )
    .expect("must not fault during read");

    assert_eq!(
        results.len(),
        9,
        "must detect 9 barcodes, found: {}",
        results.len()
    );

    assert_eq!(results[0].getText(), "CODE39");
    assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);

    assert_eq!(results[1].getText(), "012345");
    assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);

    assert_eq!(results[2].getText(), "CODE128");
    assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);

    assert_eq!(results[3].getText(), "00123456");
    assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);

    assert_eq!(results[4].getText(), "CODE93");
    assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);

    assert_eq!(results[5].getText(), "012345678905");
    assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);

    assert_eq!(results[6].getText(), "01234565");
    assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);

    assert_eq!(results[7].getText(), "01234565");
    assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);

    assert_eq!(results[8].getText(), "1234567890128");
    assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);

    /*
       Found 9 results
       Result 0:
       (code 39) CODE39
       Result 1:
       (codabar) 012345
       Result 2:
       (code 128) CODE128
       Result 3:
       (itf) 00123456
       Result 4:
       (code 93) CODE93
       Result 5:
       (upc a) 012345678905
       Result 6:
       (ean 8) 01234565
       Result 7:
       (upc e) 01234565
       Result 8:
       (ean 13) 1234567890128

    */
}

#[cfg(feature = "image")]
#[test]
fn issue_48() {
    use rxing::BarcodeFormat;
    use rxing::DecodeHints;

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    let results = rxing::helpers::detect_multiple_in_file_with_hints(
        "test_resources/blackbox/github_issue_cases/300908088-2b3ffe34-1067-48c9-8663-f841b5d0acf6.png",
        &mut hints,
    )
    .expect("must not fault during read");

    /*
       Found 3 results
       Result 0:
       (datamatrix) This is a Data Matrix by TEC-IT
       Result 1:
       (datamatrix) This is a Data Matrix by TEC-IT
       Result 2:
       (datamatrix) Hello world
    */

    assert_eq!(
        results.len(),
        3,
        "must detect 3 barcodes, found: {}",
        results.len()
    );

    assert_eq!(results[0].getText(), "This is a Data Matrix by TEC-IT");
    assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);

    assert_eq!(results[1].getText(), "This is a Data Matrix by TEC-IT");
    assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);

    assert_eq!(results[2].getText(), "Hello world");
    assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::DATA_MATRIX);
}

#[cfg(feature = "image")]
#[test]
fn zxing_bench_grey_image_issue_luma8_image() {
    use image::DynamicImage;
    use rxing::{
        BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHints, Exceptions,
        MultiUseMultiFormatReader,
        common::HybridBinarizer,
        multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png";

    let mut hints = DecodeHints::default();

    let img = DynamicImage::from(
        image::open(FILE_NAME)
            .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
            .unwrap()
            .to_luma8(),
    );
    let multi_format_reader = MultiUseMultiFormatReader::default();
    let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);

    hints.TryHarder = Some(true);

    let results = scanner
        .decode_multiple_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(BufferedImageLuminanceSource::new(img))),
            &hints,
        )
        .expect("must not fault during read");

    assert_eq!(
        results.len(),
        9,
        "must detect 9 barcodes, found: {}",
        results.len()
    );

    assert_eq!(results[0].getText(), "CODE39");
    assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);

    assert_eq!(results[1].getText(), "012345");
    assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);

    assert_eq!(results[2].getText(), "CODE128");
    assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);

    assert_eq!(results[3].getText(), "00123456");
    assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);

    assert_eq!(results[4].getText(), "CODE93");
    assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);

    assert_eq!(results[5].getText(), "012345678905");
    assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);

    assert_eq!(results[6].getText(), "01234565");
    assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);

    assert_eq!(results[7].getText(), "01234565");
    assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);

    assert_eq!(results[8].getText(), "1234567890128");
    assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);

    /*
       Found 9 results
       Result 0:
       (code 39) CODE39
       Result 1:
       (codabar) 012345
       Result 2:
       (code 128) CODE128
       Result 3:
       (itf) 00123456
       Result 4:
       (code 93) CODE93
       Result 5:
       (upc a) 012345678905
       Result 6:
       (ean 8) 01234565
       Result 7:
       (upc e) 01234565
       Result 8:
       (ean 13) 1234567890128

    */
}

#[cfg(feature = "image")]
#[test]
fn zxing_bench_grey_image_issue_raw_luma8() {
    use rxing::{
        BarcodeFormat, BinaryBitmap, DecodeHints, Exceptions, Luma8LuminanceSource,
        MultiUseMultiFormatReader,
        common::HybridBinarizer,
        multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/170050507-1f10f0ef-82ca-4e14-a2d2-4b288ec54809.png";

    let mut hints = DecodeHints::default();

    let img = image::open(FILE_NAME)
        .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
        .unwrap();
    let multi_format_reader = MultiUseMultiFormatReader::default();
    let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);

    hints.TryHarder = Some(true);

    let results = scanner
        .decode_multiple_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(Luma8LuminanceSource::new(
                img.to_luma8().into_raw(),
                img.width(),
                img.height(),
            ))),
            &hints,
        )
        .expect("must not fault during read");

    assert_eq!(
        results.len(),
        9,
        "must detect 9 barcodes, found: {}",
        results.len()
    );

    assert_eq!(results[0].getText(), "CODE39");
    assert_eq!(results[0].getBarcodeFormat(), &BarcodeFormat::CODE_39);

    assert_eq!(results[1].getText(), "012345");
    assert_eq!(results[1].getBarcodeFormat(), &BarcodeFormat::CODABAR);

    assert_eq!(results[2].getText(), "CODE128");
    assert_eq!(results[2].getBarcodeFormat(), &BarcodeFormat::CODE_128);

    assert_eq!(results[3].getText(), "00123456");
    assert_eq!(results[3].getBarcodeFormat(), &BarcodeFormat::ITF);

    assert_eq!(results[4].getText(), "CODE93");
    assert_eq!(results[4].getBarcodeFormat(), &BarcodeFormat::CODE_93);

    assert_eq!(results[5].getText(), "012345678905");
    assert_eq!(results[5].getBarcodeFormat(), &BarcodeFormat::UPC_A);

    assert_eq!(results[6].getText(), "01234565");
    assert_eq!(results[6].getBarcodeFormat(), &BarcodeFormat::EAN_8);

    assert_eq!(results[7].getText(), "01234565");
    assert_eq!(results[7].getBarcodeFormat(), &BarcodeFormat::UPC_E);

    assert_eq!(results[8].getText(), "1234567890128");
    assert_eq!(results[8].getBarcodeFormat(), &BarcodeFormat::EAN_13);

    /*
       Found 9 results
       Result 0:
       (code 39) CODE39
       Result 1:
       (codabar) 012345
       Result 2:
       (code 128) CODE128
       Result 3:
       (itf) 00123456
       Result 4:
       (code 93) CODE93
       Result 5:
       (upc a) 012345678905
       Result 6:
       (ean 8) 01234565
       Result 7:
       (upc e) 01234565
       Result 8:
       (ean 13) 1234567890128

    */
}

#[cfg(feature = "image")]
#[test]
fn test_issue_49() {
    use rxing::{
        BarcodeFormat, BinaryBitmap, DecodeHints, Exceptions, Luma8LuminanceSource,
        MultiUseMultiFormatReader,
        common::HybridBinarizer,
        multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/345143005-4538852a-242a-4f77-87cc-fefb66856ecf.png";
    let mut hints = DecodeHints::default();

    let img = image::open(FILE_NAME)
        .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
        .unwrap();
    let multi_format_reader = MultiUseMultiFormatReader::default();
    let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);

    hints.TryHarder = Some(true);

    let results = scanner
        .decode_multiple_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(Luma8LuminanceSource::new(
                img.to_luma8().into_raw(),
                img.width(),
                img.height(),
            ))),
            &hints,
        )
        .expect("must not fault during read");

    assert_eq!(results.len(), 3);

    let itf_result = results
        .iter()
        .find(|r| r.getBarcodeFormat() == &BarcodeFormat::ITF)
        .expect("must find an ITF barcode");

    const EXPECTED_ITF_TEXT: &str = "85680000000343202687700000014672192100000000";

    assert_eq!(EXPECTED_ITF_TEXT, itf_result.getText());
}

#[cfg(feature = "image")]
#[test]
fn test_issue_50() {
    use rxing::{
        BarcodeFormat, BinaryBitmap, DecodeHints, Exceptions, Luma8LuminanceSource,
        MultiUseMultiFormatReader, Reader, common::HybridBinarizer,
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/346304318-16acfb7a-4a41-4b15-af78-7ccf061e72bd.png";
    let mut hints = DecodeHints::default();

    let img = image::open(FILE_NAME)
        .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
        .unwrap();
    let mut scanner = MultiUseMultiFormatReader::default();

    hints.TryHarder = Some(true);
    hints.PureBarcode = Some(true);

    let result = scanner
        .decode_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(Luma8LuminanceSource::new(
                img.to_luma8().into_raw(),
                img.width(),
                img.height(),
            ))),
            &hints,
        )
        .expect("must not fault during read");

    const EXPECTED_FORMAT: &BarcodeFormat = &BarcodeFormat::ITF;
    const EXPECTED_ITF_TEXT: &str = "85680000001403303242024070501202400002535294";

    assert_eq!(EXPECTED_ITF_TEXT, result.getText());

    assert_eq!(EXPECTED_FORMAT, result.getBarcodeFormat());
}

#[cfg(feature = "image")]
#[test]
fn test_issue_50_2() {
    use rxing::{
        BarcodeFormat, BinaryBitmap, DecodeHints, Exceptions, Luma8LuminanceSource,
        MultiUseMultiFormatReader, Reader, common::AdaptiveThresholdBinarizer,
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/346304318-16acfb7a-4a41-4b15-af78-7ccf061e72bd.png";
    let mut hints = DecodeHints::default();

    let img = image::open(FILE_NAME)
        .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
        .unwrap();
    let mut scanner = MultiUseMultiFormatReader::default();

    hints.TryHarder = Some(true);

    let result = scanner
        .decode_with_hints(
            &mut BinaryBitmap::new(AdaptiveThresholdBinarizer::new(
                Luma8LuminanceSource::new(img.to_luma8().into_raw(), img.width(), img.height()),
                1,
            )),
            &hints,
        )
        .expect("must not fault during read");

    const EXPECTED_FORMAT: &BarcodeFormat = &BarcodeFormat::ITF;
    const EXPECTED_ITF_TEXT: &str = "85680000001403303242024070501202400002535294";

    assert_eq!(EXPECTED_ITF_TEXT, result.getText());

    assert_eq!(EXPECTED_FORMAT, result.getBarcodeFormat());
}

#[cfg(feature = "image")]
#[test]
fn issue_51_multiple_detection() {
    use image::DynamicImage;
    use rxing::{
        BinaryBitmap, BufferedImageLuminanceSource, DecodeHints, Exceptions,
        MultiUseMultiFormatReader,
        common::HybridBinarizer,
        multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
    };

    const FILE_NAME: &str = "test_resources/blackbox/github_issue_cases/349949736-8e3b9d66-d114-41ca-a8e0-f1332d111827.jpeg";

    let mut hints = DecodeHints::default();

    let img = DynamicImage::from(
        image::open(FILE_NAME)
            .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME}: {e}")))
            .unwrap()
            .to_luma8(),
    );
    let multi_format_reader = MultiUseMultiFormatReader::default();
    let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);

    hints.TryHarder = Some(true);

    let results = scanner
        .decode_multiple_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(BufferedImageLuminanceSource::new(img))),
            &hints,
        )
        .expect("must not fault during read image 1");

    assert_eq!(
        results.len(),
        1,
        "must detect 1 barcodes, found: {}",
        results.len()
    );

    const FILE_NAME2: &str = "test_resources/blackbox/github_issue_cases/349949791-1e8b67a7-0994-46fb-bd86-a5f3cd79f0e5.jpeg";

    let mut hints = DecodeHints::default();

    let img = DynamicImage::from(
        image::open(FILE_NAME2)
            .map_err(|e| Exceptions::runtime_with(format!("couldn't read {FILE_NAME2}: {e}")))
            .unwrap()
            .to_luma8(),
    );
    let multi_format_reader = MultiUseMultiFormatReader::default();
    let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);

    hints.TryHarder = Some(true);

    let results = scanner
        .decode_multiple_with_hints(
            &mut BinaryBitmap::new(HybridBinarizer::new(BufferedImageLuminanceSource::new(img))),
            &hints,
        )
        .expect("must not fault during read of image 2");

    assert_eq!(
        results.len(),
        1,
        "must detect 1 barcodes, found: {}",
        results.len()
    );
}

#[cfg(feature = "image")]
#[test]
fn issue_58() {
    use rxing::{DecodeHints, Exceptions};

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    assert!(
        rxing::helpers::detect_multiple_in_file_with_hints(
            "test_resources/blackbox/github_issue_cases/empty_issue_58.png",
            &mut hints
        )
        .is_err_and(|e| { e == Exceptions::NOT_FOUND })
    );

    hints.PureBarcode = Some(true);

    assert!(
        rxing::helpers::detect_multiple_in_file_with_hints(
            "test_resources/blackbox/github_issue_cases/empty_issue_58.png",
            &mut hints
        )
        .is_err_and(|e| { e == Exceptions::NOT_FOUND })
    );
}

#[cfg(feature = "image")]
#[test]
fn issue_59() {
    use rand::prelude::*;
    use rxing::{BufferedImageLuminanceSource, DecodeHints, EncodeHints};

    const TEST_SIZE: usize = 1400;
    const TEST_2_SIZE: usize = 100;

    let mut rnd_data = [0; TEST_SIZE];
    rand::rng().fill_bytes(&mut rnd_data);
    let data = rnd_data.into_iter().map(|c| c as char).collect::<String>();

    let writer = rxing::datamatrix::DataMatrixWriter;
    let data_matrix = writer
        .encode(&data, &rxing::BarcodeFormat::DATA_MATRIX, 0, 0)
        .expect("must encode with size of 500");

    let mut rnd_data_2 = [0; TEST_2_SIZE];
    rand::rng().fill_bytes(&mut rnd_data_2);
    let data2 = rnd_data_2
        .into_iter()
        .map(|c| c as char)
        .collect::<String>();

    #[allow(deprecated)]
    let hints =
        EncodeHints::default().with(rxing::EncodeHintValue::MinSize(Dimension::new(48, 48)));
    let data_matrix_2 = writer
        .encode_with_hints(&data2, &rxing::BarcodeFormat::DATA_MATRIX, 0, 0, &hints)
        .expect("must encode with minimum size of 48x48");

    let decode_hints = DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));

    let img: DynamicImage = data_matrix.into();
    let ls = BufferedImageLuminanceSource::new(img);
    let mut bb = rxing::BinaryBitmap::new(rxing::common::HybridBinarizer::new(ls));
    let detection = rxing::MultiFormatReader::default()
        .decode_with_hints(&mut bb, &decode_hints)
        .expect("must decode first image");
    assert_eq!(detection.getText(), data);

    let img: DynamicImage = data_matrix_2.into();
    let ls = BufferedImageLuminanceSource::new(img);
    let mut bb = rxing::BinaryBitmap::new(rxing::common::HybridBinarizer::new(ls));
    let detection = rxing::MultiFormatReader::default()
        .decode_with_hints(&mut bb, &decode_hints)
        .expect("must decode first image");
    assert_eq!(detection.getText(), data2);
}

#[cfg(feature = "image")]
#[test]
fn issue_69_timed() {
    use std::{sync::mpsc, thread, time::Duration};

    use rxing::DecodeHints;

    let (tx, rx) = mpsc::channel();

    thread::spawn(move || {
        // Capture panic so the test can surface it
        let mut hints: DecodeHints =
            DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));

        use std::panic::{AssertUnwindSafe, catch_unwind};
        let r = catch_unwind(AssertUnwindSafe(|| {
            assert!(rxing::helpers::detect_multiple_in_file_with_hints(
        "test_resources/blackbox/github_issue_cases/481273207-b43215de-7369-4a04-a695-984f27fd1225.jpg",
        &mut hints
    ).is_ok())
        }));
        let _ = tx.send(r);
    });

    match rx.recv_timeout(Duration::from_secs(30)) {
        Ok(Ok(())) => {} // finished in time
        Ok(Err(e)) => panic!("search panicked with: {e:?}"),
        Err(_) => panic!("search timed out"), // did not finish in time
    }
}

#[cfg(feature = "image")]
#[test]
fn issue_69() {
    use rxing::DecodeHints;

    let mut hints: DecodeHints =
        DecodeHints::default().with(rxing::DecodeHintValue::TryHarder(true));
    let results = rxing::helpers::detect_multiple_in_file_with_hints(
        "test_resources/blackbox/github_issue_cases/481273207-b43215de-7369-4a04-a695-984f27fd1225.jpg",
        &mut hints
    ).expect("should return results from decoding");

    assert!(
        results.len() >= 5,
        "Search should return at least 5 results"
    );

    /*

    Found 5 results
    Result 0:
    (datamatrix) 011060329549205420151734113010D24121203
    Result 1:
    (datamatrix) 01106032951299431726113010M8190P
    Result 2:
    (code 128) 01106032954920542015
    Result 3:
    (datamatrix) 0110603295041283202217350131104559233
    Result 4:
    (code 128) 1734113010D24121203
     */
}