public void Write(QRBitBuffer buffer) { for (int i = 0; i < m_data.Length; ++i) { //item buffer.Put(m_data[i], 8); } ///buffer = Data; }
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)); }