Skip to content

Commit 8a177f0

Browse files
committed
Update
1 parent eb7a0ad commit 8a177f0

File tree

2 files changed

+7
-42
lines changed

2 files changed

+7
-42
lines changed

QRCoder/Extensions/BitArrayExtensions.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,13 @@ internal static class BitArrayExtensions
1818
/// <param name="destinationOffset">The zero-based index in the destination <see cref="BitArray"/> at which storing begins.</param>
1919
/// <param name="count">The number of elements to copy.</param>
2020
/// <returns>The index in the destination <see cref="BitArray"/> immediately following the last copied element.</returns>
21-
public static int CopyTo(this BitArray source, int sourceOffset, BitArray destination, int destinationOffset, int count)
21+
public static int CopyTo(this BitArray source, BitArray destination, int sourceOffset, int destinationOffset, int count)
2222
{
2323
for (int i = 0; i < count; i++)
2424
{
2525
destination[destinationOffset + i] = source[sourceOffset + i];
2626
}
2727
return destinationOffset + count;
2828
}
29-
30-
/// <summary>
31-
/// Copies a specified number of elements from one <see cref="BitArray"/> to another starting at the specified offsets,
32-
/// and reverses every set of 8 bits during the copy operation.
33-
/// </summary>
34-
/// <param name="source">The source <see cref="BitArray"/> from which elements will be copied.</param>
35-
/// <param name="sourceOffset">The zero-based index in the source <see cref="BitArray"/> at which copying begins.</param>
36-
/// <param name="destination">The destination <see cref="BitArray"/> to which elements will be copied.</param>
37-
/// <param name="destinationOffset">The zero-based index in the destination <see cref="BitArray"/> at which storing begins.</param>
38-
/// <param name="count">The number of elements to copy. Must be a multiple of 8.</param>
39-
/// <returns>The index in the destination <see cref="BitArray"/> immediately following the last copied element.</returns>
40-
public static int CopyToRev8(this BitArray source, int sourceOffset, BitArray destination, int destinationOffset, int count)
41-
{
42-
if (count % 8 != 0)
43-
{
44-
throw new ArgumentException("Count must be a multiple of 8.", nameof(count));
45-
}
46-
47-
for (int i = 0; i < count; i += 8)
48-
{
49-
// Reverse the current set of 8 bits
50-
for (int j = 0; j < 8; j++)
51-
{
52-
destination[destinationOffset + i + j] = source[sourceOffset + i + (7 - j)];
53-
}
54-
}
55-
56-
return destinationOffset + count;
57-
}
58-
5929
}
6030
}

QRCoder/QRCodeGenerator.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ private static QRCodeData GenerateQrCode(BitArray bitArray, ECCLevel eccLevel, i
224224

225225
//Calculate error correction words
226226
var codeWordWithECC = new List<CodewordBlock>(eccInfo.BlocksInGroup1 + eccInfo.BlocksInGroup2);
227-
AddCodeWordBlocks(1, eccInfo.BlocksInGroup1, eccInfo.CodewordsInGroup1, bitArray, 0, bitArray.Length);
227+
AddCodeWordBlocks(1, eccInfo.BlocksInGroup1, eccInfo.CodewordsInGroup1, 0, bitArray.Length);
228228
int offset = eccInfo.BlocksInGroup1 * eccInfo.CodewordsInGroup1 * 8;
229-
AddCodeWordBlocks(2, eccInfo.BlocksInGroup2, eccInfo.CodewordsInGroup2, bitArray, offset, bitArray.Length - offset);
229+
AddCodeWordBlocks(2, eccInfo.BlocksInGroup2, eccInfo.CodewordsInGroup2, offset, bitArray.Length - offset);
230230

231231

232232
//Calculate interleaved code word lengths
@@ -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 = bitArray.CopyTo(i * 8 + codeBlock.CodeWordsOffset, interleavedData, pos, 8);
256+
pos = bitArray.CopyTo(interleavedData, i * 8 + codeBlock.CodeWordsOffset, pos, 8);
257257
}
258258
}
259259
for (var i = 0; i < eccInfo.ECCPerBlock; i++)
@@ -287,18 +287,13 @@ private static QRCodeData GenerateQrCode(BitArray bitArray, ECCLevel eccLevel, i
287287
ModulePlacer.AddQuietZone(qr);
288288
return qr;
289289

290-
void AddCodeWordBlocks(int blockNum, int blocksInGroup, int codewordsInGroup, BitArray bitArray2, int offset2, int count)
290+
void AddCodeWordBlocks(int blockNum, int blocksInGroup, int codewordsInGroup, int offset2, int count)
291291
{
292292
var groupLength = codewordsInGroup * 8;
293293
for (var i = 0; i < blocksInGroup; i++)
294294
{
295-
var eccWordList = CalculateECCWords(bitArray2, offset2, groupLength, eccInfo);
296-
codeWordWithECC.Add(new CodewordBlock(
297-
//bitArray2,
298-
offset2,
299-
groupLength,
300-
eccWordList)
301-
);
295+
var eccWordList = CalculateECCWords(bitArray, offset2, groupLength, eccInfo);
296+
codeWordWithECC.Add(new CodewordBlock(offset2, groupLength, eccWordList));
302297
offset2 += groupLength;
303298
}
304299
}

0 commit comments

Comments
 (0)