private void SetupPositionAdjustPattern() { var pos = QRUtil.GetPatternPosition(m_typeNumber); for (var i = 0; i < pos.Length; i++) { for (var j = 0; j < pos.Length; j++) { var row = pos[i]; var col = pos[j]; if (this.m_modules[row][col] != null) { continue; } for (var r = -2; r <= 2; r++) { for (var c = -2; c <= 2; c++) { if (r == -2 || r == 2 || c == -2 || c == 2 || (r == 0 && c == 0)) { this.m_modules[row + r][col + c] = true; } else { this.m_modules[row + r][col + c] = false; } } } } } }
private void MapData(DataCache data, QRMaskPattern maskPattern) { int inc = -1; int row = (int)this.m_moduleCount - 1; int bitIndex = 7; int byteIndex = 0; for (var col = this.m_moduleCount - 1; col > 0; col -= 2) { if (col == 6) { col--; } while (true) { for (int c = 0; c < 2; c++) { if (this.m_modules[row][col - c] == null) { bool dark = false; if (byteIndex < data.Count) { dark = (((Convert.ToUInt32(data[byteIndex]) >> bitIndex) & 1) == 1); } bool mask = QRUtil.GetMask(maskPattern, (int)row, col - c); if (mask) { dark = !dark; } this.m_modules[row][col - c] = dark; bitIndex--; if (bitIndex == -1) { byteIndex++; bitIndex = 7; } } } row += inc; if (row < 0 || this.m_moduleCount <= row) { row -= inc; inc = -inc; break; } } } }
internal static int GetBCHTypeNumber(int data) { int d = data << 12; while (QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G18) >= 0) { d ^= (QRUtil.G18 << (QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G18))); } return((data << 12) | d); }
internal static int GetBCHTypeInfo(int data) { int d = (data << 10); int s = 0; while ((s = (int)(QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G15))) >= 0) { d ^= (Convert.ToInt32(QRUtil.G15) << s); } return((int)((data << 10) | d) ^ QRUtil.G15_MASK); }
private void setupTypeNumber(bool test) { var bits = QRUtil.GetBCHTypeNumber(m_typeNumber); for (var i = 0; i < 18; i++) { var mod = (!test && ((bits >> i) & 1) == 1); this.m_modules[(int)Math.Floor((Decimal)i / 3)][i % 3 + this.m_moduleCount - 8 - 3] = mod; } for (var i = 0; i < 18; i++) { var mod = (!test && ((bits >> i) & 1) == 1); this.m_modules[i % 3 + this.m_moduleCount - 8 - 3][(int)Math.Floor((Decimal)i / 3)] = mod; } }
private void setupTypeInfo(bool test, QRMaskPattern maskPattern) { var data = ((int)this.m_errorCorrectLevel << 3) | (int)maskPattern; var bits = QRUtil.GetBCHTypeInfo(data); // vertical for (var i = 0; i < 15; i++) { var mod = (!test && ((bits >> i) & 1) == 1); if (i < 6) { this.m_modules[i][8] = mod; } else if (i < 8) { this.m_modules[i + 1][8] = mod; } else { this.m_modules[this.m_moduleCount - 15 + i][8] = mod; } } // horizontal for (var i = 0; i < 15; i++) { var mod = (!test && ((bits >> i) & 1) == 1); if (i < 8) { this.m_modules[8][this.m_moduleCount - i - 1] = mod; } else if (i < 9) { this.m_modules[8][15 - i - 1 + 1] = mod; } else { this.m_modules[8][15 - i - 1] = mod; } } // fixed module this.m_modules[this.m_moduleCount - 8][8] = (!test); }
private QRMaskPattern GetBestMaskPattern() { double minLostPoint = 0; QRMaskPattern pattern = 0; for (int i = 0; i < 8; i++) { this.MakeImpl(true, (QRMaskPattern)i); double lostPoint = QRUtil.GetLostPoint(this); if (i == 0 || minLostPoint > lostPoint) { minLostPoint = lostPoint; pattern = (QRMaskPattern)i; } } return(pattern); }
private DataCache CreateBytes(QRBitBuffer buffer, List <QRRSBlock> rsBlocks) { int offset = 0; int maxDcCount = 0; int maxEcCount = 0; var dcdata = new DataCache[(rsBlocks.Count)]; var ecdata = new DataCache[(rsBlocks.Count)]; for (int r = 0; r < rsBlocks.Count; r++) { int dcCount = rsBlocks[(int)r].DataCount; int ecCount = rsBlocks[(int)r].TotalCount - dcCount; maxDcCount = Math.Max(maxDcCount, dcCount); maxEcCount = Math.Max(maxEcCount, ecCount); dcdata[r] = new DataCache(dcCount); for (int i = 0; i < dcdata[r].Count; i++) { dcdata[r][i] = 0xff & buffer.m_buffer[(int)(i + offset)]; } offset += dcCount; QRPolynomial rsPoly = QRUtil.GetErrorCorrectPolynomial(ecCount); QRPolynomial rawPoly = new QRPolynomial(dcdata[r], rsPoly.GetLength() - 1); var modPoly = rawPoly.Mod(rsPoly); ecdata[r] = new DataCache(rsPoly.GetLength() - 1); for (int i = 0; i < ecdata[r].Count; i++) { int modIndex = i + modPoly.GetLength() - (int)ecdata[r].Count; ecdata[r][i] = (modIndex >= 0) ? modPoly.Get(modIndex) : 0; } } int totalCodeCount = 0; for (int i = 0; i < rsBlocks.Count; i++) { totalCodeCount += rsBlocks[(int)i].TotalCount; } var data = new DataCache(totalCodeCount); int index = 0; for (int i = 0; i < maxDcCount; i++) { for (int r = 0; r < rsBlocks.Count; r++) { if (i < dcdata[r].Count) { data[index++] = dcdata[r][i]; } } } for (int i = 0; i < maxEcCount; i++) { for (int r = 0; r < rsBlocks.Count; r++) { if (i < ecdata[r].Count) { data[index++] = ecdata[r][i]; } } } return(data); }
private DataCache CreateData(int typeNumber, QRErrorCorrectLevel errorCorrectLevel, List <QR8bitByte> dataList) { List <QRRSBlock> rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel); var buffer = new QRBitBuffer(); for (int i = 0; i < dataList.Count; i++) { QR8bitByte data = dataList[i]; buffer.Put((int)data.Mode, 4); buffer.Put(data.Length, QRUtil.GetLengthInBits(data.Mode, typeNumber)); data.Write(buffer); } // calc num max data. int totalDataCount = 0; for (var i = 0; i < rsBlocks.Count; i++) { totalDataCount += rsBlocks[i].DataCount; } if (buffer.GetLengthInBits() > totalDataCount * 8) { throw new Error("code length overflow. (" + buffer.GetLengthInBits() + ">" + totalDataCount * 8 + ")"); } // end code if (buffer.GetLengthInBits() + 4 <= totalDataCount * 8) { buffer.Put(0, 4); } // padding while (buffer.GetLengthInBits() % 8 != 0) { buffer.PutBit(false); } // padding while (true) { if (buffer.GetLengthInBits() >= totalDataCount * 8) { break; } buffer.Put(QRCode.PAD0, 8); if (buffer.GetLengthInBits() >= totalDataCount * 8) { break; } buffer.Put(QRCode.PAD1, 8); } return(CreateBytes(buffer, rsBlocks)); }