Skip to content

Commit d237ca6

Browse files
authored
Merge pull request #517 from Shane32/comments
Add code comments to QR code generation
2 parents e7a7eb2 + 66a4e27 commit d237ca6

15 files changed

+771
-89
lines changed

QRCoder/QRCodeGenerator.AlignmentPattern.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ namespace QRCoder
44
{
55
public partial class QRCodeGenerator
66
{
7+
/// <summary>
8+
/// Represents the alignment pattern used in QR codes, which helps ensure the code remains readable even if it is somewhat distorted.
9+
/// Each QR code version has its own specific alignment pattern locations which this struct encapsulates.
10+
/// </summary>
711
private struct AlignmentPattern
812
{
13+
/// <summary>
14+
/// The version of the QR code. Higher versions have more complex and numerous alignment patterns.
15+
/// </summary>
916
public int Version;
17+
18+
/// <summary>
19+
/// A list of points where alignment patterns are located within the QR code matrix.
20+
/// Each point represents the center of an alignment pattern.
21+
/// </summary>
1022
public List<Point> PatternPositions;
1123
}
1224
}

QRCoder/QRCodeGenerator.CodewordBlock.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents a block of codewords in a QR code. QR codes are divided into several blocks for error correction purposes.
7+
/// Each block contains a series of data codewords followed by error correction codewords.
8+
/// </summary>
59
private struct CodewordBlock
610
{
11+
/// <summary>
12+
/// Initializes a new instance of the CodewordBlock struct with specified arrays of code words and error correction (ECC) words.
13+
/// </summary>
14+
/// <param name="codeWords">The array of data codewords for this block. Data codewords carry the actual information.</param>
15+
/// <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>
716
public CodewordBlock(byte[] codeWords, byte[] eccWords)
817
{
918
this.CodeWords = codeWords;
1019
this.ECCWords = eccWords;
1120
}
1221

22+
/// <summary>
23+
/// Gets the data codewords associated with this block.
24+
/// </summary>
1325
public byte[] CodeWords { get; }
26+
27+
/// <summary>
28+
/// Gets the error correction codewords associated with this block.
29+
/// </summary>
1430
public byte[] ECCWords { get; }
1531
}
1632
}

QRCoder/QRCodeGenerator.ECCInfo.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents the error correction coding (ECC) information for a specific version and error correction level of a QR code.
7+
/// </summary>
58
private struct ECCInfo
69
{
10+
/// <summary>
11+
/// Initializes a new instance of the ECCInfo struct with specified properties.
12+
/// </summary>
13+
/// <param name="version">The version number of the QR code.</param>
14+
/// <param name="errorCorrectionLevel">The error correction level used in the QR code.</param>
15+
/// <param name="totalDataCodewords">The total number of data codewords for this version and error correction level.</param>
16+
/// <param name="eccPerBlock">The number of error correction codewords per block.</param>
17+
/// <param name="blocksInGroup1">The number of blocks in group 1.</param>
18+
/// <param name="codewordsInGroup1">The number of codewords in each block of group 1.</param>
19+
/// <param name="blocksInGroup2">The number of blocks in group 2, if any.</param>
20+
/// <param name="codewordsInGroup2">The number of codewords in each block of group 2, if any.</param>
721
public ECCInfo(int version, ECCLevel errorCorrectionLevel, int totalDataCodewords, int eccPerBlock, int blocksInGroup1,
822
int codewordsInGroup1, int blocksInGroup2, int codewordsInGroup2)
923
{
@@ -16,13 +30,45 @@ public ECCInfo(int version, ECCLevel errorCorrectionLevel, int totalDataCodeword
1630
this.BlocksInGroup2 = blocksInGroup2;
1731
this.CodewordsInGroup2 = codewordsInGroup2;
1832
}
33+
34+
/// <summary>
35+
/// Gets the version number of the QR code.
36+
/// </summary>
1937
public int Version { get; }
38+
39+
/// <summary>
40+
/// Gets the error correction level of the QR code.
41+
/// </summary>
2042
public ECCLevel ErrorCorrectionLevel { get; }
43+
44+
/// <summary>
45+
/// Gets the total number of data codewords for this version and error correction level.
46+
/// </summary>
2147
public int TotalDataCodewords { get; }
48+
49+
/// <summary>
50+
/// Gets the number of error correction codewords per block.
51+
/// </summary>
2252
public int ECCPerBlock { get; }
53+
54+
/// <summary>
55+
/// Gets the number of blocks in group 1.
56+
/// </summary>
2357
public int BlocksInGroup1 { get; }
58+
59+
/// <summary>
60+
/// Gets the number of codewords in each block of group 1.
61+
/// </summary>
2462
public int CodewordsInGroup1 { get; }
63+
64+
/// <summary>
65+
/// Gets the number of blocks in group 2, if any.
66+
/// </summary>
2567
public int BlocksInGroup2 { get; }
68+
69+
/// <summary>
70+
/// Gets the number of codewords in each block of group 2, if any.
71+
/// </summary>
2672
public int CodewordsInGroup2 { get; }
2773
}
2874
}

