rxing/
reader.rs

1/*
2 * Copyright 2007 ZXing authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::{common::Result, Binarizer, BinaryBitmap, DecodeHints, RXingResult};
18
19/**
20 * Implementations of this interface can decode an image of a barcode in some format into
21 * the String it encodes. For example, {@link com.google.zxing.qrcode.QRCodeReader} can
22 * decode a QR code. The decoder may optionally receive hints from the caller which may help
23 * it decode more quickly or accurately.
24 *
25 * See {@link MultiFormatReader}, which attempts to determine what barcode
26 * format is present within the image as well, and then decodes it accordingly.
27 *
28 * @author Sean Owen
29 * @author dswitkin@google.com (Daniel Switkin)
30 */
31pub trait Reader {
32    /**
33     * Locates and decodes a barcode in some format within an image.
34     *
35     * @param image image of barcode to decode
36     * @return String which the barcode encodes
37     * @throws NotFoundException if no potential barcode is found
38     * @throws ChecksumException if a potential barcode is found but does not pass its checksum
39     * @throws FormatException if a potential barcode is found but format is invalid
40     */
41    fn decode<B: Binarizer>(&mut self, image: &mut BinaryBitmap<B>) -> Result<RXingResult>;
42
43    /**
44     * Locates and decodes a barcode in some format within an image. This method also accepts
45     * hints, each possibly associated to some data, which may help the implementation decode.
46     *
47     * @param image image of barcode to decode
48     * @param hints passed as a {@link Map} from {@link DecodeHintType}
49     * to arbitrary data. The
50     * meaning of the data depends upon the hint type. The implementation may or may not do
51     * anything with these hints.
52     * @return String which the barcode encodes
53     * @throws NotFoundException if no potential barcode is found
54     * @throws ChecksumException if a potential barcode is found but does not pass its checksum
55     * @throws FormatException if a potential barcode is found but format is invalid
56     */
57    fn decode_with_hints<B: Binarizer>(
58        &mut self,
59        image: &mut BinaryBitmap<B>,
60        hints: &DecodeHints,
61    ) -> Result<RXingResult>;
62
63    /**
64     * Resets any internal state the implementation has after a decode, to prepare it
65     * for reuse.
66     */
67    fn reset(&mut self) { /* do nothing */
68    }
69}
70pub trait ImmutableReader {
71    fn immutable_decode<B: Binarizer>(&self, image: &mut BinaryBitmap<B>) -> Result<RXingResult> {
72        self.immutable_decode_with_hints(image, &DecodeHints::default())
73    }
74
75    fn immutable_decode_with_hints<B: Binarizer>(
76        &self,
77        image: &mut BinaryBitmap<B>,
78        hints: &DecodeHints,
79    ) -> Result<RXingResult>;
80}