private void Decompress_Click(object sender, EventArgs e)
        {
            Decompress.Enabled = false;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Data files (*.dat)|*.dat";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FilePath = openFileDialog1.FileName.Remove((openFileDialog1.FileName.Length - 4), 4);
                FileStream   rs   = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                Huffman_Tree tree = new Huffman_Tree();
                tree.FrequencyList = (List <Tuple <Dictionary <int, uint>, BitArray> >)formatter.Deserialize(rs);
                tree.BuildTree();
                List <bool> st = new List <bool>();
                tree.Encode(tree.Rroot, st, 'R');
                st = new List <bool>();
                tree.Encode(tree.Groot, st, 'G');
                st = new List <bool>();
                tree.Encode(tree.Broot, st, 'B');
                img = tree.Decompress();
                pictureBox2.Image = img;
                txtWidth.Text     = tree.FrequencyList[0].Item1[-100].ToString();
                txtHeight.Text    = tree.FrequencyList[0].Item1[-101].ToString();
                TAP.Text          = tree.FrequencyList[0].Item1[-102].ToString();
                SEED.Text         = tree.FrequencyList[0].Item1[-103].ToString();
                rs.Close();
                img.Save(FilePath + "new.bmp");
                MessageBox.Show("Decompressed Image has been Saved.", "Decompression Sucessful", MessageBoxButtons.OK);
            }
            Decompress.Enabled = true;
        }
Exemple #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            if (op.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = op.FileName;

                // create instance of video reader
                VideoFileReader reader = new VideoFileReader();
                // open video file
                reader.Open(fileName);
                // read 100 video frames out of it
                for (int i = 0; i <= 1312; i++)
                {
                    Bitmap videoFrame = reader.ReadVideoFrame();
                    Program.images_name[Program.index_vedio] = "C:\\Users\\JOE\\Desktop\\[TEMPLATE] ImageEncryptCompress\\Take Pictures\\" + i.ToString();
                    Program.index_vedio++;
                    videoFrame.Save(@"C:\\Users\\JOE\\Desktop\\[TEMPLATE] ImageEncryptCompress\Take Pictures\\" + i.ToString() + ".bmp");
                    // dispose the frame when it is no longer required
                    videoFrame.Dispose();
                }
                reader.Close();
            }

            Huffman_Tree tree = new Huffman_Tree();

            Huffman_Tree.Comp   = new FileStream("Compressed_Picture.bin", FileMode.Append);
            Huffman_Tree.Comp_r = new BinaryWriter(Huffman_Tree.Comp);
            Huffman_Tree.Comp_r.Write(Program.index_vedio);
            Huffman_Tree.Comp_r.Close();
            Huffman_Tree.Comp.Close();
            for (int i = 0; i < Program.index_vedio; i++)
            {
                Huffman_Tree.Comp   = new FileStream("Compressed_Picture.bin", FileMode.Append);
                Huffman_Tree.Comp_r = new BinaryWriter(Huffman_Tree.Comp);
                string OpenedFilePath = Program.images_name[i];
                Program.OriginalImage = ImageOperations.OpenImage(OpenedFilePath + ".bmp");
                Width  = ImageOperations.GetWidth(Program.OriginalImage);
                Height = ImageOperations.GetHeight(Program.OriginalImage);
                tree.FreqMatrix(Program.OriginalImage);
                Compress c = new Compress();
                c.convert_Image_to_binary();
            }
            MessageBox.Show("DONE");
        }
