com.google.zxing.common.BitMatrix#getTopLeftOnBit ( )源码实例Demo

下面列出了com.google.zxing.common.BitMatrix#getTopLeftOnBit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MiBandDecompiled   文件: PDF417Reader.java
private static BitMatrix a(BitMatrix bitmatrix)
{
    int ai[] = bitmatrix.getTopLeftOnBit();
    int ai1[] = bitmatrix.getBottomRightOnBit();
    if (ai == null || ai1 == null)
    {
        throw NotFoundException.getNotFoundInstance();
    }
    int i = a(ai, bitmatrix);
    int j = ai[1];
    int k = ai1[1];
    int l = a(ai[0], j, bitmatrix);
    int i1 = (1 + (b(ai[0], j, bitmatrix) - l)) / i;
    int j1 = (1 + (k - j)) / i;
    if (i1 <= 0 || j1 <= 0)
    {
        throw NotFoundException.getNotFoundInstance();
    }
    int k1 = i >> 1;
    int l1 = j + k1;
    int i2 = l + k1;
    BitMatrix bitmatrix1 = new BitMatrix(i1, j1);
    for (int j2 = 0; j2 < j1; j2++)
    {
        int k2 = l1 + j2 * i;
        for (int l2 = 0; l2 < i1; l2++)
        {
            if (bitmatrix.get(i2 + l2 * i, k2))
            {
                bitmatrix1.set(l2, j2);
            }
        }

    }

    return bitmatrix1;
}
 
源代码2 项目: ScreenCapture   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
    if (right >= image.getWidth()) {
      // Abort if that would not make sense -- off image
      throw NotFoundException.getNotFoundInstance();
    }
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;

  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码3 项目: Tesseract-OCR-Scanner   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
    if (right >= image.getWidth()) {
      // Abort if that would not make sense -- off image
      throw NotFoundException.getNotFoundInstance();
    }
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;

  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码4 项目: QrCodeScanner   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
    if (right >= image.getWidth()) {
      // Abort if that would not make sense -- off image
      throw NotFoundException.getNotFoundInstance();
    }
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;

  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码5 项目: ZXing-Orient   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];
  
  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;
  
  // But careful that this does not sample off the edge
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - (right - 1);
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - (bottom - 1);
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码6 项目: ZXing-Orient   文件: DataMatrixReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize / 2;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];
  
  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;
  
  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize / 2;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome
 * image which contains only an unrotated, unskewed, image of a code, with
 * some white border around it. This is a specialized method that works
 * exceptionally fast in this special case.
 * 
 * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix)
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

    int[] leftTopBlack = image.getTopLeftOnBit();
    int[] rightBottomBlack = image.getBottomRightOnBit();
    if (leftTopBlack == null || rightBottomBlack == null) {
        throw NotFoundException.getNotFoundInstance();
    }

    int moduleSize = moduleSize(leftTopBlack, image);

    int top = leftTopBlack[1];
    int bottom = rightBottomBlack[1];
    int left = leftTopBlack[0];
    int right = rightBottomBlack[0];

    if (bottom - top != right - left) {
        // Special case, where bottom-right module wasn't black so we found
        // something else in
        // the last row
        // Assume it's a square, so use height as the width
        right = left + (bottom - top);
    }

    int matrixWidth = (right - left + 1) / moduleSize;
    int matrixHeight = (bottom - top + 1) / moduleSize;
    if (matrixWidth <= 0 || matrixHeight <= 0) {
        throw NotFoundException.getNotFoundInstance();
    }
    if (matrixHeight != matrixWidth) {
        // Only possibly decode square regions
        throw NotFoundException.getNotFoundInstance();
    }

    // Push in the "border" by half the module width so that we start
    // sampling in the middle of the module. Just in case the image is a
    // little off, this will help recover.
    int nudge = moduleSize >> 1;
    top += nudge;
    left += nudge;

    // Now just read off the bits
    BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
    for (int y = 0; y < matrixHeight; y++) {
        int iOffset = top + y * moduleSize;
        for (int x = 0; x < matrixWidth; x++) {
            if (image.get(left + x * moduleSize, iOffset)) {
                bits.set(x, y);
            }
        }
    }
    return bits;
}
 
