code: static QrCodeMaskPattern selectMask( QrCode qr ) {
  		int N = qr.getNumberOfModules();
  		int totalBytes = QrCode.VERSION_INFO[qr.version].codewords;
  		List<Point2D_I32> locations = QrCode.LOCATION_BITS[qr.version];
  
  		QrCodeMaskPattern bestMask = null;
  		double bestScore = Double.MAX_VALUE;
  
  		PackedBits8 bits = new PackedBits8();
  		bits.size = totalBytes * 8;
  		bits.data = qr.rawbits;
  
  		if (bits.size > locations.size())
  			throw new RuntimeException("BUG in code");
  
  		// Bit value of 0 = white. 1 = black
  		QrCodeCodeWordLocations matrix = new QrCodeCodeWordLocations(qr.version);
  		for (QrCodeMaskPattern mask : QrCodeMaskPattern.values()) {
  			double score = scoreMask(N, locations, bits, matrix, mask);
  			if (score < bestScore) {
  				bestScore = score;
  				bestMask = mask;
  			}
  		}
  		return bestMask;
  	}
docs: Selects a mask by minimizing the appearance of certain patterns. This is inspired by
  what was described in the reference manual. I had a hard time understanding some
  of the specifics so I improvised.