Class UPCEANReader

java.lang.Object
com.google.zxing.oned.OneDReader
com.google.zxing.oned.UPCEANReader
All Implemented Interfaces:
Reader
Direct Known Subclasses:
EAN13Reader, EAN8Reader, UPCAReader, UPCEReader

public abstract class UPCEANReader extends OneDReader

Encapsulates functionality and implementation that is common to UPC and EAN families of one-dimensional barcodes.

  • Field Details

    • MAX_AVG_VARIANCE

      private static final float MAX_AVG_VARIANCE
      See Also:
    • MAX_INDIVIDUAL_VARIANCE

      private static final float MAX_INDIVIDUAL_VARIANCE
      See Also:
    • 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 StringBuilder decodeRowStringBuffer
    • extensionReader

      private final UPCEANExtensionSupport extensionReader
    • eanManSupport

      private final EANManufacturerOrgSupport eanManSupport
  • Constructor Details

    • UPCEANReader

      protected UPCEANReader()
  • Method Details

    • findStartGuardPattern

      static int[] findStartGuardPattern(BitArray row) throws NotFoundException
      Throws:
      NotFoundException
    • decodeRow

      public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException, ChecksumException, FormatException
      Description copied from class: OneDReader

      Attempts to decode a one-dimensional barcode format given a single row of an image.

      Specified by:
      decodeRow in class OneDReader
      Parameters:
      rowNumber - row number from top of the row
      row - the black/white pixel data of the row
      hints - decode hints
      Returns:
      Result containing encoded string and start/end of barcode
      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
    • decodeRow

      public Result decodeRow(int rowNumber, BitArray row, int[] startGuardRange, 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
    • checkChecksum

      boolean checkChecksum(String s) throws FormatException
      Parameters:
      s - string of digits to check
      Returns:
      checkStandardUPCEANChecksum(CharSequence)
      Throws:
      FormatException - if the string does not contain only digits
    • checkStandardUPCEANChecksum

      static boolean checkStandardUPCEANChecksum(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
    • getStandardUPCEANChecksum

      static int getStandardUPCEANChecksum(CharSequence s) throws FormatException
      Throws:
      FormatException
    • decodeEnd

      int[] decodeEnd(BitArray row, int endStart) throws NotFoundException
      Throws:
      NotFoundException
    • findGuardPattern

      static int[] findGuardPattern(BitArray row, int rowOffset, boolean whiteFirst, int[] pattern) throws NotFoundException
      Throws:
      NotFoundException
    • 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, 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