Java Code Examples for com.google.zxing.common.BitArray#get()

The following examples show how to use com.google.zxing.common.BitArray#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatrixUtil.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException {
  if (version.getVersionNumber() < 7) {  // Version info is necessary if version >= 7.
    return;  // Don't need version info.
  }
  BitArray versionInfoBits = new BitArray();
  makeVersionInfoBits(version, versionInfoBits);

  int bitIndex = 6 * 3 - 1;  // It will decrease from 17 to 0.
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 3; ++j) {
      // Place bits in LSB (least significant bit) to MSB order.
      boolean bit = versionInfoBits.get(bitIndex);
      bitIndex--;
      // Left bottom corner.
      matrix.set(i, matrix.getHeight() - 11 + j, bit);
      // Right bottom corner.
      matrix.set(matrix.getHeight() - 11 + j, i, bit);
    }
  }
}
 
Example 2
Source File: CodaBarReader.java    From ScreenCapture with MIT License 6 votes vote down vote up
/**
 * Records the size of all runs of white and black pixels, starting with white.
 * This is just like recordPattern, except it records all the counters, and
 * uses our builtin "counters" member for storage.
 * @param row row to count from
 */
private void setCounters(BitArray row) throws NotFoundException {
  counterLength = 0;
  // Start from the first white bit.
  int i = row.getNextUnset(0);
  int end = row.getSize();
  if (i >= end) {
    throw NotFoundException.getNotFoundInstance();
  }
  boolean isWhite = true;
  int count = 0;
  while (i < end) {
    if (row.get(i) != isWhite) {
      count++;
    } else {
      counterAppend(count);
      count = 1;
      isWhite = !isWhite;
    }
    i++;
  }
  counterAppend(count);
}
 
Example 3
Source File: d.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
static void b(int j, ByteMatrix bytematrix)
{
    if (j >= 7)
    {
        BitArray bitarray = new BitArray();
        a(j, bitarray);
        int k = 17;
        int l = 0;
        while (l < 6) 
        {
            int i1 = k;
            for (int j1 = 0; j1 < 3; j1++)
            {
                boolean flag = bitarray.get(i1);
                i1--;
                bytematrix.set(l, j1 + (-11 + bytematrix.getHeight()), flag);
                bytematrix.set(j1 + (-11 + bytematrix.getHeight()), l, flag);
            }

            l++;
            k = i1;
        }
    }
}
 
Example 4
Source File: MatrixUtil.java    From reacteu-app with MIT License 6 votes vote down vote up
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException {
  if (version.getVersionNumber() < 7) {  // Version info is necessary if version >= 7.
    return;  // Don't need version info.
  }
  BitArray versionInfoBits = new BitArray();
  makeVersionInfoBits(version, versionInfoBits);

  int bitIndex = 6 * 3 - 1;  // It will decrease from 17 to 0.
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 3; ++j) {
      // Place bits in LSB (least significant bit) to MSB order.
      boolean bit = versionInfoBits.get(bitIndex);
      bitIndex--;
      // Left bottom corner.
      matrix.set(i, matrix.getHeight() - 11 + j, bit);
      // Right bottom corner.
      matrix.set(matrix.getHeight() - 11 + j, i, bit);
    }
  }
}
 
Example 5
Source File: Encoder.java    From weex with Apache License 2.0 6 votes vote down vote up
static BitArray stuffBits(BitArray bits, int wordSize) {
  BitArray out = new BitArray();

  int n = bits.getSize();
  int mask = (1 << wordSize) - 2;
  for (int i = 0; i < n; i += wordSize) {
    int word = 0;
    for (int j = 0; j < wordSize; j++) {
      if (i + j >= n || bits.get(i + j)) {
        word |= 1 << (wordSize - 1 - j);
      }
    }
    if ((word & mask) == mask) {
      out.appendBits(word & mask, wordSize);
      i--;
    } else if ((word & mask) == 0) {
      out.appendBits(word | 1, wordSize);
      i--;
    } else {
      out.appendBits(word, wordSize);
    }
  }
  return out;
}
 
