Extends DetectorResult with more information specific to the Aztec format, like the number of layers and whether it's compact.
Наследование: ZXing.Common.DetectorResult
Пример #1
0
        /// <summary>
        /// Decodes the specified detector result.
        /// </summary>
        /// <param name="detectorResult">The detector result.</param>
        /// <returns></returns>
        public DecoderResult decode(AztecDetectorResult detectorResult)
        {
            ddata = detectorResult;
            var matrix  = detectorResult.Bits;
            var rawbits = extractBits(matrix);

            if (rawbits == null)
            {
                return(null);
            }

            var correctedBits = correctBits(rawbits);

            if (correctedBits == null)
            {
                return(null);
            }

            var result = getEncodedData(correctedBits.correctBits);

            if (result == null)
            {
                return(null);
            }

            var rawBytes = convertBoolArrayToByteArray(correctedBits.correctBits);

            var decoderResult = new DecoderResult(rawBytes, correctedBits.correctBits.Length, result, null, String.Format("{0}", correctedBits.ecLevel));

            return(decoderResult);
        }
Пример #2
0
        /// <summary>
        /// Decodes the specified detector result.
        /// </summary>
        /// <param name="detectorResult">The detector result.</param>
        /// <returns></returns>
        public DecoderResult decode(AztecDetectorResult detectorResult)
        {
            ddata = detectorResult;
            var matrix  = detectorResult.Bits;
            var rawbits = extractBits(matrix);

            if (rawbits == null)
            {
                return(null);
            }

            var correctedBits = correctBits(rawbits);

            if (correctedBits == null)
            {
                return(null);
            }

            var result = getEncodedData(correctedBits);

            if (result == null)
            {
                return(null);
            }

            var rawBytes = convertBoolArrayToByteArray(correctedBits);

            return(new DecoderResult(rawBytes, result, null, null));
        }
Пример #3
0
        /// <summary>
        /// Decodes the specified detector result.
        /// </summary>
        /// <param name="detectorResult">The detector result.</param>
        /// <returns></returns>
        public DecoderResult decode(AztecDetectorResult detectorResult)
        {
            ddata = detectorResult;
            BitMatrix matrix = detectorResult.Bits;

            bool[] rawbits = extractBits(matrix);
            if (rawbits == null)
            {
                return(null);
            }

            bool[] correctedBits = correctBits(rawbits);
            if (correctedBits == null)
            {
                return(null);
            }

            String result = getEncodedData(correctedBits);

            if (result == null)
            {
                return(null);
            }

            return(new DecoderResult(null, result, null, null));
        }
Пример #4
0
 public void testDecodeTooManyErrors()
 {
    var matrix = BitMatrix.parse(""
                                 + "X X . X . . . X X . . . X . . X X X . X . X X X X X . \n"
                                 + "X X . . X X . . . . . X X . . . X X . . . X . X . . X \n"
                                 + "X . . . X X . . X X X . X X . X X X X . X X . . X . . \n"
                                 + ". . . . X . X X . . X X . X X . X . X X X X . X . . X \n"
                                 + "X X X . . X X X X X . . . . . X X . . . X . X . X . X \n"
                                 + "X X . . . . . . . . X . . . X . X X X . X . . X . . . \n"
                                 + "X X . . X . . . . . X X . . . . . X . . . . X . . X X \n"
                                 + ". . . X . X . X . . . . . X X X X X X . . . . . . X X \n"
                                 + "X . . . X . X X X X X X . . X X X . X . X X X X X X . \n"
                                 + "X . . X X X . X X X X X X X X X X X X X . . . X . X X \n"
                                 + ". . . . X X . . . X . . . . . . . X X . . . X X . X . \n"
                                 + ". . . X X X . . X X . X X X X X . X . . X . . . . . . \n"
                                 + "X . . . . X . X . X . X . . . X . X . X X . X X . X X \n"
                                 + "X . X . . X . X . X . X . X . X . X . . . . . X . X X \n"
                                 + "X . X X X . . X . X . X . . . X . X . X X X . . . X X \n"
                                 + "X X X X X X X X . X . X X X X X . X . X . X . X X X . \n"
                                 + ". . . . . . . X . X . . . . . . . X X X X . . . X X X \n"
                                 + "X X . . X . . X . X X X X X X X X X X X X X . . X . X \n"
                                 + "X X X . X X X X . . X X X X . . X . . . . X . . X X X \n"
                                 + ". . . . X . X X X . . . . X X X X . . X X X X . . . . \n"
                                 + ". . X . . X . X . . . X . X X . X X . X . . . X . X . \n"
                                 + "X X . . X . . X X X X X X X . . X . X X X X X X X . . \n"
                                 + "X . X X . . X X . . . . . X . . . . . . X X . X X X . \n"
                                 + "X . . X X . . X X . X . X . . . . X . X . . X . . X . \n"
                                 + "X . X . X . . X . X X X X X X X X . X X X X . . X X . \n"
                                 + "X X X X . . . X . . X X X . X X . . X . . . . X X X . \n"
                                 + "X X . X . X . . . X . X . . . . X X . X . . X X . . . \n",
                                 "X ", ". ");
    var r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4);
    Assert.That(new Decoder().decode(r), Is.Null);
 }
