Changeset 8a84522


Ignore:
Timestamp:
Oct 25, 2016 3:04:55 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d2569fa
Parents:
d2f7b65
Message:

Zxing 3.3.0

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • LICENSE.txt

    rd2f7b65 r8a84522  
    208208       Copyright (c) 2008 Alexander von Gernler.  All rights reserved.
    209209       See licenses/LICENSE-BSD.txt
    210      Zxing:
     210     Zxing 3.3.0:
    211211       See licenses/LICENSE-Apache2.0.txt
    212212
  • apps/imagegen/zxing/CHANGES

    rd2f7b65 r8a84522  
    356356
    357357  - Small bug fixes
     358
     3593.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  
    33We've added a build.xml for ant.
    44
    5 Pulled from https://github.com/zxing/zxing on Jan. 4, 2016,
    6 rev 4e3abafe3008e02695f894eccf05f8257fca4ee9 dated Dec. 9, 2015.
     5https://github.com/zxing/zxing/releases Version 3.3.0 Sept. 16, 2016
  • apps/imagegen/zxing/README.md

    rd2f7b65 r8a84522  
    11<img align="right" src="https://raw.github.com/wiki/zxing/zxing/zxing-logo.png"/>
     2
     3##Get Started Developing
     4To get started, please visit: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
    25
    36ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing
     
    5154| [python-zxing](https://github.com/oostendo/python-zxing)        | bindings for Python
    5255| [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
    5357
    5458### Other related third-party open source projects
     
    6266## Links
    6367
    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/)
    6972
    7073## Contacting
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/EncodeHintType.java

    rd2f7b65 r8a84522  
    9696   */
    9797   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,
    98104}
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/ReaderException.java

    rd2f7b65 r8a84522  
    4040
    4141  // 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.
    4442  @Override
    45   public final Throwable fillInStackTrace() {
     43  public final synchronized Throwable fillInStackTrace() {
    4644    return null;
    4745  }
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/BitArray.java

    rd2f7b65 r8a84522  
    152152   */
    153153  public void setRange(int start, int end) {
    154     if (end < start) {
     154    if (end < start || start < 0 || end > size) {
    155155      throw new IllegalArgumentException();
    156156    }
     
    164164      int firstBit = i > firstInt ? 0 : start & 0x1F;
    165165      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);
    175168      bits[i] |= mask;
    176169    }
     
    194187   * @param value if true, checks that bits in range are set, otherwise checks that they are not set
    195188   * @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 start
     189   * @throws IllegalArgumentException if end is less than start or the range is not contained in the array
    197190   */
    198191  public boolean isRange(int start, int end, boolean value) {
    199     if (end < start) {
     192    if (end < start || start < 0 || end > size) {
    200193      throw new IllegalArgumentException();
    201194    }
     
    209202      int firstBit = i > firstInt ? 0 : start & 0x1F;
    210203      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);
    220206
    221207      // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,
     
    263249
    264250  public void xor(BitArray other) {
    265     if (bits.length != other.bits.length) {
     251    if (size != other.size) {
    266252      throw new IllegalArgumentException("Sizes don't match");
    267253    }
    268254    for (int i = 0; i < bits.length; i++) {
    269       // The last byte could be incomplete (i.e. not have 8 bits in
     255      // The last int could be incomplete (i.e. not have 32 bits in
    270256      // it) but there is no problem since 0 XOR 0 == 0.
    271257      bits[i] ^= other.bits[i];
     
    308294    int[] newBits = new int[bits.length];
    309295    // reverse all int's first
    310     int len = ((size-1) / 32);
     296    int len = (size - 1) / 32;
    311297    int oldBitsLen = len + 1;
    312298    for (int i = 0; i < oldBitsLen; i++) {
    313       long x = (long) bits[i];
     299      long x = bits[i];
    314300      x = ((x >>  1) & 0x55555555L) | ((x & 0x55555555L) <<  1);
    315301      x = ((x >>  2) & 0x33333333L) | ((x & 0x33333333L) <<  2);
     
    322308    if (size != oldBitsLen * 32) {
    323309      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;
    329311      for (int i = 1; i < oldBitsLen; i++) {
    330312        int nextInt = newBits[i];
    331313        currentInt |= nextInt << (32 - leftOffset);
    332314        newBits[i - 1] = currentInt;
    333         currentInt = (nextInt >> leftOffset) & mask;
     315        currentInt = nextInt >>> leftOffset;
    334316      }
    335317      newBits[oldBitsLen - 1] = currentInt;
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/BitMatrix.java

    rd2f7b65 r8a84522  
    103103    // no EOL at end?
    104104    if (bitsPos > rowStartPos) {
    105       if(rowLength == -1) {
     105      if (rowLength == -1) {
    106106        rowLength = bitsPos - rowStartPos;
    107107      } else if (bitsPos - rowStartPos != rowLength) {
     
    255255    BitArray topRow = new BitArray(width);
    256256    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++) {
    258258      topRow = getRow(i, topRow);
    259259      bottomRow = getRow(height - 1 - i, bottomRow);
     
    308308    }
    309309
    310     int width = right - left;
    311     int height = bottom - top;
    312 
    313     if (width < 0 || height < 0) {
     310    if (right < left || bottom < top) {
    314311      return null;
    315312    }
    316313
    317     return new int[] {left, top, width, height};
     314    return new int[] {left, top, right - left + 1, bottom - top + 1};
    318315  }
    319316
     
    336333    int theBits = bits[bitsOffset];
    337334    int bit = 0;
    338     while ((theBits << (31-bit)) == 0) {
     335    while ((theBits << (31 - bit)) == 0) {
    339336      bit++;
    340337    }
     
    420417   */
    421418  public String toString(String setString, String unsetString) {
    422     return toString(setString, unsetString, "\n");
     419    return buildToString(setString, unsetString, "\n");
    423420  }
    424421
     
    432429  @Deprecated
    433430  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) {
    434435    StringBuilder result = new StringBuilder(height * (width + 1));
    435436    for (int y = 0; y < height; y++) {
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java

    rd2f7b65 r8a84522  
    7171      if (x >= size) {
    7272        x ^= primitive;
    73         x &= size-1;
     73        x &= size - 1;
    7474      }
    7575    }
    76     for (int i = 0; i < size-1; i++) {
     76    for (int i = 0; i < size - 1; i++) {
    7777      logTable[expTable[i]] = i;
    7878    }
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGFPoly.java

    rd2f7b65 r8a84522  
    100100      return getCoefficient(0);
    101101    }
    102     int size = coefficients.length;
    103102    if (a == 1) {
    104103      // Just the sum of the coefficients
     
    110109    }
    111110    int result = coefficients[0];
     111    int size = coefficients.length;
    112112    for (int i = 1; i < size; i++) {
    113113      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  
    6767  };
    6868
    69   /**
    70    * Offset i holds the number of 1 bits in the binary representation of i
    71    */
    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 
    7569  private final ErrorCorrectionLevel errorCorrectionLevel;
    7670  private final byte dataMask;
     
    8478
    8579  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);
    9681  }
    9782
     
    157142  @Override
    158143  public int hashCode() {
    159     return (errorCorrectionLevel.ordinal() << 3) | (int) dataMask;
     144    return (errorCorrectionLevel.ordinal() << 3) | dataMask;
    160145  }
    161146
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java

    rd2f7b65 r8a84522  
    154154      for (int y = 0; y < max; y++) {
    155155        if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
    156           // No alignment patterns near the three finder paterns
     156          // No alignment patterns near the three finder patterns
    157157          continue;
    158158        }
     
    213213
    214214  /**
    215    * <p>Encapsualtes 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.
    216216   * This includes the number of data codewords, and the number of times a block with these
    217217   * 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  
    107107    appendBytes(content, mode, dataBits, encoding);
    108108
    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    }
    124120
    125121    BitArray headerAndDataBits = new BitArray();
     
    160156
    161157    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();
    162185  }
    163186
     
    247270
    248271  private static Version chooseVersion(int numInputBits, ErrorCorrectionLevel ecLevel) throws WriterException {
    249     // In the following comments, we use numbers of Version 7-H.
    250272    for (int versionNum = 1; versionNum <= 40; versionNum++) {
    251273      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.
    252287      // numBytes = 196
    253288      int numBytes = version.getTotalCodewords();
     
    258293      int numDataBytes = numBytes - numEcBytes;
    259294      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;
    265296  }
    266297
     
    384415      int size = numDataBytesInBlock[0];
    385416      byte[] dataBytes = new byte[size];
    386       bits.toBytes(8*dataBytesOffset, dataBytes, 0, size);
     417      bits.toBytes(8 * dataBytesOffset, dataBytes, 0, size);
    387418      byte[] ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
    388419      blocks.add(new BlockPair(dataBytes, ecBytes));
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java

    rd2f7b65 r8a84522  
    7878        if (x + 6 < width &&
    7979            arrayY[x] == 1 &&
    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 &&
     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 &&
    8686            (isWhiteHorizontal(arrayY, x - 4, x) || isWhiteHorizontal(arrayY, x + 7, x + 11))) {
    8787          numPenalties++;
    8888        }
    8989        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 +  6][x] == 1 &&
     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 &&
    9797            (isWhiteVertical(array, x, y - 4, y) || isWhiteVertical(array, x, y + 7, y + 11))) {
    9898          numPenalties++;
     
    104104
    105105  private static boolean isWhiteHorizontal(byte[] rowArray, int from, int to) {
     106    from = Math.max(from, 0);
     107    to = Math.min(to, rowArray.length);
    106108    for (int i = from; i < to; i++) {
    107       if (i >= 0 && i < rowArray.length && rowArray[i] == 1) {
     109      if (rowArray[i] == 1) {
    108110        return false;
    109111      }
     
    113115
    114116  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);
    115119    for (int i = from; i < to; i++) {
    116       if (i >= 0 && i < array.length && array[i][col] == 1) {
     120      if (array[i][col] == 1) {
    117121        return false;
    118122      }
  • apps/imagegen/zxing/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java

    rd2f7b65 r8a84522  
    272272  // - findMSBSet(255) => 8
    273273  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);
    280275  }
    281276
Note: See TracChangeset for help on using the changeset viewer.