Search in sources :

Example 76 with BitMatrix

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

the class DataMatrixWriterTestCase method testDataMatrixWriter.

@Test
public void testDataMatrixWriter() {
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    hints.put(EncodeHintType.DATA_MATRIX_SHAPE, SymbolShapeHint.FORCE_SQUARE);
    int bigEnough = 14;
    DataMatrixWriter writer = new DataMatrixWriter();
    BitMatrix matrix = writer.encode("Hello Me", BarcodeFormat.DATA_MATRIX, bigEnough, bigEnough, hints);
    assertNotNull(matrix);
    assertEquals(bigEnough, matrix.getWidth());
    assertEquals(bigEnough, matrix.getHeight());
}
Also used : EncodeHintType(com.google.zxing.EncodeHintType) BitMatrix(com.google.zxing.common.BitMatrix) EnumMap(java.util.EnumMap) SymbolShapeHint(com.google.zxing.datamatrix.encoder.SymbolShapeHint) Test(org.junit.Test)

Example 77 with BitMatrix

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

the class Code128WriterTestCase method testRoundtrip.

@Test
public void testRoundtrip() throws Exception {
    String toEncode = "ñ" + "10958" + "ñ" + "17160526";
    String expected = "1095817160526";
    BitMatrix encResult = writer.encode(toEncode, BarcodeFormat.CODE_128, 0, 0);
    BitArray row = encResult.getRow(0, null);
    Result rtResult = reader.decodeRow(0, row, null);
    String actual = rtResult.getText();
    assertEquals(expected, actual);
}
Also used : BitMatrix(com.google.zxing.common.BitMatrix) BitArray(com.google.zxing.common.BitArray) Result(com.google.zxing.Result) Test(org.junit.Test)

Example 78 with BitMatrix

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

the class QRCodeWriterTestCase method createMatrixFromImage.

// In case the golden images are not monochromatic, convert the RGB values to greyscale.
private static BitMatrix createMatrixFromImage(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    int[] pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);
    BitMatrix matrix = new BitMatrix(width, height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int pixel = pixels[y * width + x];
            int luminance = (306 * ((pixel >> 16) & 0xFF) + 601 * ((pixel >> 8) & 0xFF) + 117 * (pixel & 0xFF)) >> 10;
            if (luminance <= 0x7F) {
                matrix.set(x, y);
            }
        }
    }
    return matrix;
}
Also used : BitMatrix(com.google.zxing.common.BitMatrix)

Example 79 with BitMatrix

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

the class QRCodeWriterTestCase method compareToGoldenFile.

private static void compareToGoldenFile(String contents, ErrorCorrectionLevel ecLevel, int resolution, String fileName) throws WriterException, IOException {
    BufferedImage image = loadImage(fileName);
    assertNotNull(image);
    BitMatrix goldenResult = createMatrixFromImage(image);
    assertNotNull(goldenResult);
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    hints.put(EncodeHintType.ERROR_CORRECTION, ecLevel);
    Writer writer = new QRCodeWriter();
    BitMatrix generatedResult = writer.encode(contents, BarcodeFormat.QR_CODE, resolution, resolution, hints);
    assertEquals(resolution, generatedResult.getWidth());
    assertEquals(resolution, generatedResult.getHeight());
    assertEquals(goldenResult, generatedResult);
}
Also used : EncodeHintType(com.google.zxing.EncodeHintType) BitMatrix(com.google.zxing.common.BitMatrix) EnumMap(java.util.EnumMap) BufferedImage(java.awt.image.BufferedImage) Writer(com.google.zxing.Writer)

Example 80 with BitMatrix

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

the class Code39WriterTestCase method doTest.

private static void doTest(String input, CharSequence expected) throws WriterException {
    BitMatrix result = new Code39Writer().encode(input, BarcodeFormat.CODE_39, 0, 0);
    assertEquals(expected, BitMatrixTestCase.matrixToString(result));
}
Also used : BitMatrix(com.google.zxing.common.BitMatrix)

Aggregations

BitMatrix (com.google.zxing.common.BitMatrix)119 EncodeHintType (com.google.zxing.EncodeHintType)27 ResultPoint (com.google.zxing.ResultPoint)26 Test (org.junit.Test)20 Bitmap (android.graphics.Bitmap)18 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)17 WriterException (com.google.zxing.WriterException)14 DecoderResult (com.google.zxing.common.DecoderResult)12 EnumMap (java.util.EnumMap)11 MultiFormatWriter (com.google.zxing.MultiFormatWriter)10 DetectorResult (com.google.zxing.common.DetectorResult)10 Hashtable (java.util.Hashtable)10 AztecDetectorResult (com.google.zxing.aztec.AztecDetectorResult)8 Result (com.google.zxing.Result)7 Point (com.google.zxing.aztec.detector.Detector.Point)5 SymbolShapeHint (com.google.zxing.datamatrix.encoder.SymbolShapeHint)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 NotFoundException (com.google.zxing.NotFoundException)4