// copy ctor private SymbolTemplate(SymbolTemplate prototype) { this._modules = prototype._modules.CreateCopy(); this.ErrorCorrectionLevel = prototype.ErrorCorrectionLevel; this.Version = prototype.Version; this.Width = prototype.Width; }
private SymbolTemplate(int version) { // See ISO/IEC 18004:2006(E), Sec. 5.3.1.1 for how versions map to sizes. Debug.Assert(1 <= version && version <= 40); Version = version; Width = 21 + 4 * (version - 1); _modules = new ModuleBlock(Width); PopulateReservedModuleBits(); }
// Draws a square of the specified width whose top-left corner is at the specified coords private static void DrawSquare(ModuleBlock modules, int row, int col, int width, ModuleFlag type, bool xor = false) { DrawRect(modules, row, col, width, width, type, xor); }
// copy ctor private ModuleBlock(ModuleBlock original) { this._buffer = (byte[])(original._buffer.Clone()); this._width = original._width; }
private uint SelectAndApplyMaskingPattern() { // Masks the QR code to minimize chance of data transmission error // See ISO/IEC 18004:2006(E), Sec. 6.8 SymbolTemplate[] candidates = new SymbolTemplate[_dataMaskPredicates.Length - 1]; for (int i = 0; i < candidates.Length; i++) { SymbolTemplate candidate = new SymbolTemplate(this); // copy ctor candidate.ApplyMask(_dataMaskPredicates[i]); candidates[i] = candidate; } int lowestPenaltyScoreValue = candidates[0].CalculatePenaltyScore(); int lowestPenaltyScoreIndex = 0; for (int i = 1; i < candidates.Length; i++) { int candidatePenaltyScoreValue = candidates[i].CalculatePenaltyScore(); if (candidatePenaltyScoreValue < lowestPenaltyScoreValue) { lowestPenaltyScoreValue = candidatePenaltyScoreValue; lowestPenaltyScoreIndex = i; } } // copy the candidate modules array into me; copy by ref is fine this._modules = candidates[lowestPenaltyScoreIndex]._modules; return (uint)lowestPenaltyScoreIndex; }
private static void DrawRect(ModuleBlock modules, int row, int col, int width, int height, ModuleFlag type, bool xor = false) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { modules.Set(row + i, col + j, type, !xor); } } }