Search in sources :

Example 6 with FinderPattern

use of com.google.zxing.oned.rss.FinderPattern in project zxing by zxing.

the class RSSExpandedInternalTestCase method testRetrieveNextPairPatterns.

@Test
public void testRetrieveNextPairPatterns() throws Exception {
    BufferedImage image = readImage("3.png");
    BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
    int rowNumber = binaryMap.getHeight() / 2;
    BitArray row = binaryMap.getBlackRow(rowNumber, null);
    List<ExpandedPair> previousPairs = new ArrayList<>();
    RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
    ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    previousPairs.add(pair1);
    FinderPattern finderPattern = pair1.getFinderPattern();
    assertNotNull(finderPattern);
    assertEquals(0, finderPattern.getValue());
    ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    previousPairs.add(pair2);
    finderPattern = pair2.getFinderPattern();
    assertNotNull(finderPattern);
    assertEquals(0, finderPattern.getValue());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ArrayList(java.util.ArrayList) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 7 with FinderPattern

use of com.google.zxing.oned.rss.FinderPattern in project zxing by zxing.

the class RSSExpandedReader method parseFoundFinderPattern.

private FinderPattern parseFoundFinderPattern(BitArray row, int rowNumber, boolean oddPattern) {
    // Actually we found elements 2-5.
    int firstCounter;
    int start;
    int end;
    if (oddPattern) {
        // If pattern number is odd, we need to locate element 1 *before* the current block.
        int firstElementStart = this.startEnd[0] - 1;
        // Locate element 1
        while (firstElementStart >= 0 && !row.get(firstElementStart)) {
            firstElementStart--;
        }
        firstElementStart++;
        firstCounter = this.startEnd[0] - firstElementStart;
        start = firstElementStart;
        end = this.startEnd[1];
    } else {
        // If pattern number is even, the pattern is reversed, so we need to locate element 1 *after* the current block.
        start = this.startEnd[0];
        end = row.getNextUnset(this.startEnd[1] + 1);
        firstCounter = end - this.startEnd[1];
    }
    // Make 'counters' hold 1-4
    int[] counters = this.getDecodeFinderCounters();
    System.arraycopy(counters, 0, counters, 1, counters.length - 1);
    counters[0] = firstCounter;
    int value;
    try {
        value = parseFinderValue(counters, FINDER_PATTERNS);
    } catch (NotFoundException ignored) {
        return null;
    }
    return new FinderPattern(value, new int[] { start, end }, start, end, rowNumber);
}
Also used : FinderPattern(com.google.zxing.oned.rss.FinderPattern) NotFoundException(com.google.zxing.NotFoundException) ResultPoint(com.google.zxing.ResultPoint)

Example 8 with FinderPattern

use of com.google.zxing.oned.rss.FinderPattern in project zxing by zxing.

the class RSSExpandedReader method retrieveNextPair.

// not private for testing
ExpandedPair retrieveNextPair(BitArray row, List<ExpandedPair> previousPairs, int rowNumber) throws NotFoundException {
    boolean isOddPattern = previousPairs.size() % 2 == 0;
    if (startFromEven) {
        isOddPattern = !isOddPattern;
    }
    FinderPattern pattern;
    boolean keepFinding = true;
    int forcedOffset = -1;
    do {
        this.findNextPair(row, previousPairs, forcedOffset);
        pattern = parseFoundFinderPattern(row, rowNumber, isOddPattern);
        if (pattern == null) {
            forcedOffset = getNextSecondBar(row, this.startEnd[0]);
        } else {
            keepFinding = false;
        }
    } while (keepFinding);
    // When stacked symbol is split over multiple rows, there's no way to guess if this pair can be last or not.
    // boolean mayBeLast = checkPairSequence(previousPairs, pattern);
    DataCharacter leftChar = this.decodeDataCharacter(row, pattern, isOddPattern, true);
    if (!previousPairs.isEmpty() && previousPairs.get(previousPairs.size() - 1).mustBeLast()) {
        throw NotFoundException.getNotFoundInstance();
    }
    DataCharacter rightChar;
    try {
        rightChar = this.decodeDataCharacter(row, pattern, isOddPattern, false);
    } catch (NotFoundException ignored) {
        rightChar = null;
    }
    return new ExpandedPair(leftChar, rightChar, pattern, true);
}
Also used : FinderPattern(com.google.zxing.oned.rss.FinderPattern) NotFoundException(com.google.zxing.NotFoundException) ResultPoint(com.google.zxing.ResultPoint) DataCharacter(com.google.zxing.oned.rss.DataCharacter)

Aggregations

FinderPattern (com.google.zxing.oned.rss.FinderPattern)8 NotFoundException (com.google.zxing.NotFoundException)5 BinaryBitmap (com.google.zxing.BinaryBitmap)4 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)4 ResultPoint (com.google.zxing.ResultPoint)4 BitArray (com.google.zxing.common.BitArray)4 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)4 DataCharacter (com.google.zxing.oned.rss.DataCharacter)4 BufferedImage (java.awt.image.BufferedImage)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2