Exemplo n.º 1
0
        internal virtual int[] correctDataBlocks(int[] blocks)
        {
            int numCorrections = 0;
            int dataCapacity   = qrCodeSymbol.DataCapacity;

            int[] dataBlocks             = new int[dataCapacity];
            int   numErrorCollectionCode = qrCodeSymbol.NumErrorCollectionCode;
            int   numRSBlocks            = qrCodeSymbol.NumRSBlocks;
            int   eccPerRSBlock          = numErrorCollectionCode / numRSBlocks;

            if (numRSBlocks == 1)
            {
                ReedSolomon corrector = new ReedSolomon(blocks, eccPerRSBlock);
                corrector.correct();
                numCorrections += corrector.NumCorrectedErrors;
                if (numCorrections > 0)
                {
                    canvas.println(System.Convert.ToString(numCorrections) + " data errors corrected.");
                }
                else
                {
                    canvas.println("No errors found.");
                }
                numLastCorrections  = numCorrections;
                correctionSucceeded = corrector.CorrectionSucceeded;
                return(blocks);
            }
            else
            {
                int numLongerRSBlocks = dataCapacity % numRSBlocks;
                if (numLongerRSBlocks == 0)
                {
                    int     lengthRSBlock = dataCapacity / numRSBlocks;
                    int[][] tmpArray      = new int[numRSBlocks][];
                    for (int i = 0; i < numRSBlocks; i++)
                    {
                        tmpArray[i] = new int[lengthRSBlock];
                    }
                    int[][] RSBlocks = tmpArray;
                    for (int i = 0; i < numRSBlocks; i++)
                    {
                        for (int j = 0; j < lengthRSBlock; j++)
                        {
                            RSBlocks[i][j] = blocks[j * numRSBlocks + i];
                        }
                        ReedSolomon corrector = new ReedSolomon(RSBlocks[i], eccPerRSBlock);
                        corrector.correct();
                        numCorrections     += corrector.NumCorrectedErrors;
                        correctionSucceeded = corrector.CorrectionSucceeded;
                    }
                    int p = 0;
                    for (int i = 0; i < numRSBlocks; i++)
                    {
                        for (int j = 0; j < lengthRSBlock - eccPerRSBlock; j++)
                        {
                            dataBlocks[p++] = RSBlocks[i][j];
                        }
                    }
                }
                else
                {
                    int     lengthShorterRSBlock = dataCapacity / numRSBlocks;
                    int     lengthLongerRSBlock  = dataCapacity / numRSBlocks + 1;
                    int     numShorterRSBlocks   = numRSBlocks - numLongerRSBlocks;
                    int[][] tmpArray2            = new int[numShorterRSBlocks][];
                    for (int i2 = 0; i2 < numShorterRSBlocks; i2++)
                    {
                        tmpArray2[i2] = new int[lengthShorterRSBlock];
                    }
                    int[][] shorterRSBlocks = tmpArray2;
                    int[][] tmpArray3       = new int[numLongerRSBlocks][];
                    for (int i3 = 0; i3 < numLongerRSBlocks; i3++)
                    {
                        tmpArray3[i3] = new int[lengthLongerRSBlock];
                    }
                    int[][] longerRSBlocks = tmpArray3;
                    for (int i = 0; i < numRSBlocks; i++)
                    {
                        if (i < numShorterRSBlocks)
                        {
                            int mod = 0;
                            for (int j = 0; j < lengthShorterRSBlock; j++)
                            {
                                if (j == lengthShorterRSBlock - eccPerRSBlock)
                                {
                                    mod = numLongerRSBlocks;
                                }
                                shorterRSBlocks[i][j] = blocks[j * numRSBlocks + i + mod];
                            }
                            ReedSolomon corrector = new ReedSolomon(shorterRSBlocks[i], eccPerRSBlock);
                            corrector.correct();
                            numCorrections     += corrector.NumCorrectedErrors;
                            correctionSucceeded = corrector.CorrectionSucceeded;
                        }
                        else
                        {
                            int mod = 0;
                            for (int j = 0; j < lengthLongerRSBlock; j++)
                            {
                                if (j == lengthShorterRSBlock - eccPerRSBlock)
                                {
                                    mod = numShorterRSBlocks;
                                }
                                longerRSBlocks[i - numShorterRSBlocks][j] = blocks[j * numRSBlocks + i - mod];
                            }

                            ReedSolomon corrector = new ReedSolomon(longerRSBlocks[i - numShorterRSBlocks], eccPerRSBlock);
                            corrector.correct();
                            numCorrections     += corrector.NumCorrectedErrors;
                            correctionSucceeded = corrector.CorrectionSucceeded;
                        }
                    }
                    int p = 0;
                    for (int i = 0; i < numRSBlocks; i++)
                    {
                        if (i < numShorterRSBlocks)
                        {
                            for (int j = 0; j < lengthShorterRSBlock - eccPerRSBlock; j++)
                            {
                                dataBlocks[p++] = shorterRSBlocks[i][j];
                            }
                        }
                        else
                        {
                            for (int j = 0; j < lengthLongerRSBlock - eccPerRSBlock; j++)
                            {
                                dataBlocks[p++] = longerRSBlocks[i - numShorterRSBlocks][j];
                            }
                        }
                    }
                }
                if (numCorrections > 0)
                {
                    canvas.println(Convert.ToString(numCorrections) + " data errors corrected.");
                }
                else
                {
                    canvas.println("No errors found.");
                }
                numLastCorrections = numCorrections;
                return(dataBlocks);
            }
        }
