public void testAztecWriterDefaults() { // Test AztecWriter defaults const string data = "In ut magna vel mauris malesuada"; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0); var aztec = Internal.Encoder.encode(data, Internal.Encoder.DEFAULT_EC_PERCENT, Internal.Encoder.DEFAULT_AZTEC_LAYERS); var expectedMatrix = aztec.Matrix; Assert.AreEqual(matrix, expectedMatrix); }
private static void testWriter(String data, Encoding encoding, int eccPercent, bool compact, int layers, bool disableEci) { // Perform an encode-decode round-trip because it can be lossy. var hints = new Dictionary <EncodeHintType, Object>() ; if (encoding != null) { hints[EncodeHintType.CHARACTER_SET] = encoding.WebName.ToUpper(); } if (disableEci) { hints[EncodeHintType.DISABLE_ECI] = true; } hints[EncodeHintType.ERROR_CORRECTION] = eccPercent; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints); var aztec = Internal.Encoder.encode(data, eccPercent, Internal.Encoder.DEFAULT_AZTEC_LAYERS, encoding, disableEci); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); var matrix2 = aztec.Matrix; Assert.AreEqual(matrix, matrix2); var r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); var res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); // Check error correction by introducing up to eccPercent/2 errors int ecWords = aztec.CodeWords * eccPercent / 100 / 2; var random = getPseudoRandom(); for (int i = 0; i < ecWords; i++) { // don't touch the core int x = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Width - 1 - random.Next(aztec.Layers * 2); int y = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Height - 1 - random.Next(aztec.Layers * 2); matrix.flip(x, y); } r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(data, res.Text); }
private static void testWriter(String data, String charset, int eccPercent, bool compact, int layers) { // 1. Perform an encode-decode round-trip because it can be lossy. // 2. Aztec Decoder currently always decodes the data with a LATIN-1 charset: var byteData = Encoding.GetEncoding(charset).GetBytes(data); var expectedData = LATIN_1.GetString(byteData, 0, byteData.Length); var hints = new Dictionary <EncodeHintType, Object>() ; hints[EncodeHintType.CHARACTER_SET] = charset; hints[EncodeHintType.ERROR_CORRECTION] = eccPercent; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints); var aztec = Internal.Encoder.encode(Encoding.GetEncoding(charset).GetBytes(data), eccPercent, Internal.Encoder.DEFAULT_AZTEC_LAYERS); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); var matrix2 = aztec.Matrix; Assert.AreEqual(matrix, matrix2); var r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); var res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); // Check error correction by introducing up to eccPercent/2 errors int ecWords = aztec.CodeWords * eccPercent / 100 / 2; var random = getPseudoRandom(); for (int i = 0; i < ecWords; i++) { // don't touch the core int x = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Width - 1 - random.Next(aztec.Layers * 2); int y = random.Next(1) > 0 ? random.Next(aztec.Layers * 2) : matrix.Height - 1 - random.Next(aztec.Layers * 2); matrix.flip(x, y); } r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); }
public void testAztecWriter() { testWriter("\u20AC 1 sample data.", "ISO-8859-1", 25, true, 2); testWriter("\u20AC 1 sample data.", "ISO-8859-15", 25, true, 2); testWriter("\u20AC 1 sample data.", "UTF-8", 25, true, 2); testWriter("\u20AC 1 sample data.", "UTF-8", 100, true, 3); testWriter("\u20AC 1 sample data.", "UTF-8", 300, true, 4); testWriter("\u20AC 1 sample data.", "UTF-8", 500, false, 5); // Test AztecWriter defaults const string data = "In ut magna vel mauris malesuada"; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0); var aztec = Internal.Encoder.encode(Encoding.GetEncoding("ISO8859-1").GetBytes(data), Internal.Encoder.DEFAULT_EC_PERCENT, Internal.Encoder.DEFAULT_AZTEC_LAYERS); var expectedMatrix = aztec.Matrix; Assert.AreEqual(matrix, expectedMatrix); }
public override CodeData CreateCodeData(Payload xPayload, CodeOptions xOptions) { AztecCodeOptions xOpt = xOptions as AztecCodeOptions; // if (xOpt == null) { xOpt = new AztecCodeOptions(); } // int width = 1024; int height = 1024; AztecWriter _bcWriter = new AztecWriter(); Dictionary <EncodeHintType, object> Hints = new Dictionary <EncodeHintType, object>(); Hints[EncodeHintType.WIDTH] = width; Hints[EncodeHintType.HEIGHT] = height; //Hints[EncodeHintType.PDF417_COMPACTION] = (ZXing.PDF417.Internal.Compaction)(int)xOpt.m_eCompactionMode; //Hints[EncodeHintType.ERROR_CORRECTION] = (ZXing.PDF417.Internal.PDF417ErrorCorrectionLevel)(xOpt.ErrorCorrm_iectionLevel); //Hints[EncodeHintType.PDF417_DIMENSIONS] = new ZXing.PDF417.Internal.Dimensions(xOpt.m_iDataColumns,xOpt.m_iDataColumns,xOpt.m_iDataRows,100); BitMatrix xData = _bcWriter.encode(xPayload.ToString(), width, height, Hints); // CodeData xResData = new CodeData(xData.Width, xData.Height); // for (int y = 0; y < xData.Height; y++) { for (int x = 0; x < xData.Width; x++) { xResData.ModuleMatrix[y][x] = xData[x, y]; } } // return(xResData); }
private static void testWriter(String data, String charset, int eccPercent, bool compact, int layers) { // 1. Perform an encode-decode round-trip because it can be lossy. // 2. Aztec Decoder currently always decodes the data with a LATIN-1 charset: var byteData = Encoding.GetEncoding(charset).GetBytes(data); var expectedData = LATIN_1.GetString(byteData, 0, byteData.Length); var hints = new Dictionary<EncodeHintType, Object>() ; hints[EncodeHintType.CHARACTER_SET] = charset; hints[EncodeHintType.ERROR_CORRECTION] = eccPercent; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0, hints); var aztec = Internal.Encoder.encode(Encoding.GetEncoding(charset).GetBytes(data), eccPercent, Internal.Encoder.DEFAULT_AZTEC_LAYERS); Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)"); Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers"); var matrix2 = aztec.Matrix; Assert.AreEqual(matrix, matrix2); var r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); var res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); // Check error correction by introducing up to eccPercent errors int ecWords = aztec.CodeWords*eccPercent/100; var random = getPseudoRandom(); for (int i = 0; i < ecWords; i++) { // don't touch the core int x = random.Next(1) > 0 ? random.Next(aztec.Layers*2) : matrix.Width - 1 - random.Next(aztec.Layers*2); int y = random.Next(1) > 0 ? random.Next(aztec.Layers*2) : matrix.Height - 1 - random.Next(aztec.Layers*2); matrix.flip(x, y); } r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers); res = new Internal.Decoder().decode(r); Assert.AreEqual(expectedData, res.Text); }
public void testAztecWriter() { testWriter("\u20AC 1 sample data.", "ISO-8859-1", 25, true, 2); testWriter("\u20AC 1 sample data.", "ISO-8859-15", 25, true, 2); testWriter("\u20AC 1 sample data.", "UTF-8", 25, true, 2); testWriter("\u20AC 1 sample data.", "UTF-8", 100, true, 3); testWriter("\u20AC 1 sample data.", "UTF-8", 300, true, 4); testWriter("\u20AC 1 sample data.", "UTF-8", 500, false, 5); // Test AztecWriter defaults var data = "In ut magna vel mauris malesuada"; var writer = new AztecWriter(); var matrix = writer.encode(data, BarcodeFormat.AZTEC, 0, 0); var aztec = Internal.Encoder.encode(LATIN_1.GetBytes(data), Internal.Encoder.DEFAULT_EC_PERCENT, Internal.Encoder.DEFAULT_AZTEC_LAYERS); var expectedMatrix = aztec.Matrix; Assert.AreEqual(matrix, expectedMatrix); }