private void buttonStart_Click(object sender, EventArgs e) { invertFormAcces(); panelDestination.BackgroundImage = null; Refresh(); if (InputFile != null) { int.TryParse(textBoxThreshold.Text, out int threshold); int.TryParse(comboBoxDictionarySize.GetItemText(comboBoxDictionarySize.SelectedItem), out int dictionarySize); AvqCompression = new AVQ(InputFile); originalImage = AvqCompression.StartCompression(threshold, dictionarySize); panelDestination.BackgroundImage = originalImage.GetBitMap(); } else { MessageBox.Show("You need to choose an image!"); } invertFormAcces(); }
private void buttonStart_Click(object sender, EventArgs e) { invertFormAcces(); panelDestination.BackgroundImage = null; if (InputFile != null) { bool drawBorder = checkBoxDrawBorder.Checked; bool CompressedFileFormat = checkBoxCompressedFileFormat.Checked; int.TryParse(textBoxThreshold.Text, out int threshold); int.TryParse(textBoxDictionarySize.Text, out int dictionarySize); AvqCompression = new AVQ(InputFile); originalImage = AvqCompression.StartCompression(threshold, dictionarySize, drawBorder, CompressedFileFormat); panelDestination.BackgroundImage = originalImage.GetBitMap(); } else { MessageBox.Show("You need to choose an image!"); } invertFormAcces(); }
private void buttonDecode_Click(object sender, EventArgs e) { invertFormAcces(); openFileDialog.Filter = "AVQ Files(*.AVQ)|*.AVQ|All files (*.*)|*.*"; openFileDialog.ShowDialog(); InputFileComp = openFileDialog.FileName; if (InputFileComp != null) { AvqCompression = new AVQ(); originalImage = AvqCompression.StartDeCompression(InputFileComp); Bitmap bitmap = originalImage.GetBitMap(); string[] output = InputFileComp.Split('.'); bitmap.Save(output[0] + "-decoded.bmp"); } else { MessageBox.Show("You need to choose an image!"); } MessageBox.Show("Image decompressed!"); invertFormAcces(); }
public FastImage StartCompression(int th, int dictionarySize) { DateTime startTime = DateTime.Now; indexesList = new List <int>(); Threshold = th; MaxDictionaryLength = dictionarySize; BlocPainFrequency = (int)1.0 * 100000 / MaxDictionaryLength; originalImage.Lock(); workImage.Lock(); buildGP(); int ct = 0; while (poolGrowingPoints.Count != 0) { ct++; if (ct == BlocPainFrequency) { ct = 0; Program.form.updatePanelBlock(bitmapBlocks.GetBitMap()); //Thread.Sleep(50); } int widthStep, heightStep; //Position growingPoint = UpdateGPPool(); Position growingPoint = poolGrowingPoints[0]; int i = growingPoint.X; int j = growingPoint.Y; int index; if (i == 0 || j == 0) { index = originalImage.GetPixel(i, j); } else { index = SearchBlock(growingPoint); } indexesList.Add(index); if (index < 256) { workImage.SetPixel(i, j, index); imageBitmap[i, j] = true; widthStep = 1; heightStep = 1; } else { Block findedBlock = dictionary.LastOrDefault(x => x.Value == index).Key; ReplaceBlock(findedBlock, i, j); widthStep = findedBlock.Width; heightStep = findedBlock.Height; numberBlocksFinded++; } // TryAddGrowingPoint(growingPoint, widthStep, heightStep); //TryAddGrowingPoint(new Position(i + widthStep, j)); if (i != 0 && j != 0) { UpdateDictionary(growingPoint, index); } UpdateGPPool(); } Program.form.updatePanelBlock(bitmapBlocks.GetBitMap()); WriteInFile(indexesList); Console.WriteLine("NumberBlocksFinded = {0} numberErrorPX = {1}", numberBlocksFinded, numberErrorPX); workImage.Unlock(); originalImage.Unlock(); DateTime stopTime = DateTime.Now; Console.WriteLine(stopTime - startTime); return(workImage); }
public FastImage StartCompression(int th, int dictionarySize, bool drawBorder, bool CompressedFileFormat) { DateTime startTime = DateTime.Now; indexesList = new List <int>(); Threshold = th; MaxDictionaryLength = dictionarySize; dictionary = new Dictionary <Block, int>(MaxDictionaryLength); originalImage.Lock(); workImage.Lock(); int ct = 0; while (poolGrowingPoints.Count != 0) { ct++; if (ct == 700) { ct = 0; Program.form.updatePanelBlock(bitmapBlocks.GetBitMap()); Thread.Sleep(50); } int widthStep, heightStep; Position growingPoint = GetNextGrowingPoint(); int i = growingPoint.X; int j = growingPoint.Y; int index; if (i == 0 || j == 0) { index = originalImage.GetPixel(i, j); } else { index = SearchBlock(growingPoint); } indexesList.Add(index); if (index < 256) { workImage.SetPixel(i, j, index); imageBitmap[i, j] = true; widthStep = 1; heightStep = 1; } else { Block findedBlock = dictionary.LastOrDefault(x => x.Value == index).Key; ReplaceBlock(findedBlock, i, j); widthStep = findedBlock.Width; heightStep = findedBlock.Height; numberBlocksFinded++; if (drawBorder) { DrawBlockBorder(i, j, findedBlock); } } TryAddGrowingPoint(new Position(i, j + heightStep)); TryAddGrowingPoint(new Position(i + widthStep, j)); if (i != 0 && j != 0) { UpdateDictionary(growingPoint, index); } } WriteInFile(indexesList, CompressedFileFormat); Console.WriteLine("NumberBlocksFinded = {0} numberErrorPX = {1}", numberBlocksFinded, numberErrorPX); workImage.Unlock(); originalImage.Unlock(); DateTime stopTime = DateTime.Now; Console.WriteLine(stopTime - startTime); return(workImage); }
public SimulationResult StartSimulation(int th, int dictionarySize) { indexesList = new List <int>(); Threshold = th; MaxDictionaryLength = dictionarySize; // BlocPainFrequency = int.MaxValue; originalImage.Lock(); workImage.Lock(); DateTime startTime = DateTime.Now; buildGP(); while (poolGrowingPoints.Count != 0) { int widthStep, heightStep; //Position growingPoint = UpdateGPPool(); Position growingPoint = poolGrowingPoints[0]; int i = growingPoint.X; int j = growingPoint.Y; int index; if (i == 0 || j == 0) { index = originalImage.GetPixel(i, j); } else { index = SearchBlock(growingPoint); } indexesList.Add(index); if (index < 256) { workImage.SetPixel(i, j, index); imageBitmap[i, j] = true; widthStep = 1; heightStep = 1; } else { Block findedBlock = dictionary.LastOrDefault(x => x.Value == index).Key; ReplaceBlock(findedBlock, i, j); widthStep = findedBlock.Width; heightStep = findedBlock.Height; numberBlocksFinded++; } // TryAddGrowingPoint(growingPoint, widthStep, heightStep); //TryAddGrowingPoint(new Position(i + widthStep, j)); if (i != 0 && j != 0) { UpdateDictionary(growingPoint, index); } UpdateGPPool(); } Program.form.updatePanelBlock(bitmapBlocks.GetBitMap()); DateTime finishTime = DateTime.Now; string compressionTime = (finishTime - startTime).TotalSeconds.ToString(); WriteInFile(indexesList); Console.WriteLine("NumberBlocksFinded = {0} numberErrorPX = {1}", numberBlocksFinded, numberErrorPX); workImage.Unlock(); originalImage.Unlock(); //--- originalImageValid = false; dictionary = new Dictionary <Block, int>(); dictionaryBackup = new List <Block>(); currentDictionaryLength = 256; indexesList = new List <int>(); ReadFromFile(CompressedFile); Bitmap blackImageBitmap = new Bitmap(imageWidth, imageHeight, PixelFormat.Format24bppRgb); workImage = new FastImage(blackImageBitmap); workImage.Lock(); startTime = DateTime.Now; buildGP(); while (poolGrowingPoints.Count != 0) { int widthStep, heightStep; //Position growingPoint = UpdateGPPool(); Position growingPoint = poolGrowingPoints[0]; int i = growingPoint.X; int j = growingPoint.Y; int index = indexesList[0]; indexesList.RemoveAt(0); if (index < 256) { workImage.SetPixel(i, j, index); imageBitmap[i, j] = true; widthStep = 1; heightStep = 1; } else { Block findedBlock = dictionary.LastOrDefault(x => x.Value == index).Key; if (findedBlock == null) { Console.WriteLine("**"); foreach (Block block in dictionaryBackup) { if (block.Index == index) { findedBlock = block; } } } ReplaceBlock(findedBlock, i, j); widthStep = findedBlock.Width; heightStep = findedBlock.Height; numberBlocksFinded++; } if (i != 0 && j != 0) { UpdateDictionary(growingPoint, index); } UpdateGPPool(); } //Console.WriteLine("NumberBlocksFinded = {0} numberErrorPX = {1}", numberBlocksFinded, numberErrorPX); finishTime = DateTime.Now; string decompressionTime = (finishTime - startTime).TotalSeconds.ToString(); // workImage.Unlock(); //--- Bitmap bitmap = workImage.GetBitMap(); string[] output = CompressedFile.Split('.'); DecompressedFile = output[0] + "-decoded.bmp"; bitmap.Save(DecompressedFile); float psnr = CompareImages(originalImage, workImage); long compressedFileSize = new FileInfo(CompressedFile).Length; long decompressedFileSize = new FileInfo(DecompressedFile).Length; return(new SimulationResult(MaxDictionaryLength, Threshold, compressionTime, decompressionTime, numberBlocksFinded, compressedFileSize, decompressedFileSize, psnr)); }