Exemplo n.º 1
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="o">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        override public bool Equals(Object o)
        {
            if (!(o is FinderPattern))
            {
                return(false);
            }
            FinderPattern that = (FinderPattern)o;

            return(Value == that.Value);
        }
Exemplo n.º 2
0
        private Pair decodePair(BitArray row, bool right, int rowNumber, IDictionary <DecodeHintType, object> hints)
        {
            int[] startEnd = findFinderPattern(row, 0, right);
            if (startEnd == null)
            {
                return(null);
            }
            FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);

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

            ResultPointCallback resultPointCallback = hints == null || !hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK) ? null :
                                                      (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK];

            if (resultPointCallback != null)
            {
                float center = (startEnd[0] + startEnd[1]) / 2.0f;
                if (right)
                {
                    // row is actually reversed
                    center = row.Size - 1 - center;
                }
                resultPointCallback(new ResultPoint(center, rowNumber));
            }

            DataCharacter outside = decodeDataCharacter(row, pattern, true);

            if (outside == null)
            {
                return(null);
            }
            DataCharacter inside = decodeDataCharacter(row, pattern, false);

            if (inside == null)
            {
                return(null);
            }
            return(new Pair(1597 * outside.Value + inside.Value,
                            outside.ChecksumPortion + 4 * inside.ChecksumPortion,
                            pattern));
        }
Exemplo n.º 3
0
      private DataCharacter decodeDataCharacter(BitArray row, FinderPattern pattern, bool outsideChar)
      {
         int[] counters = getDataCharacterCounters();
         counters[0] = 0;
         counters[1] = 0;
         counters[2] = 0;
         counters[3] = 0;
         counters[4] = 0;
         counters[5] = 0;
         counters[6] = 0;
         counters[7] = 0;

         if (outsideChar)
         {
            recordPatternInReverse(row, pattern.StartEnd[0], counters);
         }
         else
         {
            recordPattern(row, pattern.StartEnd[1] + 1, counters);
            // reverse it
            for (int i = 0, j = counters.Length - 1; i < j; i++, j--)
            {
               int temp = counters[i];
               counters[i] = counters[j];
               counters[j] = temp;
            }
         }

         int numModules = outsideChar ? 16 : 15;
         float elementWidth = (float)count(counters) / (float)numModules;

         int[] oddCounts = this.getOddCounts();
         int[] evenCounts = this.getEvenCounts();
         float[] oddRoundingErrors = this.getOddRoundingErrors();
         float[] evenRoundingErrors = this.getEvenRoundingErrors();

         for (int i = 0; i < counters.Length; i++)
         {
            float value = (float)counters[i] / elementWidth;
            int rounded = (int)(value + 0.5f); // Round
            if (rounded < 1)
            {
               rounded = 1;
            }
            else if (rounded > 8)
            {
               rounded = 8;
            }
            int offset = i >> 1;
            if ((i & 0x01) == 0)
            {
               oddCounts[offset] = rounded;
               oddRoundingErrors[offset] = value - rounded;
            }
            else
            {
               evenCounts[offset] = rounded;
               evenRoundingErrors[offset] = value - rounded;
            }
         }

         if (!adjustOddEvenCounts(outsideChar, numModules))
            return null;

         int oddSum = 0;
         int oddChecksumPortion = 0;
         for (int i = oddCounts.Length - 1; i >= 0; i--)
         {
            oddChecksumPortion *= 9;
            oddChecksumPortion += oddCounts[i];
            oddSum += oddCounts[i];
         }
         int evenChecksumPortion = 0;
         int evenSum = 0;
         for (int i = evenCounts.Length - 1; i >= 0; i--)
         {
            evenChecksumPortion *= 9;
            evenChecksumPortion += evenCounts[i];
            evenSum += evenCounts[i];
         }
         int checksumPortion = oddChecksumPortion + 3 * evenChecksumPortion;

         if (outsideChar)
         {
            if ((oddSum & 0x01) != 0 || oddSum > 12 || oddSum < 4)
            {
               return null;
            }
            int group = (12 - oddSum) / 2;
            int oddWidest = OUTSIDE_ODD_WIDEST[group];
            int evenWidest = 9 - oddWidest;
            int vOdd = RSSUtils.getRSSvalue(oddCounts, oddWidest, false);
            int vEven = RSSUtils.getRSSvalue(evenCounts, evenWidest, true);
            int tEven = OUTSIDE_EVEN_TOTAL_SUBSET[group];
            int gSum = OUTSIDE_GSUM[group];
            return new DataCharacter(vOdd * tEven + vEven + gSum, checksumPortion);
         }
         else
         {
            if ((evenSum & 0x01) != 0 || evenSum > 10 || evenSum < 4)
            {
               return null;
            }
            int group = (10 - evenSum) / 2;
            int oddWidest = INSIDE_ODD_WIDEST[group];
            int evenWidest = 9 - oddWidest;
            int vOdd = RSSUtils.getRSSvalue(oddCounts, oddWidest, true);
            int vEven = RSSUtils.getRSSvalue(evenCounts, evenWidest, false);
            int tOdd = INSIDE_ODD_TOTAL_SUBSET[group];
            int gSum = INSIDE_GSUM[group];
            return new DataCharacter(vEven * tOdd + vOdd + gSum, checksumPortion);
         }
      }
