@ -155,6 +155,11 @@ namespace qrcodegen {
// 21 and 177 (inclusive). This is equal to version * 4 + 17.
public readonly size : int ;
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
// Even if a QR Code is created with automatic masking requested (mask = -1),
// the resulting object still has a mask value between 0 and 7.
public readonly mask : int ;
// The modules of this QR Code (false = light, true = dark).
// Immutable after constructor finishes. Accessed through getModule().
private readonly module s : Array < Array < boolean > > = [ ] ;
@ -179,15 +184,12 @@ namespace qrcodegen {
dataCodewords : Readonly < Array < byte > > ,
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
// Even if a QR Code is created with automatic masking requested (mask = -1),
// the resulting object still has a mask value between 0 and 7.
public readonly mask : int ) {
msk : int ) {
// Check scalar arguments
if ( version < QrCode . MIN_VERSION || version > QrCode . MAX_VERSION )
throw "Version value out of range" ;
if ( m a sk < - 1 || m a sk > 7 )
if ( m sk < - 1 || m sk > 7 )
throw "Mask value out of range" ;
this . size = version * 4 + 17 ;
@ -206,24 +208,24 @@ namespace qrcodegen {
this . drawCodewords ( allCodewords ) ;
// Do masking
if ( m a sk == - 1 ) { // Automatically choose best mask
if ( m sk == - 1 ) { // Automatically choose best mask
let minPenalty : int = 1000000000 ;
for ( let i = 0 ; i < 8 ; i ++ ) {
this . applyMask ( i ) ;
this . drawFormatBits ( i ) ;
const penalty : int = this . getPenaltyScore ( ) ;
if ( penalty < minPenalty ) {
m a sk = i ;
m sk = i ;
minPenalty = penalty ;
}
this . applyMask ( i ) ; // Undoes the mask due to XOR
}
}
if ( m a sk < 0 || m a sk > 7 )
if ( m sk < 0 || m sk > 7 )
throw "Assertion error" ;
this . mask = m a sk;
this . applyMask ( m a sk) ; // Apply the final choice of mask
this . drawFormatBits ( m a sk) ; // Overwrite old format bits
this . mask = m sk;
this . applyMask ( m sk) ; // Apply the final choice of mask
this . drawFormatBits ( m sk) ; // Overwrite old format bits
this . isFunction = [ ] ;
}