예제 #1
0
  @Test
  public void testRealloc() {
    BitMatrix bm = new BitMatrix(4, 4);

    Assert.assertFalse(bm.resize(16, 1));
    Assert.assertTrue(bm.getWidth() == 16);
    Assert.assertTrue(bm.getHeight() == 1);
    Assert.assertTrue(bm.resize(8, 3));
    Assert.assertTrue(bm.getWidth() == 8);
    Assert.assertTrue(bm.getHeight() == 3);
  }
예제 #2
0
  @Test
  public void testNotEmpty() {
    BitMatrix bm = new BitMatrix(4, 3);

    Assert.assertFalse(bm.isEmpty());
    Assert.assertTrue(bm.getWidth() == 4);
    Assert.assertTrue(bm.getHeight() == 3);
    Assert.assertTrue(bm.getSize() == 12);
  }
예제 #3
0
  @Test
  public void testEmpty() {
    BitMatrix bm = new BitMatrix();

    Assert.assertTrue(bm.isEmpty());
    Assert.assertTrue(bm.getWidth() == 0);
    Assert.assertTrue(bm.getHeight() == 0);
    Assert.assertTrue(bm.getSize() == 0);
  }
예제 #4
0
  /**
   * This method detects a Data Matrix code in a "pure" image -- that is, pure monochrome image
   * which contains only an unrotated, unskewed, image of a Data Matrix 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 {
    // Now need to determine module size in pixels

    int height = image.getHeight();
    int width = image.getWidth();
    int minDimension = Math.min(height, width);

    // First, skip white border by tracking diagonally from the top left down and to the right:
    int borderWidth = 0;
    while (borderWidth < minDimension && !image.get(borderWidth, borderWidth)) {
      borderWidth++;
    }
    if (borderWidth == minDimension) {
      throw NotFoundException.getNotFoundInstance();
    }

    // And then keep tracking across the top-left black module to determine module size
    int moduleEnd = borderWidth + 1;
    while (moduleEnd < width && image.get(moduleEnd, borderWidth)) {
      moduleEnd++;
    }
    if (moduleEnd == width) {
      throw NotFoundException.getNotFoundInstance();
    }

    int moduleSize = moduleEnd - borderWidth;

    // And now find where the bottommost black module on the first column ends
    int columnEndOfSymbol = height - 1;
    while (columnEndOfSymbol >= 0 && !image.get(borderWidth, columnEndOfSymbol)) {
      columnEndOfSymbol--;
    }
    if (columnEndOfSymbol < 0) {
      throw NotFoundException.getNotFoundInstance();
    }
    columnEndOfSymbol++;

    // Make sure width of barcode is a multiple of module size
    if ((columnEndOfSymbol - borderWidth) % moduleSize != 0) {
      throw NotFoundException.getNotFoundInstance();
    }
    int dimension = (columnEndOfSymbol - borderWidth) / moduleSize;

    // 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.
    borderWidth += moduleSize >> 1;

    int sampleDimension = borderWidth + (dimension - 1) * moduleSize;
    if (sampleDimension >= width || sampleDimension >= height) {
      throw NotFoundException.getNotFoundInstance();
    }

    // Now just read off the bits
    BitMatrix bits = new BitMatrix(dimension);
    for (int i = 0; i < dimension; i++) {
      int iOffset = borderWidth + i * moduleSize;
      for (int j = 0; j < dimension; j++) {
        if (image.get(borderWidth + j * moduleSize, iOffset)) {
          bits.set(j, i);
        }
      }
    }
    return bits;
  }