Search in sources :

Example 21 with BitArray

use of com.google.zxing.common.BitArray in project zxing by zxing.

the class EncoderTest method testStuffBits.

private static void testStuffBits(int wordSize, String bits, String expected) {
    BitArray in = toBitArray(bits);
    BitArray stuffed = Encoder.stuffBits(in, wordSize);
    assertEquals("stuffBits() failed for input string: " + bits, stripSpace(expected), stripSpace(stuffed.toString()));
}
Also used : BitArray(com.google.zxing.common.BitArray)

Example 22 with BitArray

use of com.google.zxing.common.BitArray in project zxing by zxing.

the class EncoderTest method testHighLevelEncodeString.

private static void testHighLevelEncodeString(String s, String expectedBits) {
    BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
    String receivedBits = stripSpace(bits.toString());
    assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits);
    assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
}
Also used : BitArray(com.google.zxing.common.BitArray)

Example 23 with BitArray

use of com.google.zxing.common.BitArray in project zxing by zxing.

the class BinaryUtil method buildBitArrayFromString.

/*
  * Constructs a BitArray from a String like the one returned from BitArray.toString()
  */
public static BitArray buildBitArrayFromString(CharSequence data) {
    CharSequence dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
    BitArray binary = new BitArray(SPACE.matcher(dotsAndXs).replaceAll("").length());
    int counter = 0;
    for (int i = 0; i < dotsAndXs.length(); ++i) {
        if (i % 9 == 0) {
            // spaces
            if (dotsAndXs.charAt(i) != ' ') {
                throw new IllegalStateException("space expected");
            }
            continue;
        }
        char currentChar = dotsAndXs.charAt(i);
        if (currentChar == 'X' || currentChar == 'x') {
            binary.set(counter);
        }
        counter++;
    }
    return binary;
}
Also used : BitArray(com.google.zxing.common.BitArray)

Example 24 with BitArray

use of com.google.zxing.common.BitArray in project zxing by zxing.

the class BinaryUtilTest method checkWithoutSpaces.

private static void checkWithoutSpaces(CharSequence data) {
    CharSequence dataWithoutSpaces = SPACE.matcher(data).replaceAll("");
    BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
    assertEquals(data, binary.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray)

Example 25 with BitArray

use of com.google.zxing.common.BitArray in project zxing by zxing.

the class BinaryUtilTest method check.

private static void check(CharSequence data) {
    BitArray binary = BinaryUtil.buildBitArrayFromString(data);
    assertEquals(data, binary.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray)

Aggregations

BitArray (com.google.zxing.common.BitArray)68 Test (org.junit.Test)28 BinaryBitmap (com.google.zxing.BinaryBitmap)8 Result (com.google.zxing.Result)8 BufferedImageLuminanceSource (com.google.zxing.BufferedImageLuminanceSource)7 WriterException (com.google.zxing.WriterException)7 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)7 BufferedImage (java.awt.image.BufferedImage)7 ResultPoint (com.google.zxing.ResultPoint)6 NotFoundException (com.google.zxing.NotFoundException)5 ReaderException (com.google.zxing.ReaderException)5 BitMatrix (com.google.zxing.common.BitMatrix)4 FinderPattern (com.google.zxing.oned.rss.FinderPattern)4 ArrayList (java.util.ArrayList)4 AbstractExpandedDecoder (com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder)3 Path (java.nio.file.Path)3 DecodeHintType (com.google.zxing.DecodeHintType)2 CharacterSetECI (com.google.zxing.common.CharacterSetECI)2 ReedSolomonEncoder (com.google.zxing.common.reedsolomon.ReedSolomonEncoder)2 DataCharacter (com.google.zxing.oned.rss.DataCharacter)2