Search in sources :

Example 46 with BitArray

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

the class EncoderTestCase method testAppend8BitBytes.

@Test
public void testAppend8BitBytes() throws WriterException {
    // 0x61, 0x62, 0x63
    BitArray bits = new BitArray();
    Encoder.append8BitBytes("abc", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
    // Empty.
    bits = new BitArray();
    Encoder.append8BitBytes("", bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals("", bits.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 47 with BitArray

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

the class EncoderTestCase method testTerminateBits.

@Test
public void testTerminateBits() throws WriterException {
    BitArray v = new BitArray();
    Encoder.terminateBits(0, v);
    assertEquals("", v.toString());
    v = new BitArray();
    Encoder.terminateBits(1, v);
    assertEquals(" ........", v.toString());
    v = new BitArray();
    // Append 000
    v.appendBits(0, 3);
    Encoder.terminateBits(1, v);
    assertEquals(" ........", v.toString());
    v = new BitArray();
    // Append 00000
    v.appendBits(0, 5);
    Encoder.terminateBits(1, v);
    assertEquals(" ........", v.toString());
    v = new BitArray();
    // Append 00000000
    v.appendBits(0, 8);
    Encoder.terminateBits(1, v);
    assertEquals(" ........", v.toString());
    v = new BitArray();
    Encoder.terminateBits(2, v);
    assertEquals(" ........ XXX.XX..", v.toString());
    v = new BitArray();
    // Append 0
    v.appendBits(0, 1);
    Encoder.terminateBits(3, v);
    assertEquals(" ........ XXX.XX.. ...X...X", v.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 48 with BitArray

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

the class EncoderTestCase method testAppendBytes.

@Test
public void testAppendBytes() throws WriterException {
    // Should use appendNumericBytes.
    // 1 = 01 = 0001 in 4 bits.
    BitArray bits = new BitArray();
    Encoder.appendBytes("1", Mode.NUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals(" ...X", bits.toString());
    // Should use appendAlphanumericBytes.
    // A = 10 = 0xa = 001010 in 6 bits
    bits = new BitArray();
    Encoder.appendBytes("A", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals(" ..X.X.", bits.toString());
    // Lower letters such as 'a' cannot be encoded in MODE_ALPHANUMERIC.
    try {
        Encoder.appendBytes("a", Mode.ALPHANUMERIC, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    } catch (WriterException we) {
    // good
    }
    // Should use append8BitBytes.
    // 0x61, 0x62, 0x63
    bits = new BitArray();
    Encoder.appendBytes("abc", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals(" .XX....X .XX...X. .XX...XX", bits.toString());
    // Anything can be encoded in QRCode.MODE_8BIT_BYTE.
    Encoder.appendBytes("\0", Mode.BYTE, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    // Should use appendKanjiBytes.
    // 0x93, 0x5f
    bits = new BitArray();
    Encoder.appendBytes(shiftJISString(new byte[] { (byte) 0x93, 0x5f }), Mode.KANJI, bits, Encoder.DEFAULT_BYTE_MODE_ENCODING);
    assertEquals(" .XX.XX.. XXXXX", bits.toString());
}
Also used : BitArray(com.google.zxing.common.BitArray) WriterException(com.google.zxing.WriterException) Test(org.junit.Test)

Example 49 with BitArray

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

the class EncoderTestCase method testInterleaveWithECBytes.

@Test
public void testInterleaveWithECBytes() throws WriterException {
    byte[] dataBytes = { 32, 65, (byte) 205, 69, 41, (byte) 220, 46, (byte) 128, (byte) 236 };
    BitArray in = new BitArray();
    for (byte dataByte : dataBytes) {
        in.appendBits(dataByte, 8);
    }
    BitArray out = Encoder.interleaveWithECBytes(in, 26, 9, 1);
    byte[] expected = { // Data bytes.
    32, 65, (byte) 205, 69, 41, (byte) 220, 46, (byte) 128, (byte) 236, // Error correction bytes.
    42, (byte) 159, 74, (byte) 221, (byte) 244, (byte) 169, (byte) 239, (byte) 150, (byte) 138, 70, (byte) 237, 85, (byte) 224, 96, 74, (byte) 219, 61 };
    assertEquals(expected.length, out.getSizeInBytes());
    byte[] outArray = new byte[expected.length];
    out.toBytes(0, outArray, 0, expected.length);
    // Can't use Arrays.equals(), because outArray may be longer than out.sizeInBytes()
    for (int x = 0; x < expected.length; x++) {
        assertEquals(expected[x], outArray[x]);
    }
    // Numbers are from http://www.swetake.com/qr/qr8.html
    dataBytes = new byte[] { 67, 70, 22, 38, 54, 70, 86, 102, 118, (byte) 134, (byte) 150, (byte) 166, (byte) 182, (byte) 198, (byte) 214, (byte) 230, (byte) 247, 7, 23, 39, 55, 71, 87, 103, 119, (byte) 135, (byte) 151, (byte) 166, 22, 38, 54, 70, 86, 102, 118, (byte) 134, (byte) 150, (byte) 166, (byte) 182, (byte) 198, (byte) 214, (byte) 230, (byte) 247, 7, 23, 39, 55, 71, 87, 103, 119, (byte) 135, (byte) 151, (byte) 160, (byte) 236, 17, (byte) 236, 17, (byte) 236, 17, (byte) 236, 17 };
    in = new BitArray();
    for (byte dataByte : dataBytes) {
        in.appendBits(dataByte, 8);
    }
    out = Encoder.interleaveWithECBytes(in, 134, 62, 4);
    expected = new byte[] { // Data bytes.
    67, (byte) 230, 54, 55, 70, (byte) 247, 70, 71, 22, 7, 86, 87, 38, 23, 102, 103, 54, 39, 118, 119, 70, 55, (byte) 134, (byte) 135, 86, 71, (byte) 150, (byte) 151, 102, 87, (byte) 166, (byte) 160, 118, 103, (byte) 182, (byte) 236, (byte) 134, 119, (byte) 198, 17, (byte) 150, (byte) 135, (byte) 214, (byte) 236, (byte) 166, (byte) 151, (byte) 230, 17, (byte) 182, (byte) 166, (byte) 247, (byte) 236, (byte) 198, 22, 7, 17, (byte) 214, 38, 23, (byte) 236, 39, 17, // Error correction bytes.
    (byte) 175, (byte) 155, (byte) 245, (byte) 236, 80, (byte) 146, 56, 74, (byte) 155, (byte) 165, (byte) 133, (byte) 142, 64, (byte) 183, (byte) 132, 13, (byte) 178, 54, (byte) 132, 108, 45, 113, 53, 50, (byte) 214, 98, (byte) 193, (byte) 152, (byte) 233, (byte) 147, 50, 71, 65, (byte) 190, 82, 51, (byte) 209, (byte) 199, (byte) 171, 54, 12, 112, 57, 113, (byte) 155, 117, (byte) 211, (byte) 164, 117, 30, (byte) 158, (byte) 225, 31, (byte) 190, (byte) 242, 38, (byte) 140, 61, (byte) 179, (byte) 154, (byte) 214, (byte) 138, (byte) 147, 87, 27, 96, 77, 47, (byte) 187, 49, (byte) 156, (byte) 214 };
    assertEquals(expected.length, out.getSizeInBytes());
    outArray = new byte[expected.length];
    out.toBytes(0, outArray, 0, expected.length);
    for (int x = 0; x < expected.length; x++) {
        assertEquals(expected[x], outArray[x]);
    }
}
Also used : BitArray(com.google.zxing.common.BitArray) Test(org.junit.Test)

Example 50 with BitArray

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

the class EncoderTestCase method testAppendAlphanumericBytes.

@Test
public void testAppendAlphanumericBytes() throws WriterException {
    // A = 10 = 0xa = 001010 in 6 bits
    BitArray bits = new BitArray();
    Encoder.appendAlphanumericBytes("A", bits);
    assertEquals(" ..X.X.", bits.toString());
    // AB = 10 * 45 + 11 = 461 = 0x1cd = 00111001101 in 11 bits
    bits = new BitArray();
    Encoder.appendAlphanumericBytes("AB", bits);
    assertEquals(" ..XXX..X X.X", bits.toString());
    // ABC = "AB" + "C" = 00111001101 + 001100
    bits = new BitArray();
    Encoder.appendAlphanumericBytes("ABC", bits);
    assertEquals(" ..XXX..X X.X..XX. .", bits.toString());
    // Empty.
    bits = new BitArray();
    Encoder.appendAlphanumericBytes("", bits);
    assertEquals("", bits.toString());
    // Invalid data.
    try {
        Encoder.appendAlphanumericBytes("abc", new BitArray());
    } catch (WriterException we) {
    // good
    }
}
Also used : BitArray(com.google.zxing.common.BitArray) WriterException(com.google.zxing.WriterException) Test(org.junit.Test)

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