Exemple #3
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Huffman_Tree tree = new Huffman_Tree();

            Huffman_Tree.Comp   = new FileStream("Compressed_Picture.bin", FileMode.Append);
            Huffman_Tree.Comp_r = new BinaryWriter(Huffman_Tree.Comp);
            tree.FreqMatrix(Program.OriginalImage);
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            Compress.elapsedTime_Const = String.Format
                                             ("{0:00}:{1:00}:{2:00}.{3:00}",
                                             ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
            CompressAndDecompress Opform = new CompressAndDecompress();

            Opform.Show();
        }
        private void Compression_Click(object sender, EventArgs e)
        {
            Compression.Enabled = false;
            Huffman_Tree tree = new Huffman_Tree(img);

            tree.BuildTree();
            List <bool> st = new List <bool>();

            tree.Encode(tree.Rroot, st, 'R');
            st = new List <bool>();
            tree.Encode(tree.Groot, st, 'G');
            st = new List <bool>();
            tree.Encode(tree.Broot, st, 'B');
            CompressionOutput(tree, FilePath);
            tree.Compress(img, FilePath);
            FileStream fs = new FileStream(FilePath + ".dat", FileMode.Create, FileAccess.Write);

            tree.FrequencyList[0].Item1.Add(-102, UInt32.Parse(TAP.Text));
            tree.FrequencyList[0].Item1.Add(-103, UInt32.Parse(SEED.Text));
            formatter.Serialize(fs, tree.FrequencyList);
            fs.Close();
            Compression.Enabled = true;
            MessageBox.Show("Compressed Image has been Saved.", "Compression Sucessful", MessageBoxButtons.OK);
        }
        private void CompressionOutput(Huffman_Tree tree, string path)
        {
            long         TotalBR = 0, TotalBG = 0, TotalBB = 0;
            StreamWriter sw = new StreamWriter(path + ".txt");

            sw.Write("Color\tFrequency\t\tHuffmanCode\t\t\t\tTotal Bits\n-Red-\n");
            foreach (var x in tree.RedCodeTable)
            {
                sw.Write(x.Key + "\t\t\t" + tree.RFrequencies[x.Key] + "\t\t\t");
                foreach (var i in x.Value)
                {
                    if (i == false)
                    {
                        sw.Write(0);
                    }
                    else
                    {
                        sw.Write(1);
                    }
                }
                sw.Write("\t\t\t\t" + tree.RFrequencies[x.Key] * x.Value.Count + "\n");
                TotalBR += tree.RFrequencies[x.Key] * x.Value.Count;
            }
            sw.Write("\nTotal Bits = " + TotalBR + "\n-------------------------------------------------------------------------------------------------------------\n");
            sw.Write("Color\tFrequency\t\tHuffmanCode\t\t\t\tTotal Bits\n-Green-\n");
            foreach (var x in tree.GreenCodeTable)
            {
                sw.Write(x.Key + "\t\t\t" + tree.GFrequencies[x.Key] + "\t\t\t");
                foreach (var i in x.Value)
                {
                    if (i == false)
                    {
                        sw.Write(0);
                    }
                    else
                    {
                        sw.Write(1);
                    }
                }
                sw.Write("\t\t\t\t" + tree.GFrequencies[x.Key] * x.Value.Count + "\n");
                TotalBG += tree.GFrequencies[x.Key] * x.Value.Count;
            }
            sw.Write("\nTotal Bits = " + TotalBG + "\n-------------------------------------------------------------------------------------------------------------\n");
            sw.Write("Color\tFrequency\t\tHuffmanCode\t\t\t\tTotal Bits\n-Blue-\n");
            foreach (var x in tree.BlueCodeTable)
            {
                sw.Write(x.Key + "\t\t\t" + tree.BFrequencies[x.Key] + "\t\t\t");
                foreach (var i in x.Value)
                {
                    if (i == false)
                    {
                        sw.Write(0);
                    }
                    else
                    {
                        sw.Write(1);
                    }
                }
                sw.Write("\t\t\t\t" + tree.BFrequencies[x.Key] * x.Value.Count + "\n");
                TotalBB += tree.BFrequencies[x.Key] * x.Value.Count;
            }
            sw.Write("\nTotal Bits = " + TotalBB + "\n-------------------------------------------------------------------------------------------------------------\n");
            sw.Write("Compression Output\n" + (double)(TotalBR + TotalBG + TotalBB) / 8 + "Bytes");
            sw.Close();
        }