Exemplo n.º 2
0
        internal virtual int[] correctDataBlocks(int[] blocks)
        {
            int num1         = 0;
            int dataCapacity = this.qrCodeSymbol.DataCapacity;

            int[] numArray1           = new int[dataCapacity];
            int   errorCollectionCode = this.qrCodeSymbol.NumErrorCollectionCode;
            int   numRsBlocks         = this.qrCodeSymbol.NumRSBlocks;
            int   NPAR = errorCollectionCode / numRsBlocks;

            if (numRsBlocks == 1)
            {
                ReedSolomon reedSolomon = new ReedSolomon(blocks, NPAR);
                reedSolomon.correct();
                int num2 = num1 + reedSolomon.NumCorrectedErrors;
                if (num2 > 0)
                {
                    QRCodeDecoder.canvas.println(Convert.ToString(num2) + " data errors corrected.");
                }
                else
                {
                    QRCodeDecoder.canvas.println("No errors found.");
                }
                this.numLastCorrections  = num2;
                this.correctionSucceeded = reedSolomon.CorrectionSucceeded;
                return(blocks);
            }
            int length1 = dataCapacity % numRsBlocks;

            if (length1 == 0)
            {
                int     length2   = dataCapacity / numRsBlocks;
                int[][] numArray2 = new int[numRsBlocks][];
                for (int index = 0; index < numRsBlocks; ++index)
                {
                    numArray2[index] = new int[length2];
                }
                int[][] numArray3 = numArray2;
                for (int index1 = 0; index1 < numRsBlocks; ++index1)
                {
                    for (int index2 = 0; index2 < length2; ++index2)
                    {
                        numArray3[index1][index2] = blocks[index2 * numRsBlocks + index1];
                    }
                    ReedSolomon reedSolomon = new ReedSolomon(numArray3[index1], NPAR);
                    reedSolomon.correct();
                    num1 += reedSolomon.NumCorrectedErrors;
                    this.correctionSucceeded = reedSolomon.CorrectionSucceeded;
                }
                int num2 = 0;
                for (int index1 = 0; index1 < numRsBlocks; ++index1)
                {
                    for (int index2 = 0; index2 < length2 - NPAR; ++index2)
                    {
                        numArray1[num2++] = numArray3[index1][index2];
                    }
                }
            }
            else
            {
                int     length2   = dataCapacity / numRsBlocks;
                int     length3   = dataCapacity / numRsBlocks + 1;
                int     length4   = numRsBlocks - length1;
                int[][] numArray2 = new int[length4][];
                for (int index = 0; index < length4; ++index)
                {
                    numArray2[index] = new int[length2];
                }
                int[][] numArray3 = numArray2;
                int[][] numArray4 = new int[length1][];
                for (int index = 0; index < length1; ++index)
                {
                    numArray4[index] = new int[length3];
                }
                int[][] numArray5 = numArray4;
                for (int index1 = 0; index1 < numRsBlocks; ++index1)
                {
                    if (index1 < length4)
                    {
                        int num2 = 0;
                        for (int index2 = 0; index2 < length2; ++index2)
                        {
                            if (index2 == length2 - NPAR)
                            {
                                num2 = length1;
                            }
                            numArray3[index1][index2] = blocks[index2 * numRsBlocks + index1 + num2];
                        }
                        ReedSolomon reedSolomon = new ReedSolomon(numArray3[index1], NPAR);
                        reedSolomon.correct();
                        num1 += reedSolomon.NumCorrectedErrors;
                        this.correctionSucceeded = reedSolomon.CorrectionSucceeded;
                    }
                    else
                    {
                        int num2 = 0;
                        for (int index2 = 0; index2 < length3; ++index2)
                        {
                            if (index2 == length2 - NPAR)
                            {
                                num2 = length4;
                            }
                            numArray5[index1 - length4][index2] = blocks[index2 * numRsBlocks + index1 - num2];
                        }
                        ReedSolomon reedSolomon = new ReedSolomon(numArray5[index1 - length4], NPAR);
                        reedSolomon.correct();
                        num1 += reedSolomon.NumCorrectedErrors;
                        this.correctionSucceeded = reedSolomon.CorrectionSucceeded;
                    }
                }
                int num3 = 0;
                for (int index1 = 0; index1 < numRsBlocks; ++index1)
                {
                    if (index1 < length4)
                    {
                        for (int index2 = 0; index2 < length2 - NPAR; ++index2)
                        {
                            numArray1[num3++] = numArray3[index1][index2];
                        }
                    }
                    else
                    {
                        for (int index2 = 0; index2 < length3 - NPAR; ++index2)
                        {
                            numArray1[num3++] = numArray5[index1 - length4][index2];
                        }
                    }
                }
            }
            if (num1 > 0)
            {
                QRCodeDecoder.canvas.println(Convert.ToString(num1) + " data errors corrected.");
            }
            else
            {
                QRCodeDecoder.canvas.println("No errors found.");
            }
            this.numLastCorrections = num1;
            return(numArray1);
        }