源代码10 项目: weex   文件: DataMatrixReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize / 2;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码11 项目: barcodescanner-lib-aar   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];
  
  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
    if (right >= image.getWidth()) {
      // Abort if that would not make sense -- off image
      throw NotFoundException.getNotFoundInstance();
    }
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;
  
  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码12 项目: barcodescanner-lib-aar   文件: DataMatrixReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize / 2;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码13 项目: reacteu-app   文件: PDF417Reader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = findPatternStart(leftTopBlack[0], top, image);
  int right = findPatternEnd(leftTopBlack[0], top, image);

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize >> 1;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码14 项目: reacteu-app   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix)
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码15 项目: reacteu-app   文件: DataMatrixReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 *
 * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix)
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  int moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  int matrixWidth = (right - left + 1) / moduleSize;
  int matrixHeight = (bottom - top + 1) / moduleSize;
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = moduleSize >> 1;
  top += nudge;
  left += nudge;

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + y * moduleSize;
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + x * moduleSize, iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}
 
源代码16 项目: MiBandDecompiled   文件: QRCodeReader.java
private static BitMatrix a(BitMatrix bitmatrix)
{
    int ai[] = bitmatrix.getTopLeftOnBit();
    int ai1[] = bitmatrix.getBottomRightOnBit();
    if (ai == null || ai1 == null)
    {
        throw NotFoundException.getNotFoundInstance();
    }
    float f = a(ai, bitmatrix);
    int i = ai[1];
    int j = ai1[1];
    int k = ai[0];
    int l = ai1[0];
    if (j - i != l - k)
    {
        l = k + (j - i);
    }
    int i1 = Math.round((float)(1 + (l - k)) / f);
    int j1 = Math.round((float)(1 + (j - i)) / f);
    if (i1 <= 0 || j1 <= 0)
    {
        throw NotFoundException.getNotFoundInstance();
    }
    if (j1 != i1)
    {
        throw NotFoundException.getNotFoundInstance();
    }
    int k1 = Math.round(f / 2.0F);
    int l1 = i + k1;
    int i2 = k + k1;
    BitMatrix bitmatrix1 = new BitMatrix(i1, j1);
    for (int j2 = 0; j2 < j1; j2++)
    {
        int k2 = l1 + (int)(f * (float)j2);
        for (int l2 = 0; l2 < i1; l2++)
        {
            if (bitmatrix.get(i2 + (int)(f * (float)l2), k2))
            {
                bitmatrix1.set(l2, j2);
            }
        }

    }

    return bitmatrix1;
}
 
源代码17 项目: barterli_android   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome
 * image which contains only an unrotated, unskewed, image of a code, with
 * some white border around it. This is a specialized method that works
 * exceptionally fast in this special case.
 * 
 * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix)
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

    int[] leftTopBlack = image.getTopLeftOnBit();
    int[] rightBottomBlack = image.getBottomRightOnBit();
    if (leftTopBlack == null || rightBottomBlack == null) {
        throw NotFoundException.getNotFoundInstance();
    }

    int moduleSize = moduleSize(leftTopBlack, image);

    int top = leftTopBlack[1];
    int bottom = rightBottomBlack[1];
    int left = leftTopBlack[0];
    int right = rightBottomBlack[0];

    if (bottom - top != right - left) {
        // Special case, where bottom-right module wasn't black so we found
        // something else in
        // the last row
        // Assume it's a square, so use height as the width
        right = left + (bottom - top);
    }

    int matrixWidth = (right - left + 1) / moduleSize;
    int matrixHeight = (bottom - top + 1) / moduleSize;
    if (matrixWidth <= 0 || matrixHeight <= 0) {
        throw NotFoundException.getNotFoundInstance();
    }
    if (matrixHeight != matrixWidth) {
        // Only possibly decode square regions
        throw NotFoundException.getNotFoundInstance();
    }

    // Push in the "border" by half the module width so that we start
    // sampling in the middle of the module. Just in case the image is a
    // little off, this will help recover.
    int nudge = moduleSize >> 1;
    top += nudge;
    left += nudge;

    // Now just read off the bits
    BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
    for (int y = 0; y < matrixHeight; y++) {
        int iOffset = top + y * moduleSize;
        for (int x = 0; x < matrixWidth; x++) {
            if (image.get(left + x * moduleSize, iOffset)) {
                bits.set(x, y);
            }
        }
    }
    return bits;
}
 
