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());
}
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);
}
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;
}
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);
}
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));
}
Aggregations