Exemplo n.º 3
0
        internal virtual int[] correctDataBlocks(int[] blocks)
        {
            ReedSolomon solomon;
            int         num8;
            int         num9;
            int         num10;
            int         num          = 0;
            int         dataCapacity = this.qrCodeSymbol.DataCapacity;

            int[] numArray = new int[dataCapacity];
            int   numErrorCollectionCode = this.qrCodeSymbol.NumErrorCollectionCode;
            int   numRSBlocks            = this.qrCodeSymbol.NumRSBlocks;
            int   nPAR = numErrorCollectionCode / numRSBlocks;

            if (numRSBlocks == 1)
            {
                solomon = new ReedSolomon(blocks, nPAR);
                solomon.correct();
                num += solomon.NumCorrectedErrors;
                if (num > 0)
                {
                    canvas.println(Convert.ToString(num) + " data errors corrected.");
                }
                else
                {
                    canvas.println("No errors found.");
                }
                this.numLastCorrections  = num;
                this.correctionSucceeded = solomon.CorrectionSucceeded;
                return(blocks);
            }
            int num6 = dataCapacity % numRSBlocks;

            if (num6 == 0)
            {
                int     num7      = dataCapacity / numRSBlocks;
                int[][] numArray2 = new int[numRSBlocks][];
                for (num8 = 0; num8 < numRSBlocks; num8++)
                {
                    numArray2[num8] = new int[num7];
                }
                int[][] numArray3 = numArray2;
                for (num8 = 0; num8 < numRSBlocks; num8++)
                {
                    num9 = 0;
                    while (num9 < num7)
                    {
                        numArray3[num8][num9] = blocks[(num9 * numRSBlocks) + num8];
                        num9++;
                    }
                    solomon = new ReedSolomon(numArray3[num8], nPAR);
                    solomon.correct();
                    num += solomon.NumCorrectedErrors;
                    this.correctionSucceeded = solomon.CorrectionSucceeded;
                }
                num10 = 0;
                for (num8 = 0; num8 < numRSBlocks; num8++)
                {
                    num9 = 0;
                    while (num9 < (num7 - nPAR))
                    {
                        numArray[num10++] = numArray3[num8][num9];
                        num9++;
                    }
                }
            }
            else
            {
                int     num11     = dataCapacity / numRSBlocks;
                int     num12     = (dataCapacity / numRSBlocks) + 1;
                int     num13     = numRSBlocks - num6;
                int[][] numArray4 = new int[num13][];
                for (int i = 0; i < num13; i++)
                {
                    numArray4[i] = new int[num11];
                }
                int[][] numArray5 = numArray4;
                int[][] numArray6 = new int[num6][];
                for (int j = 0; j < num6; j++)
                {
                    numArray6[j] = new int[num12];
                }
                int[][] numArray7 = numArray6;
                for (num8 = 0; num8 < numRSBlocks; num8++)
                {
                    int num16;
                    if (num8 < num13)
                    {
                        num16 = 0;
                        num9  = 0;
                        while (num9 < num11)
                        {
                            if (num9 == (num11 - nPAR))
                            {
                                num16 = num6;
                            }
                            numArray5[num8][num9] = blocks[((num9 * numRSBlocks) + num8) + num16];
                            num9++;
                        }
                        solomon = new ReedSolomon(numArray5[num8], nPAR);
                        solomon.correct();
                        num += solomon.NumCorrectedErrors;
                        this.correctionSucceeded = solomon.CorrectionSucceeded;
                    }
                    else
                    {
                        num16 = 0;
                        num9  = 0;
                        while (num9 < num12)
                        {
                            if (num9 == (num11 - nPAR))
                            {
                                num16 = num13;
                            }
                            numArray7[num8 - num13][num9] = blocks[((num9 * numRSBlocks) + num8) - num16];
                            num9++;
                        }
                        solomon = new ReedSolomon(numArray7[num8 - num13], nPAR);
                        solomon.correct();
                        num += solomon.NumCorrectedErrors;
                        this.correctionSucceeded = solomon.CorrectionSucceeded;
                    }
                }
                num10 = 0;
                for (num8 = 0; num8 < numRSBlocks; num8++)
                {
                    if (num8 < num13)
                    {
                        num9 = 0;
                        while (num9 < (num11 - nPAR))
                        {
                            numArray[num10++] = numArray5[num8][num9];
                            num9++;
                        }
                    }
                    else
                    {
                        for (num9 = 0; num9 < (num12 - nPAR); num9++)
                        {
                            numArray[num10++] = numArray7[num8 - num13][num9];
                        }
                    }
                }
            }
            if (num > 0)
            {
                canvas.println(Convert.ToString(num) + " data errors corrected.");
            }
            else
            {
                canvas.println("No errors found.");
            }
            this.numLastCorrections = num;
            return(numArray);
        }
