@@ -115,8 +115,10 @@ public static int MaskCode(QRCodeData qrCode, int version, List<Rectangle> block
115
115
116
116
// Temporary QRCodeData object to test different mask patterns without altering the original.
117
117
var qrTemp = new QRCodeData ( version ) ;
118
- foreach ( var pattern in MaskPattern . Patterns )
118
+ for ( var maskPattern = 0 ; maskPattern < 8 ; maskPattern ++ )
119
119
{
120
+ var patternFunc = MaskPattern . Patterns [ maskPattern ] ;
121
+
120
122
// Reset the temporary QR code to the current state of the actual QR code.
121
123
for ( var y = 0 ; y < size ; y ++ )
122
124
{
@@ -127,7 +129,7 @@ public static int MaskCode(QRCodeData qrCode, int version, List<Rectangle> block
127
129
}
128
130
129
131
// Place format information using the current mask pattern.
130
- var formatStr = GetFormatString ( eccLevel , pattern . Key - 1 ) ;
132
+ var formatStr = GetFormatString ( eccLevel , maskPattern ) ;
131
133
ModulePlacer . PlaceFormat ( qrTemp , formatStr ) ;
132
134
133
135
// Place version information if applicable.
@@ -144,14 +146,14 @@ public static int MaskCode(QRCodeData qrCode, int version, List<Rectangle> block
144
146
{
145
147
if ( ! IsBlocked ( new Rectangle ( x , y , 1 , 1 ) , blockedModules ) )
146
148
{
147
- qrTemp . ModuleMatrix [ y ] [ x ] ^= pattern . Value ( x , y ) ;
148
- qrTemp . ModuleMatrix [ x ] [ y ] ^= pattern . Value ( y , x ) ;
149
+ qrTemp . ModuleMatrix [ y ] [ x ] ^= patternFunc ( x , y ) ;
150
+ qrTemp . ModuleMatrix [ x ] [ y ] ^= patternFunc ( y , x ) ;
149
151
}
150
152
}
151
153
152
154
if ( ! IsBlocked ( new Rectangle ( x , x , 1 , 1 ) , blockedModules ) )
153
155
{
154
- qrTemp . ModuleMatrix [ x ] [ x ] ^= pattern . Value ( x , x ) ;
156
+ qrTemp . ModuleMatrix [ x ] [ x ] ^= patternFunc ( x , x ) ;
155
157
}
156
158
}
157
159
@@ -160,7 +162,7 @@ public static int MaskCode(QRCodeData qrCode, int version, List<Rectangle> block
160
162
// Select the pattern with the lowest score, indicating better QR code readability.
161
163
if ( ! selectedPattern . HasValue || patternScore > score )
162
164
{
163
- selectedPattern = pattern . Key ;
165
+ selectedPattern = maskPattern ;
164
166
patternScore = score ;
165
167
}
166
168
}
@@ -182,7 +184,7 @@ public static int MaskCode(QRCodeData qrCode, int version, List<Rectangle> block
182
184
qrCode . ModuleMatrix [ x ] [ x ] ^= MaskPattern . Patterns [ selectedPattern . Value ] ( x , x ) ;
183
185
}
184
186
}
185
- return selectedPattern . Value - 1 ;
187
+ return selectedPattern . Value ;
186
188
}
187
189
188
190
/// <summary>
0 commit comments