Search in sources :

Example 16 with BitArray

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

the class EncoderTestCase method testAppendLengthInfo.

@Test
public void testAppendLengthInfo() throws WriterException {
    BitArray bits = new BitArray();
    // 1 letter (1/1).
    Encoder.appendLengthInfo(// 1 letter (1/1).
    1, Version.getVersionForNumber(1), Mode.NUMERIC, bits);
    // 10 bits.
    assertEquals(" ........ .X", bits.toString());
    bits = new BitArray();
    // 2 letters (2/1).
    Encoder.appendLengthInfo(// 2 letters (2/1).
    2, Version.getVersionForNumber(10), Mode.ALPHANUMERIC, bits);
    // 11 bits.
    assertEquals(" ........ .X.", bits.toString());
    bits = new BitArray();
    // 255 letter (255/1).
    Encoder.appendLengthInfo(// 255 letter (255/1).
    255, Version.getVersionForNumber(27), Mode.BYTE, bits);
    // 16 bits.
    assertEquals(" ........ XXXXXXXX", bits.toString());
    bits = new BitArray();
    // 512 letters (1024/2).
    Encoder.appendLengthInfo(// 512 letters (1024/2).
    512, Version.getVersionForNumber(40), Mode.KANJI, bits);
    // 12 bits.
    assertEquals(" ..X..... ....", bits.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 17 with BitArray

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

the class MatrixUtilTestCase method testBuildMatrix.

@Test
public void testBuildMatrix() throws WriterException {
    // From http://www.swetake.com/qr/qr7.html
    char[] bytes = { 32, 65, 205, 69, 41, 220, 46, 128, 236, 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61 };
    BitArray bits = new BitArray();
    for (char c : bytes) {
        bits.appendBits(c, 8);
    }
    ByteMatrix matrix = new ByteMatrix(21, 21);
    MatrixUtil.buildMatrix(bits, ErrorCorrectionLevel.H, // Version 1
    Version.getVersionForNumber(1), // Mask pattern 3
    3, matrix);
    String expected = " 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\n" + " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" + " 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" + " 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" + " 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" + " 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" + " 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" + " 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" + " 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" + " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" + " 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" + " 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" + " 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" + " 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";
    assertEquals(expected, matrix.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 18 with BitArray

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

the class MatrixUtilTestCase method testEmbedDataBits.

@Test
public void testEmbedDataBits() throws WriterException {
    // Cells other than basic patterns should be filled with zero.
    ByteMatrix matrix = new ByteMatrix(21, 21);
    MatrixUtil.clearMatrix(matrix);
    MatrixUtil.embedBasicPatterns(Version.getVersionForNumber(1), matrix);
    BitArray bits = new BitArray();
    MatrixUtil.embedDataBits(bits, -1, matrix);
    String expected = " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" + " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n";
    assertEquals(expected, matrix.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 19 with BitArray

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

the class MatrixUtilTestCase method testMakeVersionInfoBits.

// We don't test a lot of cases in this function since we've already
// tested them in TEST(calculateBCHCode).
@Test
public void testMakeVersionInfoBits() throws WriterException {
    // From Appendix D in JISX0510:2004 (p 68)
    BitArray bits = new BitArray();
    MatrixUtil.makeVersionInfoBits(Version.getVersionForNumber(7), bits);
    assertEquals(" ...XXXXX ..X..X.X ..", bits.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 20 with BitArray

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

the class EncoderTest method toBitArray.

private static BitArray toBitArray(CharSequence bits) {
    BitArray in = new BitArray();
    char[] str = DOTX.matcher(bits).replaceAll("").toCharArray();
    for (char aStr : str) {
        in.appendBit(aStr == 'X');
    }
    return in;
}
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