private void MakeImpl(bool test, QRMaskPattern maskPattern) { m_moduleCount = this.m_typeNumber * 4 + 17; m_modules = new bool?[m_moduleCount][]; for (int row = 0; row < m_moduleCount; row++) { m_modules[row] = new bool?[(m_moduleCount)]; for (var col = 0; col < m_moduleCount; col++) { m_modules[row][col] = null; //(col + row) % 3; } } this.SetupPositionProbePattern(0, 0); this.SetupPositionProbePattern(m_moduleCount - 7, 0); this.SetupPositionProbePattern(0, m_moduleCount - 7); this.SetupPositionAdjustPattern(); this.SetupTimingPattern(); this.setupTypeInfo(test, maskPattern); if (m_typeNumber >= 7) { this.setupTypeNumber(test); } if (this.m_dataCache == null) { this.m_dataCache = CreateData(this.m_typeNumber, this.m_errorCorrectLevel, this.m_dataList); } MapData(this.m_dataCache, maskPattern); }
private void MakeImpl(bool test, QRMaskPattern maskPattern) { this.m_moduleCount = this.m_typeNumber * 4 + 17; this.m_modules = new bool?[this.m_moduleCount][]; for (int index = 0; index < this.m_moduleCount; index++) { this.m_modules[index] = new bool?[this.m_moduleCount]; for (int index2 = 0; index2 < this.m_moduleCount; index2++) { this.m_modules[index][index2] = null; } } this.SetupPositionProbePattern(0, 0); this.SetupPositionProbePattern(this.m_moduleCount - 7, 0); this.SetupPositionProbePattern(0, this.m_moduleCount - 7); this.SetupPositionAdjustPattern(); this.SetupTimingPattern(); this.setupTypeInfo(test, maskPattern); bool flag = this.m_typeNumber >= 7; if (flag) { this.setupTypeNumber(test); } bool flag2 = this.m_dataCache == null; if (flag2) { this.m_dataCache = this.CreateData(this.m_typeNumber, this.m_errorCorrectLevel, this.m_dataList); } this.MapData(this.m_dataCache, maskPattern); }
private void MakeImpl(bool test, QRMaskPattern maskPattern) { _moduleCount = _typeNumber * 4 + 17; _modules = new bool?[_moduleCount][]; for (int row = 0; row < _moduleCount; row++) { _modules[row] = new bool?[(_moduleCount)]; for (var col = 0; col < _moduleCount; col++) { _modules[row][col] = null; //(col + row) % 3; } } SetupPositionProbePattern(0, 0); SetupPositionProbePattern(_moduleCount - 7, 0); SetupPositionProbePattern(0, _moduleCount - 7); SetupPositionAdjustPattern(); SetupTimingPattern(); SetupTypeInfo(test, maskPattern); if (_typeNumber >= 7) { SetupTypeNumber(test); } if (_dataCache == null) { _dataCache = CreateData(_typeNumber, _errorCorrectLevel, _dataList); } MapData(_dataCache, maskPattern); }
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; } } } }
private void MapData(DataCache data, QRMaskPattern maskPattern) { int num = -1; int i = this.m_moduleCount - 1; int num2 = 7; int index = 0; for (int num3 = this.m_moduleCount - 1; num3 > 0; num3 -= 2) { bool flag2 = num3 == 6; if (flag2) { num3--; } do { for (int index2 = 0; index2 < 2; index2++) { bool flag3 = !this.m_modules[i][num3 - index2].HasValue; if (flag3) { bool flag = false; bool flag4 = index < data.Count; if (flag4) { flag = ((Convert.ToUInt32(data[index]) >> num2 & 1u) == 1u); } bool mask = QRUtil.GetMask(maskPattern, i, num3 - index2); if (mask) { flag = !flag; } this.m_modules[i][num3 - index2] = new bool?(flag); num2--; bool flag5 = num2 == -1; if (flag5) { index++; num2 = 7; } } } i += num; }while (i >= 0 && this.m_moduleCount > i); i -= num; num = -num; } }
private void setupTypeInfo(bool test, QRMaskPattern maskPattern) { int bchTypeInfo = QRUtil.GetBCHTypeInfo((int)((int)this.m_errorCorrectLevel << 3 | (int)maskPattern)); for (int index = 0; index < 15; index++) { bool flag = !test && (bchTypeInfo >> index & 1) == 1; bool flag3 = index < 6; if (flag3) { this.m_modules[index][8] = new bool?(flag); } else { bool flag4 = index < 8; if (flag4) { this.m_modules[index + 1][8] = new bool?(flag); } else { this.m_modules[this.m_moduleCount - 15 + index][8] = new bool?(flag); } } } for (int index2 = 0; index2 < 15; index2++) { bool flag2 = !test && (bchTypeInfo >> index2 & 1) == 1; bool flag5 = index2 < 8; if (flag5) { this.m_modules[8][this.m_moduleCount - index2 - 1] = new bool?(flag2); } else { bool flag6 = index2 < 9; if (flag6) { this.m_modules[8][15 - index2 - 1 + 1] = new bool?(flag2); } else { this.m_modules[8][15 - index2 - 1] = new bool?(flag2); } } } this.m_modules[this.m_moduleCount - 8][8] = new bool?(!test); }
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 num = 0.0; QRMaskPattern qrMaskPattern = QRMaskPattern.PATTERN000; for (int index = 0; index < 8; index++) { this.MakeImpl(true, (QRMaskPattern)index); double lostPoint = QRUtil.GetLostPoint(this); bool flag = index == 0 || num > lostPoint; if (flag) { num = lostPoint; qrMaskPattern = (QRMaskPattern)index; } } return(qrMaskPattern); }
internal static bool GetMask(QRMaskPattern maskPattern, int i, int j) { bool result; switch (maskPattern) { case QRMaskPattern.PATTERN000: result = ((i + j) % 2 == 0); break; case QRMaskPattern.PATTERN001: result = (i % 2 == 0); break; case QRMaskPattern.PATTERN010: result = (j % 3 == 0); break; case QRMaskPattern.PATTERN011: result = ((i + j) % 3 == 0); break; case QRMaskPattern.PATTERN100: result = ((Math.Floor(i / 2m) + Math.Floor(j / 3m)) % 2m == decimal.Zero); break; case QRMaskPattern.PATTERN101: result = (i * j % 2 + i * j % 3 == 0); break; case QRMaskPattern.PATTERN110: result = ((i * j % 2 + i * j % 3) % 2 == 0); break; case QRMaskPattern.PATTERN111: result = ((i * j % 3 + (i + j) % 2) % 2 == 0); break; default: throw new Error("bad maskPattern:" + maskPattern); } return(result); }
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); }
internal static bool GetMask(QRMaskPattern maskPattern, int i, int j) { switch (maskPattern) { case QRMaskPattern.PATTERN000: return((i + j) % 2 == 0); case QRMaskPattern.PATTERN001: return(i % 2 == 0); case QRMaskPattern.PATTERN010: return(j % 3 == 0); case QRMaskPattern.PATTERN011: return((i + j) % 3 == 0); case QRMaskPattern.PATTERN100: return((Math.Floor(i / 2) + Math.Floor(j / 3)) % 2 == 0); case QRMaskPattern.PATTERN101: return((i * j) % 2 + (i * j) % 3 == 0); case QRMaskPattern.PATTERN110: return(((i * j) % 2 + (i * j) % 3) % 2 == 0); case QRMaskPattern.PATTERN111: return(((i * j) % 3 + (i + j) % 2) % 2 == 0); default: throw new Error("bad maskPattern:" + maskPattern); } }
internal static bool GetMask(QRMaskPattern maskPattern, int i, int j) { switch (maskPattern) { case QRMaskPattern.PATTERN000: return((i + j) % 2 == 0); case QRMaskPattern.PATTERN001: return(i % 2 == 0); case QRMaskPattern.PATTERN010: return(j % 3 == 0); case QRMaskPattern.PATTERN011: return((i + j) % 3 == 0); case QRMaskPattern.PATTERN100: return((Math.Floor(Convert.ToDouble(i) / 2.0) + Math.Floor(Convert.ToDouble(j) / 3.0)) % 2 == 0); case QRMaskPattern.PATTERN101: return((i * j) % 2 + (i * j) % 3 == 0); case QRMaskPattern.PATTERN110: return(((i * j) % 2 + (i * j) % 3) % 2 == 0); case QRMaskPattern.PATTERN111: return(((i * j) % 3 + (i + j) % 2) % 2 == 0); default: throw new ErrorException("bad maskPattern:" + maskPattern, ErrorCode.BadMaskPattern); } }