QRCoder/QRCodeGenerator.ECCLevel.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@
33
public partial class QRCodeGenerator
44
{
55
/// <summary>
6-
/// Error correction level. These define the tolerance levels for how much of the code can be lost before the code cannot be recovered.
6+
/// Defines the levels of error correction available in QR codes.
7+
/// Each level specifies the proportion of data that can be recovered if the QR code is partially obscured or damaged.
78
/// </summary>
89
public enum ECCLevel
910
{
1011
/// <summary>
11-
/// 7% may be lost before recovery is not possible
12+
/// Level L: Low error correction (approximately 7% of data can be recovered).
13+
/// This level allows the highest data density.
1214
/// </summary>
1315
L,
16+
1417
/// <summary>
15-
/// 15% may be lost before recovery is not possible
18+
/// Level M: Medium error correction (approximately 15% of data can be recovered).
19+
/// Offers a balance between data capacity and error recovery.
1620
/// </summary>
1721
M,
22+
1823
/// <summary>
19-
/// 25% may be lost before recovery is not possible
24+
/// Level Q: Quartile error correction (approximately 25% of data can be recovered).
25+
/// More robust error correction at the cost of reduced data capacity.
2026
/// </summary>
2127
Q,
28+
2229
/// <summary>
23-
/// 30% may be lost before recovery is not possible
30+
/// Level H: High error correction (approximately 30% of data can be recovered).
31+
/// Provides the highest level of error recovery, ideal for environments with high risk of data loss.
2432
/// </summary>
2533
H
2634
}

QRCoder/QRCodeGenerator.EciMode.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,34 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Enumerates the Extended Channel Interpretation (ECI) modes used in QR codes to handle different character encoding standards.
7+
/// ECI mode allows QR codes to efficiently encode data using character sets other than the default ISO-8859-1.
8+
/// </summary>
59
public enum EciMode
610
{
11+
/// <summary>
12+
/// Default encoding mode (typically ISO-8859-1). Used when no ECI mode is explicitly specified.
13+
/// This mode is assumed in basic QR codes where no extended character sets are needed.
14+
/// </summary>
715
Default = 0,
16+
17+
/// <summary>
18+
/// Specifies the use of the ISO-8859-1 character set, covering most Western European languages.
19+
/// This mode explicitly sets the encoding to ISO-8859-1, which includes characters used in languages such as English, French, German, and Spanish.
20+
/// </summary>
821
Iso8859_1 = 3,
22+
23+
/// <summary>
24+
/// Specifies the use of the ISO-8859-2 character set, which is primarily used for Central and Eastern European languages.
25+
/// This includes characters used in languages such as Polish, Czech, Slovak, Hungarian, and Romanian.
26+
/// </summary>
927
Iso8859_2 = 4,
28+
29+
/// <summary>
30+
/// Specifies the use of UTF-8 encoding.
31+
/// UTF-8 can encode any Unicode character and is useful for QR codes that need to support multi-language content.
32+
/// </summary>
1033
Utf8 = 26
1134
}
1235
}

QRCoder/QRCodeGenerator.EncodingMode.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
namespace QRCoder
1+
using System;
2+
3+
namespace QRCoder
24
{
35
public partial class QRCodeGenerator
46
{
7+
/// <summary>
8+
/// Specifies the encoding modes for the characters in a QR code.
9+
/// </summary>
510
private enum EncodingMode
611
{
12+
/// <summary>
13+
/// Numeric encoding mode, which is used to encode numeric data (digits 0-9).
14+
/// Three characters are encoded into 10 bits.
15+
/// </summary>
716
Numeric = 1,
17+
18+
/// <summary>
19+
/// Alphanumeric encoding mode, which is used to encode alphanumeric characters (0-9, A-Z, space, and some punctuation).
20+
/// Two characters are encoded into 11 bits.
21+
/// </summary>
822
Alphanumeric = 2,
23+
24+
/// <summary>
25+
/// Byte encoding mode, primarily using the ISO-8859-1 character set. Each character is encoded into 8 bits.
26+
/// When combined with ECI, it can be adapted to use other character sets.
27+
/// </summary>
928
Byte = 4,
29+
30+
/// <summary>
31+
/// Kanji encoding mode, which is used to encode characters from the Shift JIS character set, primarily for Japanese Kanji and Kana characters.
32+
/// One character is encoded into 13 bits. This mode is not currently supported by QRCoder.
33+
/// </summary>
1034
Kanji = 8,
35+
36+
/// <summary>
37+
/// Extended Channel Interpretation (ECI) mode, which specifies a character set via an 8-bit number followed by one of the other encoding modes.
38+
/// This allows adapting the byte encoding to accommodate various global text encodings.
39+
/// </summary>
1140
ECI = 7
1241
}
1342
}

0 commit comments

Comments
 (0)