X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fcommon%2FBitArray.java;h=de44db3cd9d3c0fc153e44f11a76d09faf1ff0ed;hp=d4e2f190383491f5d2d09d64baaee3703d62384e;hb=d5908d116d05b4cfd17ebda8055437d3e4de15ee;hpb=19cae0857df758d0f69713f987174214f23b6d2f diff --git a/core/src/com/google/zxing/common/BitArray.java b/core/src/com/google/zxing/common/BitArray.java index d4e2f190..de44db3c 100644 --- a/core/src/com/google/zxing/common/BitArray.java +++ b/core/src/com/google/zxing/common/BitArray.java @@ -23,14 +23,12 @@ package com.google.zxing.common; */ public final class BitArray { - private final int[] bits; + private int[] bits; + private int size; public BitArray(int size) { - int arraySize = size >> 5; - if ((size & 0x1F) != 0) { - arraySize++; - } - bits = new int[arraySize]; + this.size = size; + this.bits = makeArray(size); } /** @@ -55,7 +53,7 @@ public final class BitArray { * * @param i first bit to set * @param newBits the new value of the next 32 bits. Note again that the least-significant bit - * correponds to bit i, the next-least-significant to i+1, and so on. + * corresponds to bit i, the next-least-significant to i+1, and so on. */ public void setBulk(int i, int newBits) { bits[i >> 5] = newBits; @@ -78,5 +76,31 @@ public final class BitArray { public int[] getBitArray() { return bits; } + + /** + * Reverses all bits in the array. + */ + public void reverse() { + int[] newBits = makeArray(size); + int max = newBits.length; + for (int i = 0; i < max; i++) { + newBits[i] = 0; + } + for (int i = 0; i < size; i++) { + if (this.get(size - i - 1)) { + newBits[i >> 5] |= 1 << (i & 0x1F); + } + } + bits = newBits; + } + + private int[] makeArray(int size) { + int arraySize = size >> 5; + if ((size & 0x1F) != 0) { + arraySize++; + } + int[] result = new int[arraySize]; + return result; + } } \ No newline at end of file