Esempio n. 1
0
        private static void assertCorrectImage2binary(String path, String expected)
        {
            RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

            if (!File.Exists(path))
            {
                // Support running from project root too
                path = Path.Combine("..\\..\\..\\Source", path);
            }

#if !SILVERLIGHT
            var image = new Bitmap(Image.FromFile(path));
#else
            var image = new WriteableBitmap(0, 0);
            image.SetSource(File.OpenRead(path));
#endif
            BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BitmapLuminanceSource(image)));
            int          rowNumber = binaryMap.Height / 2;
            BitArray     row       = binaryMap.getBlackRow(rowNumber, null);

            Assert.IsTrue(rssExpandedReader.decodeRow2pairs(rowNumber, row));

            BitArray binary = BitArrayBuilder.buildBitArray(rssExpandedReader.Pairs);
            Assert.AreEqual(expected, binary.ToString());
        }
        private static void assertCorrectImage2binary(String imageFileName, String expected)
        {
            var rssExpandedReader = new RSSExpandedReader();

            var binaryMap = TestCaseUtil.getBinaryBitmap("test/data/blackbox/rssexpanded-1", imageFileName);
            var rowNumber = binaryMap.Height / 2;
            var row       = binaryMap.getBlackRow(rowNumber, null);

            Assert.IsTrue(rssExpandedReader.decodeRow2pairs(rowNumber, row));

            var binary = BitArrayBuilder.buildBitArray(rssExpandedReader.Pairs);

            Assert.AreEqual(expected, binary.ToString());
        }
Esempio n. 3
0
        private static BitArray buildBitArray(int[][] pairValues)
        {
            List <ExpandedPair> pairs = new List <ExpandedPair>();

            for (int i = 0; i < pairValues.Length; ++i)
            {
                int[] pair = pairValues[i];

                DataCharacter leftChar;
                if (i == 0)
                {
                    leftChar = null;
                }
                else
                {
                    leftChar = new DataCharacter(pair[0], 0);
                }

                DataCharacter rightChar;
                if (i == 0)
                {
                    rightChar = new DataCharacter(pair[0], 0);
                }
                else if (pair.Length == 2)
                {
                    rightChar = new DataCharacter(pair[1], 0);
                }
                else
                {
                    rightChar = null;
                }

                ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null);
                pairs.Add(expandedPair);
            }

            return(BitArrayBuilder.buildBitArray(pairs));
        }