Skip to content

Commit eb7a0ad

Browse files
committed
Update
1 parent c992946 commit eb7a0ad

File tree

2 files changed

+5
-46
lines changed

2 files changed

+5
-46
lines changed

QRCoder/QRCodeGenerator.CodewordBlock.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,16 @@ private struct CodewordBlock
1313
/// <summary>
1414
/// Initializes a new instance of the CodewordBlock struct with specified arrays of code words and error correction (ECC) words.
1515
/// </summary>
16-
/// <param name="codeWords">The array of data codewords for this block. Data codewords carry the actual information.</param>
16+
/// <param name="codeWordsOffset">The offset of the data codewords within the main BitArray. Data codewords carry the actual information.</param>
17+
/// <param name="codeWordsLength">The length in bits of the data codewords within the main BitArray.</param>
1718
/// <param name="eccWords">The array of error correction codewords for this block. These codewords help recover the data if the QR code is damaged.</param>
18-
public CodewordBlock(/* byte[] codeWordsArray, */ BitArray codeWords, int codeWordsOffset, int codeWordsLength, byte[] eccWords)
19+
public CodewordBlock(int codeWordsOffset, int codeWordsLength, byte[] eccWords)
1920
{
20-
//this.CodeWordsArray = codeWordsArray;
21-
this.CodeWords = codeWords;
2221
this.CodeWordsOffset = codeWordsOffset;
2322
this.CodeWordsLength = codeWordsLength;
2423
this.ECCWords = eccWords;
2524
}
2625

27-
//public byte[] CodeWordsArray { get; }
28-
29-
/// <summary>
30-
/// Gets the data codewords associated with this block.
31-
/// </summary>
32-
public BitArray CodeWords { get; }
33-
3426
/// <summary>
3527
/// Gets the offset of the data codewords in the BitArray.
3628
/// </summary>

QRCoder/QRCodeGenerator.cs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private static QRCodeData GenerateQrCode(BitArray bitArray, ECCLevel eccLevel, i
253253
foreach (var codeBlock in codeWordWithECC)
254254
{
255255
if (codeBlock.CodeWordsLength / 8 > i)
256-
pos = codeBlock.CodeWords.CopyTo(i * 8 + codeBlock.CodeWordsOffset, interleavedData, pos, 8);
256+
pos = bitArray.CopyTo(i * 8 + codeBlock.CodeWordsOffset, interleavedData, pos, 8);
257257
}
258258
}
259259
for (var i = 0; i < eccInfo.ECCPerBlock; i++)
@@ -292,11 +292,9 @@ void AddCodeWordBlocks(int blockNum, int blocksInGroup, int codewordsInGroup, Bi
292292
var groupLength = codewordsInGroup * 8;
293293
for (var i = 0; i < blocksInGroup; i++)
294294
{
295-
//var bitBlockList = BinaryStringToBitBlockByteList(bitArray2, offset2, groupLength);
296295
var eccWordList = CalculateECCWords(bitArray2, offset2, groupLength, eccInfo);
297296
codeWordWithECC.Add(new CodewordBlock(
298-
//bitBlockList,
299-
bitArray2,
297+
//bitArray2,
300298
offset2,
301299
groupLength,
302300
eccWordList)
@@ -624,37 +622,6 @@ private static Polynom CalculateGeneratorPolynom(int numEccWords)
624622
return generatorPolynom; // Return the completed generator polynomial
625623
}
626624

627-
/// <summary>
628-
/// Converts a segment of a BitArray into a list of bytes where each byte represents a consecutive block of 8 bits from the BitArray.
629-
/// </summary>
630-
private static byte[] BinaryStringToBitBlockByteList(BitArray bitString, int offset, int count)
631-
{
632-
const int blockSize = 8;
633-
if (count % blockSize != 0)
634-
ThrowCountMustBeMultipleOf8Exception();
635-
var numberOfBlocks = (int)((uint)count / blockSize);
636-
var blocklist = new byte[numberOfBlocks];
637-
638-
int j = 0;
639-
count += offset;
640-
for (int i = offset; i < count; i += blockSize)
641-
{
642-
blocklist[j++] = (byte)(
643-
(bitString[i] ? 128 : 0) +
644-
(bitString[i + 1] ? 64 : 0) +
645-
(bitString[i + 2] ? 32 : 0) +
646-
(bitString[i + 3] ? 16 : 0) +
647-
(bitString[i + 4] ? 8 : 0) +
648-
(bitString[i + 5] ? 4 : 0) +
649-
(bitString[i + 6] ? 2 : 0) +
650-
(bitString[i + 7] ? 1 : 0));
651-
}
652-
653-
return blocklist;
654-
655-
void ThrowCountMustBeMultipleOf8Exception() => throw new ArgumentOutOfRangeException(nameof(count), "Count must be a multiple of 8.");
656-
}
657-
658625
/// <summary>
659626
/// Converts a segment of a BitArray into its decimal (integer) equivalent.
660627
/// </summary>

0 commit comments

Comments
 (0)