private static void embedTimingPatterns(ByteMatrix matrix) throws WriterException {
    // -8 is for skipping position detection patterns (size 7), and two horizontal/vertical
    // separation patterns (size 1). Thus, 8 = 7 + 1.
    for (int i = 8; i < matrix.getWidth() - 8; ++i) {
      int bit = (i + 1) % 2;
      // Horizontal line.
      if (!isValidValue(matrix.get(i, 6))) {
        throw new WriterException();
      }
      if (isEmpty(matrix.get(i, 6))) {
        matrix.set(i, 6, bit);
      }
      // Vertical line.
      if (!isValidValue(matrix.get(6, i))) {
        throw new WriterException();
      }
      if (isEmpty(matrix.get(6, i))) {
        matrix.set(6, i, bit);
      }
    }
  }