Exemplo n.º 4
0
        internal virtual int[] correctDataBlocks(int[] blocks)
        {
            int num          = 0;
            int dataCapacity = qrCodeSymbol.DataCapacity;

            int[] array = new int[dataCapacity];
            int   numErrorCollectionCode = qrCodeSymbol.NumErrorCollectionCode;
            int   numRSBlocks            = qrCodeSymbol.NumRSBlocks;
            int   num2 = numErrorCollectionCode / numRSBlocks;

            if (numRSBlocks == 1)
            {
                ReedSolomon reedSolomon = new ReedSolomon(blocks, num2);
                reedSolomon.correct();
                num += reedSolomon.NumCorrectedErrors;
                if (num > 0)
                {
                    canvas.println(Convert.ToString(num) + " data errors corrected.");
                }
                else
                {
                    canvas.println("No errors found.");
                }
                numLastCorrections  = num;
                correctionSucceeded = reedSolomon.CorrectionSucceeded;
                return(blocks);
            }
            int num3 = dataCapacity % numRSBlocks;

            if (num3 == 0)
            {
                int     num4   = dataCapacity / numRSBlocks;
                int[][] array2 = new int[numRSBlocks][];
                for (int i = 0; i < numRSBlocks; i++)
                {
                    array2[i] = new int[num4];
                }
                int[][] array3 = array2;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    for (int j = 0; j < num4; j++)
                    {
                        array3[i][j] = blocks[j * numRSBlocks + i];
                    }
                    ReedSolomon reedSolomon = new ReedSolomon(array3[i], num2);
                    reedSolomon.correct();
                    num += reedSolomon.NumCorrectedErrors;
                    correctionSucceeded = reedSolomon.CorrectionSucceeded;
                }
                int num5 = 0;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    for (int j = 0; j < num4 - num2; j++)
                    {
                        array[num5++] = array3[i][j];
                    }
                }
            }
            else
            {
                int     num6   = dataCapacity / numRSBlocks;
                int     num7   = dataCapacity / numRSBlocks + 1;
                int     num8   = numRSBlocks - num3;
                int[][] array4 = new int[num8][];
                for (int k = 0; k < num8; k++)
                {
                    array4[k] = new int[num6];
                }
                int[][] array5 = array4;
                int[][] array6 = new int[num3][];
                for (int l = 0; l < num3; l++)
                {
                    array6[l] = new int[num7];
                }
                int[][] array7 = array6;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    int         num9;
                    ReedSolomon reedSolomon;
                    if (i < num8)
                    {
                        num9 = 0;
                        for (int j = 0; j < num6; j++)
                        {
                            if (j == num6 - num2)
                            {
                                num9 = num3;
                            }
                            array5[i][j] = blocks[j * numRSBlocks + i + num9];
                        }
                        reedSolomon = new ReedSolomon(array5[i], num2);
                        reedSolomon.correct();
                        num += reedSolomon.NumCorrectedErrors;
                        correctionSucceeded = reedSolomon.CorrectionSucceeded;
                        continue;
                    }
                    num9 = 0;
                    for (int j = 0; j < num7; j++)
                    {
                        if (j == num6 - num2)
                        {
                            num9 = num8;
                        }
                        array7[i - num8][j] = blocks[j * numRSBlocks + i - num9];
                    }
                    reedSolomon = new ReedSolomon(array7[i - num8], num2);
                    reedSolomon.correct();
                    num += reedSolomon.NumCorrectedErrors;
                    correctionSucceeded = reedSolomon.CorrectionSucceeded;
                }
                int num5 = 0;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    if (i < num8)
                    {
                        for (int j = 0; j < num6 - num2; j++)
                        {
                            array[num5++] = array5[i][j];
                        }
                    }
                    else
                    {
                        for (int j = 0; j < num7 - num2; j++)
                        {
                            array[num5++] = array7[i - num8][j];
                        }
                    }
                }
            }
            if (num > 0)
            {
                canvas.println(Convert.ToString(num) + " data errors corrected.");
            }
            else
            {
                canvas.println("No errors found.");
            }
            numLastCorrections = num;
            return(array);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The correct data blocks.
        /// </summary>
        /// <param name="blocks">
        /// The blocks.
        /// </param>
        /// <returns>
        /// </returns>
        internal virtual int[] correctDataBlocks(int[] blocks)
        {
            int numCorrections = 0;
            int dataCapacity   = this.qrCodeSymbol.DataCapacity;

            int[] dataBlocks             = new int[dataCapacity];
            int   numErrorCollectionCode = this.qrCodeSymbol.NumErrorCollectionCode;
            int   numRSBlocks            = this.qrCodeSymbol.NumRSBlocks;
            int   eccPerRSBlock          = numErrorCollectionCode / numRSBlocks;

            if (numRSBlocks == 1)
            {
                ReedSolomon corrector = new ReedSolomon(blocks, eccPerRSBlock);
                corrector.correct();
                numCorrections += corrector.NumCorrectedErrors;
                if (numCorrections > 0)
                {
                    canvas.println(Convert.ToString(numCorrections) + " data errors corrected.");
                }
                else
                {
                    canvas.println("No errors found.");
                }

                this.numLastCorrections  = numCorrections;
                this.correctionSucceeded = corrector.CorrectionSucceeded;
                return(blocks);
            }

            // we have to interleave data blocks because symbol has 2 or more RS blocks
            int numLongerRSBlocks = dataCapacity % numRSBlocks;

            if (numLongerRSBlocks == 0)
            {
                // symbol has only 1 type of RS block
                int     lengthRSBlock = dataCapacity / numRSBlocks;
                int[][] tmpArray      = new int[numRSBlocks][];
                for (int i = 0; i < numRSBlocks; i++)
                {
                    tmpArray[i] = new int[lengthRSBlock];
                }

                int[][] RSBlocks = tmpArray;

                // obtain RS blocks
                for (int i = 0; i < numRSBlocks; i++)
                {
                    for (int j = 0; j < lengthRSBlock; j++)
                    {
                        RSBlocks[i][j] = blocks[j * numRSBlocks + i];
                    }

                    ReedSolomon corrector = new ReedSolomon(RSBlocks[i], eccPerRSBlock);
                    corrector.correct();
                    numCorrections          += corrector.NumCorrectedErrors;
                    this.correctionSucceeded = corrector.CorrectionSucceeded;
                }

                // obtain only data part
                int p = 0;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    for (int j = 0; j < lengthRSBlock - eccPerRSBlock; j++)
                    {
                        dataBlocks[p++] = RSBlocks[i][j];
                    }
                }
            }
            else
            {
                // symbol has 2 types of RS blocks
                int     lengthShorterRSBlock = dataCapacity / numRSBlocks;
                int     lengthLongerRSBlock  = dataCapacity / numRSBlocks + 1;
                int     numShorterRSBlocks   = numRSBlocks - numLongerRSBlocks;
                int[][] tmpArray2            = new int[numShorterRSBlocks][];
                for (int i2 = 0; i2 < numShorterRSBlocks; i2++)
                {
                    tmpArray2[i2] = new int[lengthShorterRSBlock];
                }

                int[][] shorterRSBlocks = tmpArray2;
                int[][] tmpArray3       = new int[numLongerRSBlocks][];
                for (int i3 = 0; i3 < numLongerRSBlocks; i3++)
                {
                    tmpArray3[i3] = new int[lengthLongerRSBlock];
                }

                int[][] longerRSBlocks = tmpArray3;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    if (i < numShorterRSBlocks)
                    {
                        // get shorter RS Block(s)
                        int mod = 0;
                        for (int j = 0; j < lengthShorterRSBlock; j++)
                        {
                            if (j == lengthShorterRSBlock - eccPerRSBlock)
                            {
                                mod = numLongerRSBlocks;
                            }

                            shorterRSBlocks[i][j] = blocks[j * numRSBlocks + i + mod];
                        }

                        ReedSolomon corrector = new ReedSolomon(shorterRSBlocks[i], eccPerRSBlock);
                        corrector.correct();
                        numCorrections          += corrector.NumCorrectedErrors;
                        this.correctionSucceeded = corrector.CorrectionSucceeded;
                    }
                    else
                    {
                        // get longer RS Blocks
                        int mod = 0;
                        for (int j = 0; j < lengthLongerRSBlock; j++)
                        {
                            if (j == lengthShorterRSBlock - eccPerRSBlock)
                            {
                                mod = numShorterRSBlocks;
                            }

                            longerRSBlocks[i - numShorterRSBlocks][j] = blocks[j * numRSBlocks + i - mod];
                        }

                        ReedSolomon corrector = new ReedSolomon(
                            longerRSBlocks[i - numShorterRSBlocks], eccPerRSBlock);
                        corrector.correct();
                        numCorrections          += corrector.NumCorrectedErrors;
                        this.correctionSucceeded = corrector.CorrectionSucceeded;
                    }
                }

                int p = 0;
                for (int i = 0; i < numRSBlocks; i++)
                {
                    if (i < numShorterRSBlocks)
                    {
                        for (int j = 0; j < lengthShorterRSBlock - eccPerRSBlock; j++)
                        {
                            dataBlocks[p++] = shorterRSBlocks[i][j];
                        }
                    }
                    else
                    {
                        for (int j = 0; j < lengthLongerRSBlock - eccPerRSBlock; j++)
                        {
                            dataBlocks[p++] = longerRSBlocks[i - numShorterRSBlocks][j];
                        }
                    }
                }
            }

            if (numCorrections > 0)
            {
                canvas.println(Convert.ToString(numCorrections) + " data errors corrected.");
            }
            else
            {
                canvas.println("No errors found.");
            }

            this.numLastCorrections = numCorrections;
            return(dataBlocks);
        }