/// <summary> /// The do mask. /// </summary> /// <param name="codeMask"> /// The mask. /// </param> private void DoMask(QrMask codeMask) { if (this.debugData != null) { this.debugData.Append( "------------------ Step 9 ------------------\n- Executing mask on data pixels: " + BinaryExtensions.BinaryToString(codeMask.GetBits()) + "\n"); } int counter = 0; for (int i = 0; i < this.picture.GetLength(0); i++) { for (int j = 0; j < this.picture.GetLength(1); j++) { int x = this.picture.GetLength(0) - i - 1; int y = this.picture.GetLength(1) - j - 1; if (codeMask.Test(y, x) && (this.staticData[x, y] == false) && (this.picture[x, y] != QrPixel.Empty)) { this.picture[x, y] = (this.picture[x, y] == QrPixel.White) ? QrPixel.Black : QrPixel.White; counter++; if ((this.breakPoint == QrBreakPoint.Mask) && (this.debugData != null)) { this.picture[x, y] = QrPixel.Mask; } } } } if (this.debugData != null) { this.debugData.Append("- Mask (" + codeMask + ") written to: " + counter + " pixels.\n\n"); } }
/// <summary> /// Calculate <c>QR</c> code format /// </summary> /// <param name="error"> /// The error code information. /// </param> /// <param name="mask"> /// The mask. /// </param> private void CalculateFormat(QrError error, QrMask mask) { // Get error bits if (this.debugData != null) { this.debugData.Append("- Calculating format bits...\n"); } // Get 5 bits of format information int formatInfo = (QrErrorBits.GetBits(error) << 3) | BinaryExtensions.BinToDec(mask.GetBits()); if (this.debugData != null) { this.debugData.Append( "- Format information error and mask bits: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo)) + "\n"); this.debugData.Append("- Calculating BCH (15,5) code for information bits...\n"); } int bchCode = QrBoseChaudhuriHocquenghem.CalculateBch(formatInfo, QrConst.GenPolyFormat); if (this.debugData != null) { this.debugData.Append( "- BCH (15,5) error code: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(bchCode)) + "\n"); } // Append BCH code to format info formatInfo = (formatInfo << 10) | bchCode; if (this.debugData != null) { this.debugData.Append( "- Format information with appended BCH: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo)) + "\n"); this.debugData.Append( "- Calculating XOR with format constant: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(QrConst.ConstFormatXor)) + "\n"); } formatInfo = formatInfo ^ QrConst.ConstFormatXor; if (this.debugData != null) { this.debugData.Append( "- Final format: " + BinaryExtensions.BinaryToString(BinaryExtensions.DecToBin(formatInfo, 15)) + "\n"); } List <bool> formatBits = BinaryExtensions.DecToBin(formatInfo, 15); // Reverse, because our QRCode is inserting backwards formatBits.Reverse(); foreach (bool t in formatBits) { this.output.Enqueue(t); } }