Changeset 8a84522
- Timestamp:
- Oct 25, 2016 3:04:55 PM (4 years ago)
- Branches:
- master
- Children:
- d2569fa
- Parents:
- d2f7b65
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
LICENSE.txt
rd2f7b65 r8a84522 208 208 Copyright (c) 2008 Alexander von Gernler. All rights reserved. 209 209 See licenses/LICENSE-BSD.txt 210 Zxing :210 Zxing 3.3.0: 211 211 See licenses/LICENSE-Apache2.0.txt 212 212 -
apps/imagegen/zxing/CHANGES
rd2f7b65 r8a84522 356 356 357 357 - Small bug fixes 358 359 3.3.0 (16 Sep 2016) 360 361 - Minor core API additions like 'Result.getNumBits', raw bytes for Aztec 362 - Small changes for Java 9 compatibility 363 - BS 4.7.6 release with Android API 23 support 364 - TIFF support in online decoder 365 - Many small bug fixes, typo fixes and project build improvements -
apps/imagegen/zxing/README-i2p.txt
rd2f7b65 r8a84522 3 3 We've added a build.xml for ant. 4 4 5 Pulled from https://github.com/zxing/zxing on Jan. 4, 2016, 6 rev 4e3abafe3008e02695f894eccf05f8257fca4ee9 dated Dec. 9, 2015. 5 https://github.com/zxing/zxing/releases Version 3.3.0 Sept. 16, 2016 -
apps/imagegen/zxing/README.md
rd2f7b65 r8a84522 1 1 <img align="right" src="https://raw.github.com/wiki/zxing/zxing/zxing-logo.png"/> 2 3 ##Get Started Developing 4 To get started, please visit: https://github.com/zxing/zxing/wiki/Getting-Started-Developing 2 5 3 6 ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing … … 51 54 | [python-zxing](https://github.com/oostendo/python-zxing) | bindings for Python 52 55 | [ZXing .NET](http://zxingnet.codeplex.com/) | port to .NET and C#, and related Windows platform 56 | [php-qrcode-detector-decoder](https://github.com/khanamiryan/php-qrcode-detector-decoder) | port to PHP 53 57 54 58 ### Other related third-party open source projects … … 62 66 ## Links 63 67 64 * [Online Decoder](http://zxing.org/w/decode.jspx) 65 * [QR Code Generator](http://zxing.appspot.com/generator) 66 * [Javadoc](http://zxing.github.io/zxing/apidocs/) 67 * [Documentation Site](http://zxing.github.io/zxing/) 68 * [Google+](https://plus.google.com/u/0/b/105889184633382354358/105889184633382354358/posts) 68 * [Online Decoder](https://zxing.org/w/decode.jspx) 69 * [QR Code Generator](https://zxing.appspot.com/generator) 70 * [Javadoc](https://zxing.github.io/zxing/apidocs/) 71 * [Documentation Site](https://zxing.github.io/zxing/) 69 72 70 73 ## Contacting -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/EncodeHintType.java
rd2f7b65 r8a84522 96 96 */ 97 97 AZTEC_LAYERS, 98 99 /** 100 * Specifies the exact version of QR code to be encoded. 101 * (Type {@link Integer}, or {@link String} representation of the integer value). 102 */ 103 QR_VERSION, 98 104 } -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/ReaderException.java
rd2f7b65 r8a84522 40 40 41 41 // Prevent stack traces from being taken 42 // srowen says: huh, my IDE is saying this is not an override. native methods can't be overridden?43 // This, at least, does not hurt. Because we use a singleton pattern here, it doesn't matter anyhow.44 42 @Override 45 public final Throwable fillInStackTrace() {43 public final synchronized Throwable fillInStackTrace() { 46 44 return null; 47 45 } -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/BitArray.java
rd2f7b65 r8a84522 152 152 */ 153 153 public void setRange(int start, int end) { 154 if (end < start ) {154 if (end < start || start < 0 || end > size) { 155 155 throw new IllegalArgumentException(); 156 156 } … … 164 164 int firstBit = i > firstInt ? 0 : start & 0x1F; 165 165 int lastBit = i < lastInt ? 31 : end & 0x1F; 166 int mask; 167 if (firstBit == 0 && lastBit == 31) { 168 mask = -1; 169 } else { 170 mask = 0; 171 for (int j = firstBit; j <= lastBit; j++) { 172 mask |= 1 << j; 173 } 174 } 166 // Ones from firstBit to lastBit, inclusive 167 int mask = (2 << lastBit) - (1 << firstBit); 175 168 bits[i] |= mask; 176 169 } … … 194 187 * @param value if true, checks that bits in range are set, otherwise checks that they are not set 195 188 * @return true iff all bits are set or not set in range, according to value argument 196 * @throws IllegalArgumentException if end is less than or equal to start189 * @throws IllegalArgumentException if end is less than start or the range is not contained in the array 197 190 */ 198 191 public boolean isRange(int start, int end, boolean value) { 199 if (end < start ) {192 if (end < start || start < 0 || end > size) { 200 193 throw new IllegalArgumentException(); 201 194 } … … 209 202 int firstBit = i > firstInt ? 0 : start & 0x1F; 210 203 int lastBit = i < lastInt ? 31 : end & 0x1F; 211 int mask; 212 if (firstBit == 0 && lastBit == 31) { 213 mask = -1; 214 } else { 215 mask = 0; 216 for (int j = firstBit; j <= lastBit; j++) { 217 mask |= 1 << j; 218 } 219 } 204 // Ones from firstBit to lastBit, inclusive 205 int mask = (2 << lastBit) - (1 << firstBit); 220 206 221 207 // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is, … … 263 249 264 250 public void xor(BitArray other) { 265 if ( bits.length != other.bits.length) {251 if (size != other.size) { 266 252 throw new IllegalArgumentException("Sizes don't match"); 267 253 } 268 254 for (int i = 0; i < bits.length; i++) { 269 // The last byte could be incomplete (i.e. not have 8bits in255 // The last int could be incomplete (i.e. not have 32 bits in 270 256 // it) but there is no problem since 0 XOR 0 == 0. 271 257 bits[i] ^= other.bits[i]; … … 308 294 int[] newBits = new int[bits.length]; 309 295 // reverse all int's first 310 int len = ( (size-1) / 32);296 int len = (size - 1) / 32; 311 297 int oldBitsLen = len + 1; 312 298 for (int i = 0; i < oldBitsLen; i++) { 313 long x = (long)bits[i];299 long x = bits[i]; 314 300 x = ((x >> 1) & 0x55555555L) | ((x & 0x55555555L) << 1); 315 301 x = ((x >> 2) & 0x33333333L) | ((x & 0x33333333L) << 2); … … 322 308 if (size != oldBitsLen * 32) { 323 309 int leftOffset = oldBitsLen * 32 - size; 324 int mask = 1; 325 for (int i = 0; i < 31 - leftOffset; i++) { 326 mask = (mask << 1) | 1; 327 } 328 int currentInt = (newBits[0] >> leftOffset) & mask; 310 int currentInt = newBits[0] >>> leftOffset; 329 311 for (int i = 1; i < oldBitsLen; i++) { 330 312 int nextInt = newBits[i]; 331 313 currentInt |= nextInt << (32 - leftOffset); 332 314 newBits[i - 1] = currentInt; 333 currentInt = (nextInt >> leftOffset) & mask;315 currentInt = nextInt >>> leftOffset; 334 316 } 335 317 newBits[oldBitsLen - 1] = currentInt; -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/BitMatrix.java
rd2f7b65 r8a84522 103 103 // no EOL at end? 104 104 if (bitsPos > rowStartPos) { 105 if (rowLength == -1) {105 if (rowLength == -1) { 106 106 rowLength = bitsPos - rowStartPos; 107 107 } else if (bitsPos - rowStartPos != rowLength) { … … 255 255 BitArray topRow = new BitArray(width); 256 256 BitArray bottomRow = new BitArray(width); 257 for (int i = 0; i < (height +1) / 2; i++) {257 for (int i = 0; i < (height + 1) / 2; i++) { 258 258 topRow = getRow(i, topRow); 259 259 bottomRow = getRow(height - 1 - i, bottomRow); … … 308 308 } 309 309 310 int width = right - left; 311 int height = bottom - top; 312 313 if (width < 0 || height < 0) { 310 if (right < left || bottom < top) { 314 311 return null; 315 312 } 316 313 317 return new int[] {left, top, width, height};314 return new int[] {left, top, right - left + 1, bottom - top + 1}; 318 315 } 319 316 … … 336 333 int theBits = bits[bitsOffset]; 337 334 int bit = 0; 338 while ((theBits << (31 -bit)) == 0) {335 while ((theBits << (31 - bit)) == 0) { 339 336 bit++; 340 337 } … … 420 417 */ 421 418 public String toString(String setString, String unsetString) { 422 return toString(setString, unsetString, "\n");419 return buildToString(setString, unsetString, "\n"); 423 420 } 424 421 … … 432 429 @Deprecated 433 430 public String toString(String setString, String unsetString, String lineSeparator) { 431 return buildToString(setString, unsetString, lineSeparator); 432 } 433 434 private String buildToString(String setString, String unsetString, String lineSeparator) { 434 435 StringBuilder result = new StringBuilder(height * (width + 1)); 435 436 for (int y = 0; y < height; y++) { -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java
rd2f7b65 r8a84522 71 71 if (x >= size) { 72 72 x ^= primitive; 73 x &= size -1;73 x &= size - 1; 74 74 } 75 75 } 76 for (int i = 0; i < size -1; i++) {76 for (int i = 0; i < size - 1; i++) { 77 77 logTable[expTable[i]] = i; 78 78 } -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGFPoly.java
rd2f7b65 r8a84522 100 100 return getCoefficient(0); 101 101 } 102 int size = coefficients.length;103 102 if (a == 1) { 104 103 // Just the sum of the coefficients … … 110 109 } 111 110 int result = coefficients[0]; 111 int size = coefficients.length; 112 112 for (int i = 1; i < size; i++) { 113 113 result = GenericGF.addOrSubtract(field.multiply(a, result), coefficients[i]); -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/decoder/FormatInformation.java
rd2f7b65 r8a84522 67 67 }; 68 68 69 /**70 * Offset i holds the number of 1 bits in the binary representation of i71 */72 private static final int[] BITS_SET_IN_HALF_BYTE =73 {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};74 75 69 private final ErrorCorrectionLevel errorCorrectionLevel; 76 70 private final byte dataMask; … … 84 78 85 79 static int numBitsDiffering(int a, int b) { 86 a ^= b; // a now has a 1 bit exactly where its bit differs with b's 87 // Count bits set quickly with a series of lookups: 88 return BITS_SET_IN_HALF_BYTE[a & 0x0F] + 89 BITS_SET_IN_HALF_BYTE[(a >>> 4 & 0x0F)] + 90 BITS_SET_IN_HALF_BYTE[(a >>> 8 & 0x0F)] + 91 BITS_SET_IN_HALF_BYTE[(a >>> 12 & 0x0F)] + 92 BITS_SET_IN_HALF_BYTE[(a >>> 16 & 0x0F)] + 93 BITS_SET_IN_HALF_BYTE[(a >>> 20 & 0x0F)] + 94 BITS_SET_IN_HALF_BYTE[(a >>> 24 & 0x0F)] + 95 BITS_SET_IN_HALF_BYTE[(a >>> 28 & 0x0F)]; 80 return Integer.bitCount(a ^ b); 96 81 } 97 82 … … 157 142 @Override 158 143 public int hashCode() { 159 return (errorCorrectionLevel.ordinal() << 3) | (int)dataMask;144 return (errorCorrectionLevel.ordinal() << 3) | dataMask; 160 145 } 161 146 -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java
rd2f7b65 r8a84522 154 154 for (int y = 0; y < max; y++) { 155 155 if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { 156 // No alignment patterns near the three finder pat erns156 // No alignment patterns near the three finder patterns 157 157 continue; 158 158 } … … 213 213 214 214 /** 215 * <p>Encapsu altes the parameters for one error-correction block in one symbol version.215 * <p>Encapsulates the parameters for one error-correction block in one symbol version. 216 216 * This includes the number of data codewords, and the number of times a block with these 217 217 * parameters is used consecutively in the QR code version's format.</p> -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/encoder/Encoder.java
rd2f7b65 r8a84522 107 107 appendBytes(content, mode, dataBits, encoding); 108 108 109 // Hard part: need to know version to know how many bits length takes. But need to know how many 110 // bits it takes to know version. First we take a guess at version by assuming version will be 111 // the minimum, 1: 112 113 int provisionalBitsNeeded = headerBits.getSize() 114 + mode.getCharacterCountBits(Version.getVersionForNumber(1)) 115 + dataBits.getSize(); 116 Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel); 117 118 // Use that guess to calculate the right version. I am still not sure this works in 100% of cases. 119 120 int bitsNeeded = headerBits.getSize() 121 + mode.getCharacterCountBits(provisionalVersion) 122 + dataBits.getSize(); 123 Version version = chooseVersion(bitsNeeded, ecLevel); 109 Version version; 110 if (hints != null && hints.containsKey(EncodeHintType.QR_VERSION)) { 111 int versionNumber = Integer.parseInt(hints.get(EncodeHintType.QR_VERSION).toString()); 112 version = Version.getVersionForNumber(versionNumber); 113 int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, version); 114 if (!willFit(bitsNeeded, version, ecLevel)) { 115 throw new WriterException("Data too big for requested version"); 116 } 117 } else { 118 version = recommendVersion(ecLevel, mode, headerBits, dataBits); 119 } 124 120 125 121 BitArray headerAndDataBits = new BitArray(); … … 160 156 161 157 return qrCode; 158 } 159 160 /** 161 * Decides the smallest version of QR code that will contain all of the provided data. 162 * 163 * @throws WriterException if the data cannot fit in any version 164 */ 165 private static Version recommendVersion(ErrorCorrectionLevel ecLevel, 166 Mode mode, 167 BitArray headerBits, 168 BitArray dataBits) throws WriterException { 169 // Hard part: need to know version to know how many bits length takes. But need to know how many 170 // bits it takes to know version. First we take a guess at version by assuming version will be 171 // the minimum, 1: 172 int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1)); 173 Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel); 174 175 // Use that guess to calculate the right version. I am still not sure this works in 100% of cases. 176 int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion); 177 return chooseVersion(bitsNeeded, ecLevel); 178 } 179 180 private static int calculateBitsNeeded(Mode mode, 181 BitArray headerBits, 182 BitArray dataBits, 183 Version version) { 184 return headerBits.getSize() + mode.getCharacterCountBits(version) + dataBits.getSize(); 162 185 } 163 186 … … 247 270 248 271 private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException { 249 // In the following comments, we use numbers of Version 7-H.250 272 for (int versionNum = 1; versionNum <= 40; versionNum++) { 251 273 Version version = Version.getVersionForNumber(versionNum); 274 if (willFit(numInputBits, version, ecLevel)) { 275 return version; 276 } 277 } 278 throw new WriterException("Data too big"); 279 } 280 281 /** 282 * @return true if the number of input bits will fit in a code with the specified version and 283 * error correction level. 284 */ 285 private static boolean willFit(int numInputBits, Version version, ErrorCorrectionLevel ecLevel) { 286 // In the following comments, we use numbers of Version 7-H. 252 287 // numBytes = 196 253 288 int numBytes = version.getTotalCodewords(); … … 258 293 int numDataBytes = numBytes - numEcBytes; 259 294 int totalInputBytes = (numInputBits + 7) / 8; 260 if (numDataBytes >= totalInputBytes) { 261 return version; 262 } 263 } 264 throw new WriterException("Data too big"); 295 return numDataBytes >= totalInputBytes; 265 296 } 266 297 … … 384 415 int size = numDataBytesInBlock[0]; 385 416 byte[] dataBytes = new byte[size]; 386 bits.toBytes(8 *dataBytesOffset, dataBytes, 0, size);417 bits.toBytes(8 * dataBytesOffset, dataBytes, 0, size); 387 418 byte[] ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]); 388 419 blocks.add(new BlockPair(dataBytes, ecBytes)); -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java
rd2f7b65 r8a84522 78 78 if (x + 6 < width && 79 79 arrayY[x] == 1 && 80 arrayY[x + 81 arrayY[x + 82 arrayY[x + 83 arrayY[x + 84 arrayY[x + 85 arrayY[x + 80 arrayY[x + 1] == 0 && 81 arrayY[x + 2] == 1 && 82 arrayY[x + 3] == 1 && 83 arrayY[x + 4] == 1 && 84 arrayY[x + 5] == 0 && 85 arrayY[x + 6] == 1 && 86 86 (isWhiteHorizontal(arrayY, x - 4, x) || isWhiteHorizontal(arrayY, x + 7, x + 11))) { 87 87 numPenalties++; 88 88 } 89 89 if (y + 6 < height && 90 array[y][x] == 1 91 array[y + 1][x] == 0&&92 array[y + 2][x] == 1&&93 array[y + 3][x] == 1&&94 array[y + 4][x] == 1&&95 array[y + 5][x] == 0&&96 array[y + 90 array[y][x] == 1 && 91 array[y + 1][x] == 0 && 92 array[y + 2][x] == 1 && 93 array[y + 3][x] == 1 && 94 array[y + 4][x] == 1 && 95 array[y + 5][x] == 0 && 96 array[y + 6][x] == 1 && 97 97 (isWhiteVertical(array, x, y - 4, y) || isWhiteVertical(array, x, y + 7, y + 11))) { 98 98 numPenalties++; … … 104 104 105 105 private static boolean isWhiteHorizontal(byte[] rowArray, int from, int to) { 106 from = Math.max(from, 0); 107 to = Math.min(to, rowArray.length); 106 108 for (int i = from; i < to; i++) { 107 if ( i >= 0 && i < rowArray.length &&rowArray[i] == 1) {109 if (rowArray[i] == 1) { 108 110 return false; 109 111 } … … 113 115 114 116 private static boolean isWhiteVertical(byte[][] array, int col, int from, int to) { 117 from = Math.max(from, 0); 118 to = Math.min(to, array.length); 115 119 for (int i = from; i < to; i++) { 116 if ( i >= 0 && i < array.length &&array[i][col] == 1) {120 if (array[i][col] == 1) { 117 121 return false; 118 122 } -
apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java
rd2f7b65 r8a84522 272 272 // - findMSBSet(255) => 8 273 273 static int findMSBSet(int value) { 274 int numDigits = 0; 275 while (value != 0) { 276 value >>>= 1; 277 ++numDigits; 278 } 279 return numDigits; 274 return 32 - Integer.numberOfLeadingZeros(value); 280 275 } 281 276
Note: See TracChangeset
for help on using the changeset viewer.