Пример #5
0
 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);
 }
Пример #6
0
 private static void testEncodeDecode(String data, bool compact, int layers)
 {
    AztecCode aztec = Internal.Encoder.encode(LATIN_1.GetBytes(data), 25, Internal.Encoder.DEFAULT_AZTEC_LAYERS);
    Assert.AreEqual(compact, aztec.isCompact, "Unexpected symbol format (compact)");
    Assert.AreEqual(layers, aztec.Layers, "Unexpected nr. of layers");
    BitMatrix matrix = aztec.Matrix;
    AztecDetectorResult r =
       new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers);
    DecoderResult res = new Internal.Decoder().decode(r);
    Assert.AreEqual(data, res.Text);
    // Check error correction by introducing a few minor errors
    Random random = getPseudoRandom();
    matrix.flip(random.Next(matrix.Width), random.Next(2));
    matrix.flip(random.Next(matrix.Width), matrix.Height - 2 + random.Next(2));
    matrix.flip(random.Next(2), random.Next(matrix.Height));
    matrix.flip(matrix.Width - 2 + random.Next(2), random.Next(matrix.Height));
    r = new AztecDetectorResult(matrix, NO_POINTS, aztec.isCompact, aztec.CodeWords, aztec.Layers);
    res = new Internal.Decoder().decode(r);
    Assert.AreEqual(data, res.Text);
 }
Пример #7
0
      /// <summary>
      /// Decodes the specified detector result.
      /// </summary>
      /// <param name="detectorResult">The detector result.</param>
      /// <returns></returns>
      public DecoderResult decode(AztecDetectorResult detectorResult)
      {
         ddata = detectorResult;
         var matrix = detectorResult.Bits;
         var rawbits = extractBits(matrix);
         if (rawbits == null)
            return null;

         var correctedBits = correctBits(rawbits);
         if (correctedBits == null)
            return null;

         var result = getEncodedData(correctedBits);
         if (result == null)
            return null;

         var rawBytes = convertBoolArrayToByteArray(correctedBits);

         return new DecoderResult(rawBytes, result, null, null);
      }
Пример #8
0
      /// <summary>
      /// Decodes the specified detector result.
      /// </summary>
      /// <param name="detectorResult">The detector result.</param>
      /// <returns></returns>
      public DecoderResult decode(AztecDetectorResult detectorResult)
      {
         ddata = detectorResult;
         BitMatrix matrix = detectorResult.Bits;
         bool[] rawbits = extractBits(matrix);
         if (rawbits == null)
            return null;

         bool[] correctedBits = correctBits(rawbits);
         if (correctedBits == null)
            return null;

         String result = getEncodedData(correctedBits);
         if (result == null)
            return null;

         return new DecoderResult(null, result, null, null);
      }