Example 6
Source File: MatrixUtil.java    From ScreenCapture with MIT License 6 votes vote down vote up
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException {
  if (version.getVersionNumber() < 7) {  // Version info is necessary if version >= 7.
    return;  // Don't need version info.
  }
  BitArray versionInfoBits = new BitArray();
  makeVersionInfoBits(version, versionInfoBits);

  int bitIndex = 6 * 3 - 1;  // It will decrease from 17 to 0.
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 3; ++j) {
      // Place bits in LSB (least significant bit) to MSB order.
      boolean bit = versionInfoBits.get(bitIndex);
      bitIndex--;
      // Left bottom corner.
      matrix.set(i, matrix.getHeight() - 11 + j, bit);
      // Right bottom corner.
      matrix.set(matrix.getHeight() - 11 + j, i, bit);
    }
  }
}
 
Example 7
Source File: Code93Reader.java    From weex with Apache License 2.0 5 votes vote down vote up
private int[] findAsteriskPattern(BitArray row) throws NotFoundException {
  int width = row.getSize();
  int rowOffset = row.getNextSet(0);

  Arrays.fill(counters, 0);
  int[] theCounters = counters;
  int patternStart = rowOffset;
  boolean isWhite = false;
  int patternLength = theCounters.length;

  int counterPosition = 0;
  for (int i = rowOffset; i < width; i++) {
    if (row.get(i) ^ isWhite) {
      theCounters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (toPattern(theCounters) == ASTERISK_ENCODING) {
          return new int[]{patternStart, i};
        }
        patternStart += theCounters[0] + theCounters[1];
        System.arraycopy(theCounters, 2, theCounters, 0, patternLength - 2);
        theCounters[patternLength - 2] = 0;
        theCounters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      theCounters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 8
Source File: OneDReader.java    From reacteu-app with MIT License 5 votes vote down vote up
/**
 * 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.
 *
 * @param row row to count from
 * @param start offset into row to start at
 * @param counters array into which to record counts
 * @throws NotFoundException if counters cannot be filled entirely from row before running out
 *  of pixels
 */
protected static void recordPattern(BitArray row,
                                    int start,
                                    int[] counters) throws NotFoundException {
  int numCounters = counters.length;
  Arrays.fill(counters, 0, numCounters, 0);
  int end = row.getSize();
  if (start >= end) {
    throw NotFoundException.getNotFoundInstance();
  }
  boolean isWhite = !row.get(start);
  int counterPosition = 0;
  int i = start;
  while (i < end) {
    if (row.get(i) ^ isWhite) { // that is, exactly one is true
      counters[counterPosition]++;
    } else {
      counterPosition++;
      if (counterPosition == numCounters) {
        break;
      } else {
        counters[counterPosition] = 1;
        isWhite = !isWhite;
      }
    }
    i++;
  }
  // If we read fully the last section of pixels and filled up our counters -- or filled
  // the last counter but ran off the side of the image, OK. Otherwise, a problem.
  if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
    throw NotFoundException.getNotFoundInstance();
  }
}
 
Example 9
Source File: Code39Reader.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
private static int[] findAsteriskPattern(BitArray row, int[] counters) throws NotFoundException {
  int width = row.getSize();
  int rowOffset = row.getNextSet(0);

  int counterPosition = 0;
  int patternStart = rowOffset;
  boolean isWhite = false;
  int patternLength = counters.length;

  for (int i = rowOffset; i < width; i++) {
    if (row.get(i) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        // Look for whitespace before start pattern, >= 50% of width of start pattern
        if (toNarrowWidePattern(counters) == ASTERISK_ENCODING &&
            row.isRange(Math.max(0, patternStart - ((i - patternStart) / 2)), patternStart, false)) {
          return new int[]{patternStart, i};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, patternLength - 2);
        counters[patternLength - 2] = 0;
        counters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 10
Source File: UPCEANReader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * @param row row of black/white values to search
 * @param rowOffset position to start search
 * @param whiteFirst if true, indicates that the pattern specifies white/black/white/...
 * pixel counts, otherwise, it is interpreted as black/white/black/...
 * @param pattern pattern of counts of number of black and white pixels that are being
 * searched for as a pattern
 * @param counters array of counters, as long as pattern, to re-use
 * @return start/end horizontal offset of guard pattern, as an array of two ints
 * @throws NotFoundException if pattern is not found
 */
private static int[] findGuardPattern(BitArray row,
                                      int rowOffset,
                                      boolean whiteFirst,
                                      int[] pattern,
                                      int[] counters) throws NotFoundException {
  int patternLength = pattern.length;
  int width = row.getSize();
  boolean isWhite = whiteFirst;
  rowOffset = whiteFirst ? row.getNextUnset(rowOffset) : row.getNextSet(rowOffset);
  int counterPosition = 0;
  int patternStart = rowOffset;
  for (int x = rowOffset; x < width; x++) {
    if (row.get(x) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
          return new int[]{patternStart, x};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, patternLength - 2);
        counters[patternLength - 2] = 0;
        counters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 11
Source File: ITFReader.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
/**
 * @param row       row of black/white values to search
 * @param rowOffset position to start search
 * @param pattern   pattern of counts of number of black and white pixels that are
 *                  being searched for as a pattern
 * @return start/end horizontal offset of guard pattern, as an array of two
 *         ints
 * @throws NotFoundException if pattern is not found
 */
private static int[] findGuardPattern(BitArray row,
                                      int rowOffset,
                                      int[] pattern) throws NotFoundException {

  // TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
  // merged to a single method.
  int patternLength = pattern.length;
  int[] counters = new int[patternLength];
  int width = row.getSize();
  boolean isWhite = false;

  int counterPosition = 0;
  int patternStart = rowOffset;
  for (int x = rowOffset; x < width; x++) {
    if (row.get(x) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
          return new int[]{patternStart, x};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, patternLength - 2);
        counters[patternLength - 2] = 0;
        counters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 12
Source File: ITFReader.java    From ScreenCapture with MIT License 5 votes vote down vote up
/**
 * @param row       row of black/white values to search
 * @param rowOffset position to start search
 * @param pattern   pattern of counts of number of black and white pixels that are
 *                  being searched for as a pattern
 * @return start/end horizontal offset of guard pattern, as an array of two
 *         ints
 * @throws NotFoundException if pattern is not found
 */
private static int[] findGuardPattern(BitArray row,
                                      int rowOffset,
                                      int[] pattern) throws NotFoundException {
  int patternLength = pattern.length;
  int[] counters = new int[patternLength];
  int width = row.getSize();
  boolean isWhite = false;

  int counterPosition = 0;
  int patternStart = rowOffset;
  for (int x = rowOffset; x < width; x++) {
    if (row.get(x) != isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
          return new int[]{patternStart, x};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
        counters[counterPosition - 1] = 0;
        counters[counterPosition] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 13
Source File: UPCEANReader.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * @param row row of black/white values to search
 * @param rowOffset position to start search
 * @param whiteFirst if true, indicates that the pattern specifies white/black/white/...
 * pixel counts, otherwise, it is interpreted as black/white/black/...
 * @param pattern pattern of counts of number of black and white pixels that are being
 * searched for as a pattern
 * @param counters array of counters, as long as pattern, to re-use
 * @return start/end horizontal offset of guard pattern, as an array of two ints
 * @throws NotFoundException if pattern is not found
 */
private static int[] findGuardPattern(BitArray row,
                                      int rowOffset,
                                      boolean whiteFirst,
                                      int[] pattern,
                                      int[] counters) throws NotFoundException {
  int patternLength = pattern.length;
  int width = row.getSize();
  boolean isWhite = whiteFirst;
  rowOffset = whiteFirst ? row.getNextUnset(rowOffset) : row.getNextSet(rowOffset);
  int counterPosition = 0;
  int patternStart = rowOffset;
  for (int x = rowOffset; x < width; x++) {
    if (row.get(x) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
          return new int[]{patternStart, x};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, patternLength - 2);
        counters[patternLength - 2] = 0;
        counters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 14
Source File: Code93Reader.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private int[] findAsteriskPattern(BitArray row) throws NotFoundException {
	int width = row.getSize();
	int rowOffset = row.getNextSet(0);

	Arrays.fill(counters, 0);
	int[] theCounters = counters;
	int patternStart = rowOffset;
	boolean isWhite = false;
	int patternLength = theCounters.length;

	int counterPosition = 0;
	for (int i = rowOffset; i < width; i++) {
		if (row.get(i) ^ isWhite) {
			theCounters[counterPosition]++;
		} else {
			if (counterPosition == patternLength - 1) {
				if (toPattern(theCounters) == ASTERISK_ENCODING) {
					return new int[] { patternStart, i };
				}
				patternStart += theCounters[0] + theCounters[1];
				System.arraycopy(theCounters, 2, theCounters, 0, patternLength - 2);
				theCounters[patternLength - 2] = 0;
				theCounters[patternLength - 1] = 0;
				counterPosition--;
			} else {
				counterPosition++;
			}
			theCounters[counterPosition] = 1;
			isWhite = !isWhite;
		}
	}
	throw NotFoundException.getNotFoundInstance();
}
 
Example 15
Source File: Code128Reader.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
private static int[] findStartPattern(BitArray row) throws NotFoundException {
  int width = row.getSize();
  int rowOffset = row.getNextSet(0);

  int counterPosition = 0;
  int[] counters = new int[6];
  int patternStart = rowOffset;
  boolean isWhite = false;
  int patternLength = counters.length;

  for (int i = rowOffset; i < width; i++) {
    if (row.get(i) != isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        float bestVariance = MAX_AVG_VARIANCE;
        int bestMatch = -1;
        for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
          float variance = patternMatchVariance(counters, CODE_PATTERNS[startCode],
              MAX_INDIVIDUAL_VARIANCE);
          if (variance < bestVariance) {
            bestVariance = variance;
            bestMatch = startCode;
          }
        }
        // Look for whitespace before start pattern, >= 50% of width of start pattern
        if (bestMatch >= 0 &&
            row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
          return new int[]{patternStart, i, bestMatch};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
        counters[counterPosition - 1] = 0;
        counters[counterPosition] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 16
Source File: Code128Reader.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static int[] findStartPattern(BitArray row) throws NotFoundException {
  int width = row.getSize();
  int rowOffset = row.getNextSet(0);

  int counterPosition = 0;
  int[] counters = new int[6];
  int patternStart = rowOffset;
  boolean isWhite = false;
  int patternLength = counters.length;

  for (int i = rowOffset; i < width; i++) {
    if (row.get(i) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        float bestVariance = MAX_AVG_VARIANCE;
        int bestMatch = -1;
        for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
          float variance = patternMatchVariance(counters, CODE_PATTERNS[startCode],
              MAX_INDIVIDUAL_VARIANCE);
          if (variance < bestVariance) {
            bestVariance = variance;
            bestMatch = startCode;
          }
        }
        // Look for whitespace before start pattern, >= 50% of width of start pattern
        if (bestMatch >= 0 &&
            row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
          return new int[]{patternStart, i, bestMatch};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, patternLength - 2);
        counters[patternLength - 2] = 0;
        counters[patternLength - 1] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 17
Source File: RSSExpandedReader.java    From weex with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 18
Source File: RSS14Reader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
private int[] findFinderPattern(BitArray row, int rowOffset, boolean rightFinderPattern)
    throws NotFoundException {

  int[] counters = getDecodeFinderCounters();
  counters[0] = 0;
  counters[1] = 0;
  counters[2] = 0;
  counters[3] = 0;

  int width = row.getSize();
  boolean isWhite = false;
  while (rowOffset < width) {
    isWhite = !row.get(rowOffset);
    if (rightFinderPattern == isWhite) {
      // Will encounter white first when searching for right finder pattern
      break;
    }
    rowOffset++;
  }

  int counterPosition = 0;
  int patternStart = rowOffset;
  for (int x = rowOffset; x < width; x++) {
    if (row.get(x) ^ isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == 3) {
        if (isFinderPattern(counters)) {
          return new int[]{patternStart, x};
        }
        patternStart += counters[0] + counters[1];
        counters[0] = counters[2];
        counters[1] = counters[3];
        counters[2] = 0;
        counters[3] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();

}
 
Example 19
Source File: Code128Reader.java    From ScreenCapture with MIT License 4 votes vote down vote up
private static int[] findStartPattern(BitArray row) throws NotFoundException {
  int width = row.getSize();
  int rowOffset = row.getNextSet(0);

  int counterPosition = 0;
  int[] counters = new int[6];
  int patternStart = rowOffset;
  boolean isWhite = false;
  int patternLength = counters.length;

  for (int i = rowOffset; i < width; i++) {
    if (row.get(i) != isWhite) {
      counters[counterPosition]++;
    } else {
      if (counterPosition == patternLength - 1) {
        float bestVariance = MAX_AVG_VARIANCE;
        int bestMatch = -1;
        for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
          float variance = patternMatchVariance(counters, CODE_PATTERNS[startCode],
              MAX_INDIVIDUAL_VARIANCE);
          if (variance < bestVariance) {
            bestVariance = variance;
            bestMatch = startCode;
          }
        }
        // Look for whitespace before start pattern, >= 50% of width of start pattern
        if (bestMatch >= 0 &&
            row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
          return new int[]{patternStart, i, bestMatch};
        }
        patternStart += counters[0] + counters[1];
        System.arraycopy(counters, 2, counters, 0, counterPosition - 1);
        counters[counterPosition - 1] = 0;
        counters[counterPosition] = 0;
        counterPosition--;
      } else {
        counterPosition++;
      }
      counters[counterPosition] = 1;
      isWhite = !isWhite;
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
 
Example 20
Source File: Code93Reader.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public Result decodeRow(int i, BitArray bitarray, Map map)
{
    int ai[] = a(bitarray);
    int j = bitarray.getNextSet(ai[1]);
    int k = bitarray.getSize();
    StringBuilder stringbuilder = new StringBuilder(20);
    int ai1[] = new int[6];
    do
    {
        recordPattern(bitarray, j, ai1);
        int l = a(ai1);
        if (l < 0)
        {
            throw NotFoundException.getNotFoundInstance();
        }
        char c1 = a(l);
        stringbuilder.append(c1);
        int i1 = ai1.length;
        int j1 = 0;
        int k1 = j;
        for (; j1 < i1; j1++)
        {
            k1 += ai1[j1];
        }

        int l1 = bitarray.getNextSet(k1);
        if (c1 == '*')
        {
            stringbuilder.deleteCharAt(-1 + stringbuilder.length());
            if (l1 == k || !bitarray.get(l1))
            {
                throw NotFoundException.getNotFoundInstance();
            }
            if (stringbuilder.length() < 2)
            {
                throw NotFoundException.getNotFoundInstance();
            } else
            {
                b(stringbuilder);
                stringbuilder.setLength(-2 + stringbuilder.length());
                String s = a(stringbuilder);
                float f = (float)(ai[1] + ai[0]) / 2.0F;
                float f1 = (float)(j + l1) / 2.0F;
                ResultPoint aresultpoint[] = new ResultPoint[2];
                aresultpoint[0] = new ResultPoint(f, i);
                aresultpoint[1] = new ResultPoint(f1, i);
                return new Result(s, null, aresultpoint, BarcodeFormat.CODE_93);
            }
        }
        j = l1;
    } while (true);
}