embedTypeInfo static method

void embedTypeInfo(
  1. ErrorCorrectionLevel ecLevel,
  2. int maskPattern,
  3. ByteMatrix matrix
)

Implementation

static void embedTypeInfo(
  ErrorCorrectionLevel ecLevel,
  int maskPattern,
  ByteMatrix matrix,
) {
  final typeInfoBits = BitArray();
  makeTypeInfoBits(ecLevel, maskPattern, typeInfoBits);

  for (int i = 0; i < typeInfoBits.size; ++i) {
    // Place bits in LSB to MSB order.  LSB (least significant bit) is the last value in
    // "typeInfoBits".
    final bit = typeInfoBits.get(typeInfoBits.size - 1 - i);

    // Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46).
    final coordinates = _typeInfoCoordinates[i];
    final x1 = coordinates[0];
    final y1 = coordinates[1];
    matrix.set(x1, y1, bit ? 1 : 0);

    int x2;
    int y2;
    if (i < 8) {
      // Right top corner.
      x2 = matrix.width - i - 1;
      y2 = 8;
    } else {
      // Left bottom corner.
      x2 = 8;
      y2 = matrix.height - 7 + (i - 8);
    }
    matrix.set(x2, y2, bit ? 1 : 0);
  }
}