Class UPCEANReader

    • Field Detail

      • MAX_INDIVIDUAL_VARIANCE

        private static final float MAX_INDIVIDUAL_VARIANCE
        See Also:
        Constant Field Values
      • START_END_PATTERN

        static final int[] START_END_PATTERN
        Start/end guard pattern.
      • MIDDLE_PATTERN

        static final int[] MIDDLE_PATTERN
        Pattern marking the middle of a UPC/EAN pattern, separating the two halves.
      • END_PATTERN

        static final int[] END_PATTERN
        end guard pattern.
      • L_PATTERNS

        static final int[][] L_PATTERNS
        "Odd", or "L" patterns used to encode UPC/EAN digits.
      • L_AND_G_PATTERNS

        static final int[][] L_AND_G_PATTERNS
        As above but also including the "even", or "G" patterns used to encode UPC/EAN digits.
      • decodeRowStringBuffer

        private final java.lang.StringBuilder decodeRowStringBuffer
    • Constructor Detail

      • UPCEANReader

        protected UPCEANReader()
    • Method Detail

      • decodeRow

        public Result decodeRow​(int rowNumber,
                                BitArray row,
                                int[] startGuardRange,
                                java.util.Map<DecodeHintType,​?> hints)
                         throws NotFoundException,
                                ChecksumException,
                                FormatException

        Like decodeRow(int, BitArray, Map), but allows caller to inform method about where the UPC/EAN start pattern is found. This allows this to be computed once and reused across many implementations.

        Parameters:
        rowNumber - row index into the image
        row - encoding of the row of the barcode image
        startGuardRange - start/end column where the opening start pattern was found
        hints - optional hints that influence decoding
        Returns:
        Result encapsulating the result of decoding a barcode in the row
        Throws:
        NotFoundException - if no potential barcode is found
        ChecksumException - if a potential barcode is found but does not pass its checksum
        FormatException - if a potential barcode is found but format is invalid
      • checkStandardUPCEANChecksum

        static boolean checkStandardUPCEANChecksum​(java.lang.CharSequence s)
                                            throws FormatException
        Computes the UPC/EAN checksum on a string of digits, and reports whether the checksum is correct or not.
        Parameters:
        s - string of digits to check
        Returns:
        true iff string of digits passes the UPC/EAN checksum algorithm
        Throws:
        FormatException - if the string does not contain only digits
      • findGuardPattern

        private static int[] findGuardPattern​(BitArray row,
                                              int rowOffset,
                                              boolean whiteFirst,
                                              int[] pattern,
                                              int[] counters)
                                       throws NotFoundException
        Parameters:
        row - row of black/white values to search
        rowOffset - position to start search
        whiteFirst - if true, indicates that the pattern specifies white/black/white/... pixel counts, otherwise, it is interpreted as black/white/black/...
        pattern - pattern of counts of number of black and white pixels that are being searched for as a pattern
        counters - array of counters, as long as pattern, to re-use
        Returns:
        start/end horizontal offset of guard pattern, as an array of two ints
        Throws:
        NotFoundException - if pattern is not found
      • decodeDigit

        static int decodeDigit​(BitArray row,
                               int[] counters,
                               int rowOffset,
                               int[][] patterns)
                        throws NotFoundException
        Attempts to decode a single UPC/EAN-encoded digit.
        Parameters:
        row - row of black/white values to decode
        counters - the counts of runs of observed black/white/black/... values
        rowOffset - horizontal offset to start decoding from
        patterns - the set of patterns to use to decode -- sometimes different encodings for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should be used
        Returns:
        horizontal offset of first pixel beyond the decoded digit
        Throws:
        NotFoundException - if digit cannot be decoded
      • getBarcodeFormat

        abstract BarcodeFormat getBarcodeFormat()
        Get the format of this decoder.
        Returns:
        The 1D format.
      • decodeMiddle

        protected abstract int decodeMiddle​(BitArray row,
                                            int[] startRange,
                                            java.lang.StringBuilder resultString)
                                     throws NotFoundException
        Subclasses override this to decode the portion of a barcode between the start and end guard patterns.
        Parameters:
        row - row of black/white values to search
        startRange - start/end offset of start guard pattern
        resultString - StringBuilder to append decoded chars to
        Returns:
        horizontal offset of first pixel after the "middle" that was decoded
        Throws:
        NotFoundException - if decoding could not complete successfully