源代码18 项目: RipplePower   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome
 * image which contains only an unrotated, unskewed, image of a code, with
 * some white border around it. This is a specialized method that works
 * exceptionally fast in this special case.
 * 
 * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

	int[] leftTopBlack = image.getTopLeftOnBit();
	int[] rightBottomBlack = image.getBottomRightOnBit();
	if (leftTopBlack == null || rightBottomBlack == null) {
		throw NotFoundException.getNotFoundInstance();
	}

	float moduleSize = moduleSize(leftTopBlack, image);

	int top = leftTopBlack[1];
	int bottom = rightBottomBlack[1];
	int left = leftTopBlack[0];
	int right = rightBottomBlack[0];

	// Sanity check!
	if (left >= right || top >= bottom) {
		throw NotFoundException.getNotFoundInstance();
	}

	if (bottom - top != right - left) {
		// Special case, where bottom-right module wasn't black so we found
		// something else in the last row
		// Assume it's a square, so use height as the width
		right = left + (bottom - top);
	}

	int matrixWidth = Math.round((right - left + 1) / moduleSize);
	int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
	if (matrixWidth <= 0 || matrixHeight <= 0) {
		throw NotFoundException.getNotFoundInstance();
	}
	if (matrixHeight != matrixWidth) {
		// Only possibly decode square regions
		throw NotFoundException.getNotFoundInstance();
	}

	// Push in the "border" by half the module width so that we start
	// sampling in the middle of the module. Just in case the image is a
	// little off, this will help recover.
	int nudge = (int) (moduleSize / 2.0f);
	top += nudge;
	left += nudge;

	// But careful that this does not sample off the edge
	int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - (right - 1);
	if (nudgedTooFarRight > 0) {
		if (nudgedTooFarRight > nudge) {
			// Neither way fits; abort
			throw NotFoundException.getNotFoundInstance();
		}
		left -= nudgedTooFarRight;
	}
	int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - (bottom - 1);
	if (nudgedTooFarDown > 0) {
		if (nudgedTooFarDown > nudge) {
			// Neither way fits; abort
			throw NotFoundException.getNotFoundInstance();
		}
		top -= nudgedTooFarDown;
	}

	// Now just read off the bits
	BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
	for (int y = 0; y < matrixHeight; y++) {
		int iOffset = top + (int) (y * moduleSize);
		for (int x = 0; x < matrixWidth; x++) {
			if (image.get(left + (int) (x * moduleSize), iOffset)) {
				bits.set(x, y);
			}
		}
	}
	return bits;
}
 