Exemplo n.º 4
0
        private DataCharacter decodeDataCharacter(BitArray row, FinderPattern pattern, bool outsideChar)
        {
            int[] counters = getDataCharacterCounters();
            counters[0] = 0;
            counters[1] = 0;
            counters[2] = 0;
            counters[3] = 0;
            counters[4] = 0;
            counters[5] = 0;
            counters[6] = 0;
            counters[7] = 0;

            if (outsideChar)
            {
                recordPatternInReverse(row, pattern.StartEnd[0], counters);
            }
            else
            {
                recordPattern(row, pattern.StartEnd[1] + 1, counters);
                // reverse it
                for (int i = 0, j = counters.Length - 1; i < j; i++, j--)
                {
                    int temp = counters[i];
                    counters[i] = counters[j];
                    counters[j] = temp;
                }
            }

            int   numModules   = outsideChar ? 16 : 15;
            float elementWidth = (float)count(counters) / (float)numModules;

            int[]   oddCounts          = this.getOddCounts();
            int[]   evenCounts         = this.getEvenCounts();
            float[] oddRoundingErrors  = this.getOddRoundingErrors();
            float[] evenRoundingErrors = this.getEvenRoundingErrors();

            for (int i = 0; i < counters.Length; i++)
            {
                float value   = (float)counters[i] / elementWidth;
                int   rounded = (int)(value + 0.5f); // Round
                if (rounded < 1)
                {
                    rounded = 1;
                }
                else if (rounded > 8)
                {
                    rounded = 8;
                }
                int offset = i >> 1;
                if ((i & 0x01) == 0)
                {
                    oddCounts[offset]         = rounded;
                    oddRoundingErrors[offset] = value - rounded;
                }
                else
                {
                    evenCounts[offset]         = rounded;
                    evenRoundingErrors[offset] = value - rounded;
                }
            }

            if (!adjustOddEvenCounts(outsideChar, numModules))
            {
                return(null);
            }

            int oddSum             = 0;
            int oddChecksumPortion = 0;

            for (int i = oddCounts.Length - 1; i >= 0; i--)
            {
                oddChecksumPortion *= 9;
                oddChecksumPortion += oddCounts[i];
                oddSum             += oddCounts[i];
            }
            int evenChecksumPortion = 0;
            int evenSum             = 0;

            for (int i = evenCounts.Length - 1; i >= 0; i--)
            {
                evenChecksumPortion *= 9;
                evenChecksumPortion += evenCounts[i];
                evenSum             += evenCounts[i];
            }
            int checksumPortion = oddChecksumPortion + 3 * evenChecksumPortion;

            if (outsideChar)
            {
                if ((oddSum & 0x01) != 0 || oddSum > 12 || oddSum < 4)
                {
                    return(null);
                }
                int group      = (12 - oddSum) / 2;
                int oddWidest  = OUTSIDE_ODD_WIDEST[group];
                int evenWidest = 9 - oddWidest;
                int vOdd       = RSSUtils.getRSSvalue(oddCounts, oddWidest, false);
                int vEven      = RSSUtils.getRSSvalue(evenCounts, evenWidest, true);
                int tEven      = OUTSIDE_EVEN_TOTAL_SUBSET[group];
                int gSum       = OUTSIDE_GSUM[group];
                return(new DataCharacter(vOdd * tEven + vEven + gSum, checksumPortion));
            }
            else
            {
                if ((evenSum & 0x01) != 0 || evenSum > 10 || evenSum < 4)
                {
                    return(null);
                }
                int group      = (10 - evenSum) / 2;
                int oddWidest  = INSIDE_ODD_WIDEST[group];
                int evenWidest = 9 - oddWidest;
                int vOdd       = RSSUtils.getRSSvalue(oddCounts, oddWidest, true);
                int vEven      = RSSUtils.getRSSvalue(evenCounts, evenWidest, false);
                int tOdd       = INSIDE_ODD_TOTAL_SUBSET[group];
                int gSum       = INSIDE_GSUM[group];
                return(new DataCharacter(vEven * tOdd + vOdd + gSum, checksumPortion));
            }
        }