From 8af98a573fc6c5db3dd1f2f790824b918c1b7239 Mon Sep 17 00:00:00 2001 From: Sean Owen Date: Fri, 25 Apr 2014 13:30:58 +0100 Subject: [PATCH] Replace bit shifts that are really multiplication and division with simple operators now --- .../com/google/zxing/RGBLuminanceSource.java | 2 +- .../google/zxing/aztec/decoder/Decoder.java | 2 +- .../com/google/zxing/common/BitMatrix.java | 16 +++++++-------- .../zxing/common/DefaultGridSampler.java | 6 +++--- .../common/GlobalHistogramBinarizer.java | 6 +++--- .../google/zxing/common/HybridBinarizer.java | 6 +++--- .../detector/MonochromeRectangleDetector.java | 20 +++++++++---------- .../zxing/common/reedsolomon/GenericGF.java | 2 +- .../zxing/datamatrix/DataMatrixReader.java | 2 +- .../zxing/datamatrix/detector/Detector.java | 2 +- .../datamatrix/encoder/ErrorCorrection.java | 2 +- .../com/google/zxing/oned/Code39Reader.java | 6 +++--- .../java/com/google/zxing/oned/ITFReader.java | 4 ++-- .../java/com/google/zxing/oned/ITFWriter.java | 4 ++-- .../com/google/zxing/oned/OneDReader.java | 2 +- .../google/zxing/oned/rss/RSS14Reader.java | 2 +- .../com/google/zxing/oned/rss/RSSUtils.java | 2 +- .../oned/rss/expanded/BitArrayBuilder.java | 2 +- .../oned/rss/expanded/RSSExpandedReader.java | 2 +- .../com/google/zxing/pdf417/PDF417Common.java | 2 +- .../decoder/DecodedBitStreamParser.java | 4 ++-- .../pdf417/decoder/PDF417ScanningDecoder.java | 2 +- .../com/google/zxing/qrcode/QRCodeWriter.java | 4 ++-- .../zxing/qrcode/decoder/BitMatrixParser.java | 2 +- .../google/zxing/qrcode/decoder/DataMask.java | 2 +- .../decoder/DecodedBitStreamParser.java | 2 +- .../google/zxing/qrcode/decoder/Version.java | 2 +- .../detector/AlignmentPatternFinder.java | 4 ++-- .../zxing/qrcode/detector/Detector.java | 4 ++-- .../google/zxing/qrcode/encoder/Encoder.java | 2 +- .../google/zxing/qrcode/encoder/MaskUtil.java | 2 +- .../qrcode/encoder/BitVectorTestCase.java | 2 +- 32 files changed, 62 insertions(+), 62 deletions(-) diff --git a/core/src/main/java/com/google/zxing/RGBLuminanceSource.java b/core/src/main/java/com/google/zxing/RGBLuminanceSource.java index 3f4870744..7c70b35ca 100644 --- a/core/src/main/java/com/google/zxing/RGBLuminanceSource.java +++ b/core/src/main/java/com/google/zxing/RGBLuminanceSource.java @@ -54,7 +54,7 @@ public final class RGBLuminanceSource extends LuminanceSource { luminances[offset + x] = (byte) r; } else { // Calculate luminance cheaply, favoring green. - luminances[offset + x] = (byte) ((r + g + g + b) >> 2); + luminances[offset + x] = (byte) ((r + 2 * g + b) / 4); } } } diff --git a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java index eae9af913..e4a3611e9 100644 --- a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java +++ b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java @@ -323,7 +323,7 @@ public final class Decoder { for (int i = startIndex; i < startIndex + length; i++) { res <<= 1; if (rawbits[i]) { - res++; + res |= 0x01; } } return res; diff --git a/core/src/main/java/com/google/zxing/common/BitMatrix.java b/core/src/main/java/com/google/zxing/common/BitMatrix.java index d4f0d9b7b..04e30a241 100755 --- a/core/src/main/java/com/google/zxing/common/BitMatrix.java +++ b/core/src/main/java/com/google/zxing/common/BitMatrix.java @@ -51,7 +51,7 @@ public final class BitMatrix implements Cloneable { } this.width = width; this.height = height; - this.rowSize = (width + 31) >> 5; + this.rowSize = (width + 31) / 32; bits = new int[rowSize * height]; } @@ -70,7 +70,7 @@ public final class BitMatrix implements Cloneable { * @return value of given bit in matrix */ public boolean get(int x, int y) { - int offset = y * rowSize + (x >> 5); + int offset = y * rowSize + (x / 32); return ((bits[offset] >>> (x & 0x1f)) & 1) != 0; } @@ -81,7 +81,7 @@ public final class BitMatrix implements Cloneable { * @param y The vertical component (i.e. which row) */ public void set(int x, int y) { - int offset = y * rowSize + (x >> 5); + int offset = y * rowSize + (x / 32); bits[offset] |= 1 << (x & 0x1f); } @@ -92,7 +92,7 @@ public final class BitMatrix implements Cloneable { * @param y The vertical component (i.e. which row) */ public void flip(int x, int y) { - int offset = y * rowSize + (x >> 5); + int offset = y * rowSize + (x / 32); bits[offset] ^= 1 << (x & 0x1f); } @@ -129,7 +129,7 @@ public final class BitMatrix implements Cloneable { for (int y = top; y < bottom; y++) { int offset = y * rowSize; for (int x = left; x < right; x++) { - bits[offset + (x >> 5)] |= 1 << (x & 0x1f); + bits[offset + (x / 32)] |= 1 << (x & 0x1f); } } } @@ -150,7 +150,7 @@ public final class BitMatrix implements Cloneable { } int offset = y * rowSize; for (int x = 0; x < rowSize; x++) { - row.setBulk(x << 5, bits[offset + x]); + row.setBulk(x * 32, bits[offset + x]); } return row; } @@ -248,7 +248,7 @@ public final class BitMatrix implements Cloneable { return null; } int y = bitsOffset / rowSize; - int x = (bitsOffset % rowSize) << 5; + int x = (bitsOffset % rowSize) * 32; int theBits = bits[bitsOffset]; int bit = 0; @@ -269,7 +269,7 @@ public final class BitMatrix implements Cloneable { } int y = bitsOffset / rowSize; - int x = (bitsOffset % rowSize) << 5; + int x = (bitsOffset % rowSize) * 32; int theBits = bits[bitsOffset]; int bit = 31; diff --git a/core/src/main/java/com/google/zxing/common/DefaultGridSampler.java b/core/src/main/java/com/google/zxing/common/DefaultGridSampler.java index 4ab43fd68..0ef0fbee1 100644 --- a/core/src/main/java/com/google/zxing/common/DefaultGridSampler.java +++ b/core/src/main/java/com/google/zxing/common/DefaultGridSampler.java @@ -52,12 +52,12 @@ public final class DefaultGridSampler extends GridSampler { throw NotFoundException.getNotFoundInstance(); } BitMatrix bits = new BitMatrix(dimensionX, dimensionY); - float[] points = new float[dimensionX << 1]; + float[] points = new float[2 * dimensionX]; for (int y = 0; y < dimensionY; y++) { int max = points.length; float iValue = (float) y + 0.5f; for (int x = 0; x < max; x += 2) { - points[x] = (float) (x >> 1) + 0.5f; + points[x] = (float) (x / 2) + 0.5f; points[x + 1] = iValue; } transform.transformPoints(points); @@ -68,7 +68,7 @@ public final class DefaultGridSampler extends GridSampler { for (int x = 0; x < max; x += 2) { if (image.get((int) points[x], (int) points[x + 1])) { // Black(-ish) pixel - bits.set(x >> 1, y); + bits.set(x / 2, y); } } } catch (ArrayIndexOutOfBoundsException aioobe) { diff --git a/core/src/main/java/com/google/zxing/common/GlobalHistogramBinarizer.java b/core/src/main/java/com/google/zxing/common/GlobalHistogramBinarizer.java index f9676468b..b4c0edbd8 100644 --- a/core/src/main/java/com/google/zxing/common/GlobalHistogramBinarizer.java +++ b/core/src/main/java/com/google/zxing/common/GlobalHistogramBinarizer.java @@ -72,7 +72,7 @@ public class GlobalHistogramBinarizer extends Binarizer { for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. - int luminance = ((center << 2) - left - right) >> 1; + int luminance = ((center * 4) - left - right) / 2; if (luminance < blackPoint) { row.set(x); } @@ -97,7 +97,7 @@ public class GlobalHistogramBinarizer extends Binarizer { for (int y = 1; y < 5; y++) { int row = height * y / 5; byte[] localLuminances = source.getRow(row, luminances); - int right = (width << 2) / 5; + int right = (width * 4) / 5; for (int x = width / 5; x < right; x++) { int pixel = localLuminances[x] & 0xff; localBuckets[pixel >> LUMINANCE_SHIFT]++; @@ -174,7 +174,7 @@ public class GlobalHistogramBinarizer extends Binarizer { // If there is too little contrast in the image to pick a meaningful black point, throw rather // than waste time trying to decode the image, and risk false positives. - if (secondPeak - firstPeak <= numBuckets >> 4) { + if (secondPeak - firstPeak <= numBuckets / 16) { throw NotFoundException.getNotFoundInstance(); } diff --git a/core/src/main/java/com/google/zxing/common/HybridBinarizer.java b/core/src/main/java/com/google/zxing/common/HybridBinarizer.java index ba56db7d0..de2934da4 100644 --- a/core/src/main/java/com/google/zxing/common/HybridBinarizer.java +++ b/core/src/main/java/com/google/zxing/common/HybridBinarizer.java @@ -211,7 +211,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer { // // The default assumption is that the block is light/background. Since no estimate for // the level of dark pixels exists locally, use half the min for the block. - average = min >> 1; + average = min / 2; if (y > 0 && x > 0) { // Correct the "white background" assumption for blocks that have neighbors by comparing @@ -221,8 +221,8 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer { // the boundaries is used for the interior. // The (min < bp) is arbitrary but works better than other heuristics that were tried. - int averageNeighborBlackPoint = (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + - blackPoints[y - 1][x - 1]) >> 2; + int averageNeighborBlackPoint = + (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + blackPoints[y - 1][x - 1]) / 4; if (min < averageNeighborBlackPoint) { average = averageNeighborBlackPoint; } diff --git a/core/src/main/java/com/google/zxing/common/detector/MonochromeRectangleDetector.java b/core/src/main/java/com/google/zxing/common/detector/MonochromeRectangleDetector.java index 5746b88df..1ce8452ee 100644 --- a/core/src/main/java/com/google/zxing/common/detector/MonochromeRectangleDetector.java +++ b/core/src/main/java/com/google/zxing/common/detector/MonochromeRectangleDetector.java @@ -50,31 +50,31 @@ public final class MonochromeRectangleDetector { public ResultPoint[] detect() throws NotFoundException { int height = image.getHeight(); int width = image.getWidth(); - int halfHeight = height >> 1; - int halfWidth = width >> 1; - int deltaY = Math.max(1, height / (MAX_MODULES << 3)); - int deltaX = Math.max(1, width / (MAX_MODULES << 3)); + int halfHeight = height / 2; + int halfWidth = width / 2; + int deltaY = Math.max(1, height / (MAX_MODULES * 8)); + int deltaX = Math.max(1, width / (MAX_MODULES * 8)); int top = 0; int bottom = height; int left = 0; int right = width; ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, -deltaY, top, bottom, halfWidth >> 1); + halfHeight, -deltaY, top, bottom, halfWidth / 2); top = (int) pointA.getY() - 1; ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right, - halfHeight, 0, top, bottom, halfHeight >> 1); + halfHeight, 0, top, bottom, halfHeight / 2); left = (int) pointB.getX() - 1; ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right, - halfHeight, 0, top, bottom, halfHeight >> 1); + halfHeight, 0, top, bottom, halfHeight / 2); right = (int) pointC.getX() + 1; ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, deltaY, top, bottom, halfWidth >> 1); + halfHeight, deltaY, top, bottom, halfWidth / 2); bottom = (int) pointD.getY() + 1; // Go try to find point A again with better information -- might have been off at first. pointA = findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, -deltaY, top, bottom, halfWidth >> 2); + halfHeight, -deltaY, top, bottom, halfWidth / 4); return new ResultPoint[] { pointA, pointB, pointC, pointD }; } @@ -167,7 +167,7 @@ public final class MonochromeRectangleDetector { */ private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, boolean horizontal) { - int center = (minDim + maxDim) >> 1; + int center = (minDim + maxDim) / 2; // Scan left/up first int start = center; diff --git a/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java b/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java index a3130cd84..9ede5d80a 100644 --- a/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java +++ b/core/src/main/java/com/google/zxing/common/reedsolomon/GenericGF.java @@ -67,7 +67,7 @@ public final class GenericGF { int x = 1; for (int i = 0; i < size; i++) { expTable[i] = x; - x <<= 1; // x = x * 2; we're assuming the generator alpha is 2 + x *= 2; // we're assuming the generator alpha is 2 if (x >= size) { x ^= primitive; x &= size-1; diff --git a/core/src/main/java/com/google/zxing/datamatrix/DataMatrixReader.java b/core/src/main/java/com/google/zxing/datamatrix/DataMatrixReader.java index f66be4af3..e02d766a1 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/DataMatrixReader.java +++ b/core/src/main/java/com/google/zxing/datamatrix/DataMatrixReader.java @@ -123,7 +123,7 @@ public final class DataMatrixReader implements Reader { // Push in the "border" by half the module width so that we start // sampling in the middle of the module. Just in case the image is a // little off, this will help recover. - int nudge = moduleSize >> 1; + int nudge = moduleSize / 2; top += nudge; left += nudge; diff --git a/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java b/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java index 4e4ccf1e4..4e3de8168 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java @@ -370,7 +370,7 @@ public final class Detector { int dx = Math.abs(toX - fromX); int dy = Math.abs(toY - fromY); - int error = -dx >> 1; + int error = -dx / 2; int ystep = fromY < toY ? 1 : -1; int xstep = fromX < toX ? 1 : -1; int transitions = 0; diff --git a/core/src/main/java/com/google/zxing/datamatrix/encoder/ErrorCorrection.java b/core/src/main/java/com/google/zxing/datamatrix/encoder/ErrorCorrection.java index 8d6d5ff40..d38933498 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/encoder/ErrorCorrection.java +++ b/core/src/main/java/com/google/zxing/datamatrix/encoder/ErrorCorrection.java @@ -81,7 +81,7 @@ public final class ErrorCorrection { for (int i = 0; i < 255; i++) { ALOG[i] = p; LOG[p] = i; - p <<= 1; + p *= 2; if (p >= 256) { p ^= MODULO_VALUE; } diff --git a/core/src/main/java/com/google/zxing/oned/Code39Reader.java b/core/src/main/java/com/google/zxing/oned/Code39Reader.java index 685354de7..76eee5717 100644 --- a/core/src/main/java/com/google/zxing/oned/Code39Reader.java +++ b/core/src/main/java/com/google/zxing/oned/Code39Reader.java @@ -136,7 +136,7 @@ public final class Code39Reader extends OneDReader { int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize; // If 50% of last pattern size, following last pattern, is not whitespace, fail // (but if it's whitespace to the very end of the image, that's OK) - if (nextStart != end && (whiteSpaceAfterEnd << 1) < lastPatternSize) { + if (nextStart != end && (whiteSpaceAfterEnd * 2) < lastPatternSize) { throw NotFoundException.getNotFoundInstance(); } @@ -192,7 +192,7 @@ public final class Code39Reader extends OneDReader { if (counterPosition == patternLength - 1) { // Look for whitespace before start pattern, >= 50% of width of start pattern if (toNarrowWidePattern(counters) == ASTERISK_ENCODING && - row.isRange(Math.max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { + row.isRange(Math.max(0, patternStart - ((i - patternStart) / 2)), patternStart, false)) { return new int[]{patternStart, i}; } patternStart += counters[0] + counters[1]; @@ -244,7 +244,7 @@ public final class Code39Reader extends OneDReader { if (counter > maxNarrowCounter) { wideCounters--; // totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average - if ((counter << 1) >= totalWideCountersWidth) { + if ((counter * 2) >= totalWideCountersWidth) { return -1; } } diff --git a/core/src/main/java/com/google/zxing/oned/ITFReader.java b/core/src/main/java/com/google/zxing/oned/ITFReader.java index b250b3278..e57d5a1e1 100644 --- a/core/src/main/java/com/google/zxing/oned/ITFReader.java +++ b/core/src/main/java/com/google/zxing/oned/ITFReader.java @@ -157,7 +157,7 @@ public final class ITFReader extends OneDReader { recordPattern(row, payloadStart, counterDigitPair); // Split them into each array for (int k = 0; k < 5; k++) { - int twoK = k << 1; + int twoK = 2 * k; counterBlack[k] = counterDigitPair[twoK]; counterWhite[k] = counterDigitPair[twoK + 1]; } @@ -188,7 +188,7 @@ public final class ITFReader extends OneDReader { // Determine the width of a narrow line in pixels. We can do this by // getting the width of the start pattern and dividing by 4 because its // made up of 4 narrow lines. - this.narrowLineWidth = (startPattern[1] - startPattern[0]) >> 2; + this.narrowLineWidth = (startPattern[1] - startPattern[0]) / 4; validateQuietZone(row, startPattern[0]); diff --git a/core/src/main/java/com/google/zxing/oned/ITFWriter.java b/core/src/main/java/com/google/zxing/oned/ITFWriter.java index 03c0287e4..3ce020775 100644 --- a/core/src/main/java/com/google/zxing/oned/ITFWriter.java +++ b/core/src/main/java/com/google/zxing/oned/ITFWriter.java @@ -63,8 +63,8 @@ public final class ITFWriter extends OneDimensionalCodeWriter { int two = Character.digit(contents.charAt(i+1), 10); int[] encoding = new int[18]; for (int j = 0; j < 5; j++) { - encoding[j << 1] = ITFReader.PATTERNS[one][j]; - encoding[(j << 1) + 1] = ITFReader.PATTERNS[two][j]; + encoding[2 * j] = ITFReader.PATTERNS[one][j]; + encoding[2 * j + 1] = ITFReader.PATTERNS[two][j]; } pos += appendPattern(result, pos, encoding, true); } diff --git a/core/src/main/java/com/google/zxing/oned/OneDReader.java b/core/src/main/java/com/google/zxing/oned/OneDReader.java index 29d93f0c0..1c7a95fd1 100644 --- a/core/src/main/java/com/google/zxing/oned/OneDReader.java +++ b/core/src/main/java/com/google/zxing/oned/OneDReader.java @@ -119,7 +119,7 @@ public abstract class OneDReader implements Reader { for (int x = 0; x < maxLines; x++) { // Scanning from the middle out. Determine which row we're looking at next: - int rowStepsAboveOrBelow = (x + 1) >> 1; + int rowStepsAboveOrBelow = (x + 1) / 2; boolean isAbove = (x & 0x01) == 0; // i.e. is x even? int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); if (rowNumber < 0 || rowNumber >= height) { diff --git a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java index cb62673bc..604a2aa7a 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java @@ -228,7 +228,7 @@ public final class RSS14Reader extends AbstractRSSReader { } else if (count > 8) { count = 8; } - int offset = i >> 1; + int offset = i / 2; if ((i & 0x01) == 0) { oddCounts[offset] = count; oddRoundingErrors[offset] = value - count; diff --git a/core/src/main/java/com/google/zxing/oned/rss/RSSUtils.java b/core/src/main/java/com/google/zxing/oned/rss/RSSUtils.java index f1fd1798c..fb5a1d020 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/RSSUtils.java +++ b/core/src/main/java/com/google/zxing/oned/rss/RSSUtils.java @@ -129,7 +129,7 @@ public final class RSSUtils { /* static int[] elements(int[] eDist, int N, int K) { int[] widths = new int[eDist.length + 2]; - int twoK = K << 1; + int twoK = 2 * K; widths[0] = 1; int i; int minEven = 10; diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java index 5fe109c18..0fa4edeec 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/BitArrayBuilder.java @@ -40,7 +40,7 @@ final class BitArrayBuilder { } static BitArray buildBitArray(List pairs) { - int charNumber = (pairs.size() << 1) - 1; + int charNumber = (pairs.size() * 2) - 1; if (pairs.get(pairs.size() - 1).getRightChar() == null) { charNumber -= 1; } diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java index 0d283a8d3..3f89e4b79 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java @@ -639,7 +639,7 @@ public final class RSSExpandedReader extends AbstractRSSReader { } count = 8; } - int offset = i >> 1; + int offset = i / 2; if ((i & 0x01) == 0) { oddCounts[offset] = count; oddRoundingErrors[offset] = value - count; diff --git a/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java b/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java index a784ef859..b402d4607 100644 --- a/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java +++ b/core/src/main/java/com/google/zxing/pdf417/PDF417Common.java @@ -83,7 +83,7 @@ public final class PDF417Common { int first = 0; int upto = SYMBOL_TABLE.length; while (first < upto) { - int mid = (first + upto) >>> 1; // Compute mid point. + int mid = (first + upto) / 2; // Compute mid point. if (symbol < SYMBOL_TABLE[mid]) { upto = mid; // continue search in bottom half. } else if (symbol > SYMBOL_TABLE[mid]) { diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java b/core/src/main/java/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java index ab97a5597..003040c9d 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/DecodedBitStreamParser.java @@ -197,9 +197,9 @@ final class DecodedBitStreamParser { */ private static int textCompaction(int[] codewords, int codeIndex, StringBuilder result) { // 2 character per codeword - int[] textCompactionData = new int[(codewords[0] - codeIndex) << 1]; + int[] textCompactionData = new int[(codewords[0] - codeIndex) * 2]; // Used to hold the byte compaction value if there is a mode shift - int[] byteCompactionData = new int[(codewords[0] - codeIndex) << 1]; + int[] byteCompactionData = new int[(codewords[0] - codeIndex) * 2]; int index = 0; boolean end = false; diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java index 106573694..f8388e19b 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java @@ -416,7 +416,7 @@ public final class PDF417ScanningDecoder { if (leftToRight) { endColumn = startColumn + codewordBitCount; } else { - for (int i = 0; i < moduleBitCount.length >> 1; i++) { + for (int i = 0; i < moduleBitCount.length / 2; i++) { int tmpCount = moduleBitCount[i]; moduleBitCount[i] = moduleBitCount[moduleBitCount.length - 1 - i]; moduleBitCount[moduleBitCount.length - 1 - i] = tmpCount; diff --git a/core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java b/core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java index a4fabf406..f5dcf089e 100644 --- a/core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java +++ b/core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java @@ -90,8 +90,8 @@ public final class QRCodeWriter implements Writer { } int inputWidth = input.getWidth(); int inputHeight = input.getHeight(); - int qrWidth = inputWidth + (quietZone << 1); - int qrHeight = inputHeight + (quietZone << 1); + int qrWidth = inputWidth + (quietZone * 2); + int qrHeight = inputHeight + (quietZone * 2); int outputWidth = Math.max(width, qrWidth); int outputHeight = Math.max(height, qrHeight); diff --git a/core/src/main/java/com/google/zxing/qrcode/decoder/BitMatrixParser.java b/core/src/main/java/com/google/zxing/qrcode/decoder/BitMatrixParser.java index 7d3d949bd..10cb475a9 100644 --- a/core/src/main/java/com/google/zxing/qrcode/decoder/BitMatrixParser.java +++ b/core/src/main/java/com/google/zxing/qrcode/decoder/BitMatrixParser.java @@ -101,7 +101,7 @@ final class BitMatrixParser { int dimension = bitMatrix.getHeight(); - int provisionalVersion = (dimension - 17) >> 2; + int provisionalVersion = (dimension - 17) / 4; if (provisionalVersion <= 6) { return Version.getVersionForNumber(provisionalVersion); } diff --git a/core/src/main/java/com/google/zxing/qrcode/decoder/DataMask.java b/core/src/main/java/com/google/zxing/qrcode/decoder/DataMask.java index 353c1a826..c1dbbb798 100755 --- a/core/src/main/java/com/google/zxing/qrcode/decoder/DataMask.java +++ b/core/src/main/java/com/google/zxing/qrcode/decoder/DataMask.java @@ -125,7 +125,7 @@ abstract class DataMask { private static final class DataMask100 extends DataMask { @Override boolean isMasked(int i, int j) { - return (((i >>> 1) + (j /3)) & 0x01) == 0; + return (((i / 2) + (j /3)) & 0x01) == 0; } } diff --git a/core/src/main/java/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java b/core/src/main/java/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java index 09e8a5745..319495802 100644 --- a/core/src/main/java/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java +++ b/core/src/main/java/com/google/zxing/qrcode/decoder/DecodedBitStreamParser.java @@ -217,7 +217,7 @@ final class DecodedBitStreamParser { Collection byteSegments, Map hints) throws FormatException { // Don't crash trying to read more bits than we have available. - if (count << 3 > bits.available()) { + if (8 * count > bits.available()) { throw FormatException.getFormatInstance(); } diff --git a/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java b/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java index b649e207e..cc4052508 100755 --- a/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java +++ b/core/src/main/java/com/google/zxing/qrcode/decoder/Version.java @@ -94,7 +94,7 @@ public final class Version { throw FormatException.getFormatInstance(); } try { - return getVersionForNumber((dimension - 17) >> 2); + return getVersionForNumber((dimension - 17) / 4); } catch (IllegalArgumentException ignored) { throw FormatException.getFormatInstance(); } diff --git a/core/src/main/java/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java b/core/src/main/java/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java index 95fbc2ecb..b6e1b5dbe 100644 --- a/core/src/main/java/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java +++ b/core/src/main/java/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java @@ -88,13 +88,13 @@ final class AlignmentPatternFinder { int startX = this.startX; int height = this.height; int maxJ = startX + width; - int middleI = startY + (height >> 1); + int middleI = startY + (height / 2); // We are looking for black/white/black modules in 1:1:1 ratio; // this tracks the number of black/white/black modules seen so far int[] stateCount = new int[3]; for (int iGen = 0; iGen < height; iGen++) { // Search from middle outwards - int i = middleI + ((iGen & 0x01) == 0 ? (iGen + 1) >> 1 : -((iGen + 1) >> 1)); + int i = middleI + ((iGen & 0x01) == 0 ? (iGen + 1) / 2 : -((iGen + 1) / 2)); stateCount[0] = 0; stateCount[1] = 0; stateCount[2] = 0; diff --git a/core/src/main/java/com/google/zxing/qrcode/detector/Detector.java b/core/src/main/java/com/google/zxing/qrcode/detector/Detector.java index beae1a6a0..d802a1359 100644 --- a/core/src/main/java/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/main/java/com/google/zxing/qrcode/detector/Detector.java @@ -201,7 +201,7 @@ public class Detector { float moduleSize) throws NotFoundException { int tltrCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleSize); int tlblCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize); - int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7; + int dimension = ((tltrCentersDimension + tlblCentersDimension) / 2) + 7; switch (dimension & 0x03) { // mod 4 case 0: dimension++; @@ -318,7 +318,7 @@ public class Detector { int dx = Math.abs(toX - fromX); int dy = Math.abs(toY - fromY); - int error = -dx >> 1; + int error = -dx / 2; int xstep = fromX < toX ? 1 : -1; int ystep = fromY < toY ? 1 : -1; diff --git a/core/src/main/java/com/google/zxing/qrcode/encoder/Encoder.java b/core/src/main/java/com/google/zxing/qrcode/encoder/Encoder.java index 425ca8ed0..ae2fc5456 100644 --- a/core/src/main/java/com/google/zxing/qrcode/encoder/Encoder.java +++ b/core/src/main/java/com/google/zxing/qrcode/encoder/Encoder.java @@ -268,7 +268,7 @@ public final class Encoder { * Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24). */ static void terminateBits(int numDataBytes, BitArray bits) throws WriterException { - int capacity = numDataBytes << 3; + int capacity = numDataBytes * 8; if (bits.getSize() > capacity) { throw new WriterException("data bits cannot fit in the QR Code" + bits.getSize() + " > " + capacity); diff --git a/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java b/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java index 6b0062bca..b2204d4a9 100644 --- a/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java +++ b/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java @@ -163,7 +163,7 @@ final class MaskUtil { intermediate = (y + x) % 3; break; case 4: - intermediate = ((y >>> 1) + (x / 3)) & 0x1; + intermediate = ((y / 2) + (x / 3)) & 0x1; break; case 5: temp = y * x; diff --git a/core/src/test/java/com/google/zxing/qrcode/encoder/BitVectorTestCase.java b/core/src/test/java/com/google/zxing/qrcode/encoder/BitVectorTestCase.java index a7689eb05..0fed100a3 100644 --- a/core/src/test/java/com/google/zxing/qrcode/encoder/BitVectorTestCase.java +++ b/core/src/test/java/com/google/zxing/qrcode/encoder/BitVectorTestCase.java @@ -28,7 +28,7 @@ public final class BitVectorTestCase extends Assert { private static long getUnsignedInt(BitArray v, int index) { long result = 0L; - for (int i = 0, offset = index << 3; i < 32; i++) { + for (int i = 0, offset = index * 8; i < 32; i++) { if (v.get(offset + i)) { result |= 1L << (31 - i); }