Search in sources :

Example 1 with FinderPattern

use of com.google.zxing.oned.rss.FinderPattern in project weex-example by KalicyZhou.

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;
    }
    boolean mayBeLast = true;
    return new ExpandedPair(leftChar, rightChar, pattern, mayBeLast);
}
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)

Example 2 with FinderPattern

use of com.google.zxing.oned.rss.FinderPattern in project weex-example by KalicyZhou.

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 3 with FinderPattern

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

the class RSSExpandedInternalTestCase method testFindFinderPatterns.

@Test
public void testFindFinderPatterns() throws Exception {
    BufferedImage image = readImage("2.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(1, finderPattern.getValue());
    ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
    previousPairs.add(pair3);
    finderPattern = pair3.getFinderPattern();
    assertNotNull(finderPattern);
    assertEquals(1, finderPattern.getValue());
    try {
        rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
        //   the previous was the last pair
        fail(NotFoundException.class.getName() + " expected");
    } catch (NotFoundException nfe) {
    // ok
    }
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) ArrayList(java.util.ArrayList) NotFoundException(com.google.zxing.NotFoundException) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 4 with FinderPattern

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

the class RSSExpandedInternalTestCase method testDecodeDataCharacter.

@Test
public void testDecodeDataCharacter() throws Exception {
    BufferedImage image = readImage("3.png");
    BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
    BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
    //image pixels where the A1 pattern starts (at 124) and ends (at 214)
    int[] startEnd = { 145, 243 };
    // A
    int value = 0;
    FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
    //{1, 8, 4, 1, 1};
    RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
    DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);
    assertEquals(19, dataCharacter.getValue());
    assertEquals(1007, dataCharacter.getChecksumPortion());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) DataCharacter(com.google.zxing.oned.rss.DataCharacter) Test(org.junit.Test)

Example 5 with FinderPattern

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

the class RSSExpandedInternalTestCase method testDecodeCheckCharacter.

@Test
public void testDecodeCheckCharacter() throws Exception {
    BufferedImage image = readImage("3.png");
    BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
    BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
    //image pixels where the A1 pattern starts (at 124) and ends (at 214)
    int[] startEnd = { 145, 243 };
    // A
    int value = 0;
    FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
    //{1, 8, 4, 1, 1};
    RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
    DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);
    assertEquals(98, dataCharacter.getValue());
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) FinderPattern(com.google.zxing.oned.rss.FinderPattern) BufferedImageLuminanceSource(com.google.zxing.BufferedImageLuminanceSource) BitArray(com.google.zxing.common.BitArray) BinaryBitmap(com.google.zxing.BinaryBitmap) BufferedImage(java.awt.image.BufferedImage) DataCharacter(com.google.zxing.oned.rss.DataCharacter) Test(org.junit.Test)

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