Exemple #1
0
        private void RtbSource_TextChanged(object sender, EventArgs e)
        {
            SetDefaultEncodingTextInfo();
            if (RtbSource.TextLength == 0)
            {
                return;
            }

            try
            {
                var encoded = ArithmeticCoding.Encode(RtbSource.Text);
                _lastSavedEncoded = encoded.ToString();

                LblSourceEntropy.Text  += ArithmeticInfo.GetEntropy(encoded.OccurrenceFrequencies);
                LblEncodedEntropy.Text += ArithmeticInfo.GetEntropy(encoded);
                LblCompressRatio.Text  += ArithmeticInfo.GetCompressionRatio(encoded);
                LblRedundantRatio.Text += ArithmeticInfo.GetRedundantRatio(encoded);
                LblAlphabetSize.Text   += encoded.OccurrenceFrequencies.Count;
                LblTextLength.Text     += RtbSource.TextLength;
                LblEncoded.Text        += _lastSavedEncoded;
                if (_lastSavedEncoded.Length > MaxCodeLength)
                {
                    BtnShowFullEncoded.Visible = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void TestCoding32AlphabetAnd96TextLength()
        {
            var source  = "АбвгдеёйжзийклмнопрстуфхчшщьъэюяАбвгдеёйжзийклмнопрстуфхчшщьъэюяАбвгдеёйжзийклмнопрстуфхчшщьъэюя";
            var encoded = ArithmeticCoding.Encode(source);
            var decoded = ArithmeticCoding.Decode(encoded);

            Assert.AreEqual(source, decoded);
        }
        public void TestCoding20AlphabetAbd20TextLength()
        {
            var source  = "абвгдеёжзийклмнопрст";
            var encoded = ArithmeticCoding.Encode(source);
            var decoded = ArithmeticCoding.Decode(encoded);

            Assert.AreEqual(source, decoded);
        }
        public void TestCoding1AlphabetAnd20TextLength()
        {
            var source  = "cccccccccccccccccccc";
            var encoded = ArithmeticCoding.Encode(source);
            var decoded = ArithmeticCoding.Decode(encoded);

            Assert.AreEqual(source, decoded);
        }
        public void TestCoding64AlphabetAnd128TextLength()
        {
            var source = "абвгдеёжзийклмнопрстуфхчшщъьэюяABCDEFGHIJKLMNOPQRSTUVWXYZ123456" +
                         "абвгдеёжзийклмнопрстуфхчшщъьэюяABCDEFGHIJKLMNOPQRSTUVWXYZ123456";
            var encoded = ArithmeticCoding.Encode(source);
            var decoded = ArithmeticCoding.Decode(encoded);

            Assert.AreEqual(source, decoded);
        }
        public void TestEncodeWriteAndReadDecode()
        {
            const string source   = "abcdefghklmopqastuvwxyz";
            const string fileName = "test1.acode";

            var fullPath = Path.Combine(GetTestFolder(), fileName);
            var encoded  = ArithmeticCoding.Encode(source);

            ArithmeticFile.Write(fullPath, encoded);
            var read    = ArithmeticFile.Read(fullPath);
            var decoded = ArithmeticCoding.Decode(read);

            Assert.AreEqual(source, decoded);
        }
        public void TestCoding256AlphabetAnd1024TextLength()
        {
            var sb = new StringBuilder(1024);

            for (int i = 0; i < 256; i++)
            {
                sb.Append((char)i);
            }

            var s = sb.ToString();

            sb.Append(s);
            sb.Append(s);
            sb.Append(s);

            var source  = sb.ToString();
            var encoded = ArithmeticCoding.Encode(source);
            var decoded = ArithmeticCoding.Decode(encoded);

            Assert.AreEqual(source, decoded);
        }
Exemple #8
0
        private void BtnSaveCode_Click(object sender, EventArgs e)
        {
            if (RtbSource.TextLength == 0)
            {
                return;
            }
            if (_sdfEncoded.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                var encoded = ArithmeticCoding.Encode(RtbSource.Text);
                ArithmeticFile.Write(_sdfEncoded.FileName, encoded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }