Beispiel #1
0
        int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString)
        {
            int[] counters = decodeMiddleCounters;
            counters[0] = 0;
            counters[1] = 0;
            counters[2] = 0;
            counters[3] = 0;
            int end       = row.Size;
            int rowOffset = startRange[1];

            int lgPatternFound = 0;

            for (int x = 0; x < 5 && rowOffset < end; x++)
            {
                int bestMatch;
                if (!UPCEANReader.decodeDigit(row, counters, rowOffset, UPCEANReader.L_AND_G_PATTERNS, out bestMatch))
                {
                    return(-1);
                }
                resultString.Append((char)('0' + bestMatch % 10));
                foreach (int counter in counters)
                {
                    rowOffset += counter;
                }
                if (bestMatch >= 10)
                {
                    lgPatternFound |= 1 << (4 - x);
                }
                if (x != 4)
                {
                    // Read off separator if not last
                    rowOffset = row.getNextSet(rowOffset);
                    rowOffset = row.getNextUnset(rowOffset);
                }
            }

            if (resultString.Length != 5)
            {
                return(-1);
            }

            int checkDigit;

            if (!determineCheckDigit(lgPatternFound, out checkDigit))
            {
                return(-1);
            }

            if (extensionChecksum(resultString.ToString()) != checkDigit)
            {
                return(-1);
            }

            return(rowOffset);
        }
Beispiel #2
0
        int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString)
        {
            int[] counters = decodeMiddleCounters;
            counters[0] = 0;
            counters[1] = 0;
            counters[2] = 0;
            counters[3] = 0;
            int end       = row.Size;
            int rowOffset = startRange[1];

            int checkParity = 0;

            for (int x = 0; x < 2 && rowOffset < end; x++)
            {
                int bestMatch;
                if (!UPCEANReader.decodeDigit(row, counters, rowOffset, UPCEANReader.L_AND_G_PATTERNS, out bestMatch))
                {
                    return(-1);
                }
                resultString.Append((char)('0' + bestMatch % 10));
                foreach (int counter in counters)
                {
                    rowOffset += counter;
                }
                if (bestMatch >= 10)
                {
                    checkParity |= 1 << (1 - x);
                }
                if (x != 1)
                {
                    // Read off separator if not last
                    rowOffset = row.getNextSet(rowOffset);
                    rowOffset = row.getNextUnset(rowOffset);
                }
            }

            if (resultString.Length != 2)
            {
                return(-1);
            }

            if (int.Parse(resultString.ToString()) % 4 != checkParity)
            {
                return(-1);
            }

            return(rowOffset);
        }