源代码19 项目: RipplePower   文件: DataMatrixReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome
 * image which contains only an unrotated, unskewed, image of a code, with
 * some white border around it. This is a specialized method that works
 * exceptionally fast in this special case.
 * 
 * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

	int[] leftTopBlack = image.getTopLeftOnBit();
	int[] rightBottomBlack = image.getBottomRightOnBit();
	if (leftTopBlack == null || rightBottomBlack == null) {
		throw NotFoundException.getNotFoundInstance();
	}

	int moduleSize = moduleSize(leftTopBlack, image);

	int top = leftTopBlack[1];
	int bottom = rightBottomBlack[1];
	int left = leftTopBlack[0];
	int right = rightBottomBlack[0];

	int matrixWidth = (right - left + 1) / moduleSize;
	int matrixHeight = (bottom - top + 1) / moduleSize;
	if (matrixWidth <= 0 || matrixHeight <= 0) {
		throw NotFoundException.getNotFoundInstance();
	}

	// Push in the "border" by half the module width so that we start
	// sampling in the middle of the module. Just in case the image is a
	// little off, this will help recover.
	int nudge = moduleSize / 2;
	top += nudge;
	left += nudge;

	// Now just read off the bits
	BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight);
	for (int y = 0; y < matrixHeight; y++) {
		int iOffset = top + y * moduleSize;
		for (int x = 0; x < matrixWidth; x++) {
			if (image.get(left + x * moduleSize, iOffset)) {
				bits.set(x, y);
			}
		}
	}
	return bits;
}
 
源代码20 项目: Telegram   文件: QRCodeReader.java
/**
 * This method detects a code in a "pure" image -- that is, pure monochrome image
 * which contains only an unrotated, unskewed, image of a code, with some white border
 * around it. This is a specialized method that works exceptionally fast in this special
 * case.
 */
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {

  int[] leftTopBlack = image.getTopLeftOnBit();
  int[] rightBottomBlack = image.getBottomRightOnBit();
  if (leftTopBlack == null || rightBottomBlack == null) {
    throw NotFoundException.getNotFoundInstance();
  }

  float moduleSize = moduleSize(leftTopBlack, image);

  int top = leftTopBlack[1];
  int bottom = rightBottomBlack[1];
  int left = leftTopBlack[0];
  int right = rightBottomBlack[0];

  // Sanity check!
  if (left >= right || top >= bottom) {
    throw NotFoundException.getNotFoundInstance();
  }

  if (bottom - top != right - left) {
    // Special case, where bottom-right module wasn't black so we found something else in the last row
    // Assume it's a square, so use height as the width
    right = left + (bottom - top);
    if (right >= image.getWidth()) {
      // Abort if that would not make sense -- off image
      throw NotFoundException.getNotFoundInstance();
    }
  }

  int matrixWidth = Math.round((right - left + 1) / moduleSize);
  int matrixHeight = Math.round((bottom - top + 1) / moduleSize);
  if (matrixWidth <= 0 || matrixHeight <= 0) {
    throw NotFoundException.getNotFoundInstance();
  }
  if (matrixHeight != matrixWidth) {
    // Only possibly decode square regions
    throw NotFoundException.getNotFoundInstance();
  }

  // Push in the "border" by half the module width so that we start
  // sampling in the middle of the module. Just in case the image is a
  // little off, this will help recover.
  int nudge = (int) (moduleSize / 2.0f);
  top += nudge;
  left += nudge;

  // But careful that this does not sample off the edge
  // "right" is the farthest-right valid pixel location -- right+1 is not necessarily
  // This is positive by how much the inner x loop below would be too large
  int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - right;
  if (nudgedTooFarRight > 0) {
    if (nudgedTooFarRight > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    left -= nudgedTooFarRight;
  }
  // See logic above
  int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - bottom;
  if (nudgedTooFarDown > 0) {
    if (nudgedTooFarDown > nudge) {
      // Neither way fits; abort
      throw NotFoundException.getNotFoundInstance();
    }
    top -= nudgedTooFarDown;
  }

  // Now just read off the bits
  BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight, 1);
  for (int y = 0; y < matrixHeight; y++) {
    int iOffset = top + (int) (y * moduleSize);
    for (int x = 0; x < matrixWidth; x++) {
      if (image.get(left + (int) (x * moduleSize), iOffset)) {
        bits.set(x, y);
      }
    }
  }
  return bits;
}