Class OneDReader

    • Constructor Summary

      Constructors 
      Constructor Description
      OneDReader()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Result decode​(BinaryBitmap image)
      Locates and decodes a barcode in some format within an image.
      Result decode​(BinaryBitmap image, java.util.Map<DecodeHintType,​?> hints)
      Locates and decodes a barcode in some format within an image.
      abstract Result decodeRow​(int rowNumber, BitArray row, java.util.Map<DecodeHintType,​?> hints)
      Attempts to decode a one-dimensional barcode format given a single row of an image.
      private Result doDecode​(BinaryBitmap image, java.util.Map<DecodeHintType,​?> hints)
      We're going to examine rows from the middle outward, searching alternately above and below the middle, and farther out each time.
      protected static float patternMatchVariance​(int[] counters, int[] pattern, float maxIndividualVariance)
      Determines how closely a set of observed counts of runs of black/white values matches a given target pattern.
      protected static void recordPattern​(BitArray row, int start, int[] counters)
      Records the size of successive runs of white and black pixels in a row, starting at a given point.
      protected static void recordPatternInReverse​(BitArray row, int start, int[] counters)  
      void reset()
      Resets any internal state the implementation has after a decode, to prepare it for reuse.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OneDReader

        public OneDReader()
    • Method Detail

      • decode

        public Result decode​(BinaryBitmap image,
                             java.util.Map<DecodeHintType,​?> hints)
                      throws NotFoundException,
                             FormatException
        Description copied from interface: Reader
        Locates and decodes a barcode in some format within an image. This method also accepts hints, each possibly associated to some data, which may help the implementation decode.
        Specified by:
        decode in interface Reader
        Parameters:
        image - image of barcode to decode
        hints - passed as a Map from DecodeHintType to arbitrary data. The meaning of the data depends upon the hint type. The implementation may or may not do anything with these hints.
        Returns:
        String which the barcode encodes
        Throws:
        NotFoundException - if no potential barcode is found
        FormatException - if a potential barcode is found but format is invalid
      • reset

        public void reset()
        Description copied from interface: Reader
        Resets any internal state the implementation has after a decode, to prepare it for reuse.
        Specified by:
        reset in interface Reader
      • doDecode

        private Result doDecode​(BinaryBitmap image,
                                java.util.Map<DecodeHintType,​?> hints)
                         throws NotFoundException
        We're going to examine rows from the middle outward, searching alternately above and below the middle, and farther out each time. rowStep is the number of rows between each successive attempt above and below the middle. So we'd scan row middle, then middle - rowStep, then middle + rowStep, then middle - (2 * rowStep), etc. rowStep is bigger as the image is taller, but is always at least 1. We've somewhat arbitrarily decided that moving up and down by about 1/16 of the image is pretty good; we try more of the image if "trying harder".
        Parameters:
        image - The image to decode
        hints - Any hints that were requested
        Returns:
        The contents of the decoded barcode
        Throws:
        NotFoundException - Any spontaneous errors which occur
      • recordPattern

        protected static void recordPattern​(BitArray row,
                                            int start,
                                            int[] counters)
                                     throws NotFoundException
        Records the size of successive runs of white and black pixels in a row, starting at a given point. The values are recorded in the given array, and the number of runs recorded is equal to the size of the array. If the row starts on a white pixel at the given start point, then the first count recorded is the run of white pixels starting from that point; likewise it is the count of a run of black pixels if the row begin on a black pixels at that point.
        Parameters:
        row - row to count from
        start - offset into row to start at
        counters - array into which to record counts
        Throws:
        NotFoundException - if counters cannot be filled entirely from row before running out of pixels
      • patternMatchVariance

        protected static float patternMatchVariance​(int[] counters,
                                                    int[] pattern,
                                                    float maxIndividualVariance)
        Determines how closely a set of observed counts of runs of black/white values matches a given target pattern. This is reported as the ratio of the total variance from the expected pattern proportions across all pattern elements, to the length of the pattern.
        Parameters:
        counters - observed counters
        pattern - expected pattern
        maxIndividualVariance - The most any counter can differ before we give up
        Returns:
        ratio of total variance between counters and pattern compared to total pattern size
      • decodeRow

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

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

        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