コード例 #1
0
  static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMatrix matrix)
      throws WriterException {
    BitArray typeInfoBits = new BitArray();
    makeTypeInfoBits(ecLevel, maskPattern, typeInfoBits);

    for (int i = 0; i < typeInfoBits.getSize(); ++i) {

      boolean bit = typeInfoBits.get(typeInfoBits.getSize() - 1 - i);

      int x1 = TYPE_INFO_COORDINATES[i][0];
      int y1 = TYPE_INFO_COORDINATES[i][1];
      matrix.set(x1, y1, bit);

      if (i < 8) {

        int x2 = matrix.getWidth() - i - 1;
        int y2 = 8;
        matrix.set(x2, y2, bit);
      } else {

        int x2 = 8;
        int y2 = matrix.getHeight() - 7 + (i - 8);
        matrix.set(x2, y2, bit);
      }
    }
  }
コード例 #2
0
  static void embedDataBits(BitArray dataBits, int maskPattern, ByteMatrix matrix)
      throws WriterException {
    int bitIndex = 0;
    int direction = -1;

    int x = matrix.getWidth() - 1;
    int y = matrix.getHeight() - 1;
    while (x > 0) {

      if (x == 6) {
        x -= 1;
      }
      while (y >= 0 && y < matrix.getHeight()) {
        for (int i = 0; i < 2; ++i) {
          int xx = x - i;

          if (!isEmpty(matrix.get(xx, y))) {
            continue;
          }
          boolean bit;
          if (bitIndex < dataBits.getSize()) {
            bit = dataBits.get(bitIndex);
            ++bitIndex;
          } else {

            bit = false;
          }

          if (maskPattern != -1) {
            if (MaskUtil.getDataMaskBit(maskPattern, xx, y)) {
              bit = !bit;
            }
          }
          matrix.set(xx, y, bit);
        }
        y += direction;
      }
      direction = -direction;
      y += direction;
      x -= 2;
    }

    if (bitIndex != dataBits.getSize()) {
      throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.getSize());
    }
  }
コード例 #3
0
  static void maybeEmbedVersionInfo(int version, ByteMatrix matrix) throws WriterException {
    if (version < 7) {
      return;
    }
    BitArray versionInfoBits = new BitArray();
    makeVersionInfoBits(version, versionInfoBits);

    int bitIndex = 6 * 3 - 1;
    for (int i = 0; i < 6; ++i) {
      for (int j = 0; j < 3; ++j) {

        boolean bit = versionInfoBits.get(bitIndex);
        bitIndex--;

        matrix.set(i, matrix.getHeight() - 11 + j, bit);

        matrix.set(matrix.getHeight() - 11 + j, i, bit);
      }
    }
  }