QrUtil class
Static Fields
int G15 #
static int G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
int G15_MASK #
static int G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
int G18 #
static int G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
Static Methods
int getBCHDigit(int data) #
static int getBCHDigit(int data) { var digit = 0; while (data != 0) { digit++; data >>= 1; } return digit; }
int getBCHTypeInfo(int data) #
static int getBCHTypeInfo(int data) { var d = data << 10; while (getBCHDigit(d) - getBCHDigit(G15) >= 0) { d ^= (G15 << (getBCHDigit(d) - getBCHDigit(G15))); } return ((data << 10) | d) ^ G15_MASK; }
int getBCHTypeNumber(int data) #
static int getBCHTypeNumber(int data) { var d = data << 12; while (getBCHDigit(d) - getBCHDigit(G18) >= 0) { d ^= (G18 << (getBCHDigit(d) - getBCHDigit(G18))); } return (data << 12) | d; }
QrPolynomial getErrorCorrectPolynomial(int errorCorrectLength) #
static QrPolynomial getErrorCorrectPolynomial(int errorCorrectLength) { var a = new QrPolynomial([1], 0); for (var i = 0; i < errorCorrectLength; i++) { a = a.multiply(new QrPolynomial([1, QrMath.gexp(i)], 0)); } return a; }
int getLengthInBits(int mode, int type) #
static int getLengthInBits(int mode, int type) { if (1 <= type && type < 10) { // 1 - 9 switch (mode) { case QrMode.MODE_NUMBER: return 10; case QrMode.MODE_ALPHA_NUM: return 9; case QrMode.MODE_8BIT_BYTE: return 8; case QrMode.MODE_KANJI: return 8; default: throw 'mode:$mode'; } } else if (type < 27) { // 10 - 26 switch (mode) { case QrMode.MODE_NUMBER: return 12; case QrMode.MODE_ALPHA_NUM: return 11; case QrMode.MODE_8BIT_BYTE: return 16; case QrMode.MODE_KANJI: return 10; default: throw 'mode:$mode'; } } else if (type < 41) { // 27 - 40 switch (mode) { case QrMode.MODE_NUMBER: return 14; case QrMode.MODE_ALPHA_NUM: return 13; case QrMode.MODE_8BIT_BYTE: return 16; case QrMode.MODE_KANJI: return 12; default: throw 'mode:$mode'; } } else { throw 'type:$type'; } }
num getLostPoint(QrCode qrCode) #
static num getLostPoint(QrCode qrCode) { var moduleCount = qrCode.moduleCount; var lostPoint = 0.0; int row, col; // LEVEL1 for (row = 0; row < moduleCount; row++) { for (col = 0; col < moduleCount; col++) { var sameCount = 0; var dark = qrCode.isDark(row, col); for (var r = -1; r <= 1; r++) { if (row + r < 0 || moduleCount <= row + r) { continue; } for (var c = -1; c <= 1; c++) { if (col + c < 0 || moduleCount <= col + c) { continue; } if (r == 0 && c == 0) { continue; } if (dark == qrCode.isDark(row + r, col + c)) { sameCount++; } } } if (sameCount > 5) { lostPoint += (3 + sameCount - 5); } } } // LEVEL2 for (row = 0; row < moduleCount - 1; row++) { for (col = 0; col < moduleCount - 1; col++) { var count = 0; if (qrCode.isDark(row, col)) count++; if (qrCode.isDark(row + 1, col)) count++; if (qrCode.isDark(row, col + 1)) count++; if (qrCode.isDark(row + 1, col + 1)) count++; if (count == 0 || count == 4) { lostPoint += 3; } } } // LEVEL3 for (row = 0; row < moduleCount; row++) { for (col = 0; col < moduleCount - 6; col++) { if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) { lostPoint += 40; } } } for (col = 0; col < moduleCount; col++) { for (row = 0; row < moduleCount - 6; row++) { if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) { lostPoint += 40; } } } // LEVEL4 var darkCount = 0; for (col = 0; col < moduleCount; col++) { for (row = 0; row < moduleCount; row++) { if (qrCode.isDark(row, col)) { darkCount++; } } } var ratio = (100 * darkCount / moduleCount / moduleCount - 50).abs() / 5; lostPoint += ratio * 10; return lostPoint; }
bool getMask(int maskPattern, int i, int j) #
static bool getMask(int maskPattern, int i, int j) { switch (maskPattern) { case QrMaskPattern.PATTERN000: return (i + j) % 2 == 0; case QrMaskPattern.PATTERN001: return i % 2 == 0; case QrMaskPattern.PATTERN010: return j % 3 == 0; case QrMaskPattern.PATTERN011: return (i + j) % 3 == 0; case QrMaskPattern.PATTERN100: return ((i ~/ 2) + (j ~/ 3)) % 2 == 0; case QrMaskPattern.PATTERN101: return (i * j) % 2 + (i * j) % 3 == 0; case QrMaskPattern.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 == 0; case QrMaskPattern.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 == 0; default: throw 'bad maskPattern:$maskPattern'; } }
List<int> getPatternPosition(int typeNumber) #
static List<int> getPatternPosition(int typeNumber) { return _PATTERN_POSITION_TABLE[typeNumber - 1]; }
Methods
bool operator ==(other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode
it should override the
equality operator as well to maintain consistency.
external int hashCode();
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
Type get runtimeType() #
A representation of the runtime type of the object.
external Type get runtimeType;
String toString() #
Returns a string representation of this object.
external String toString();