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 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 FastImage newBlackImage(Bitmap imageBitmap) { FastImage newImg = new FastImage(imageBitmap); newImg.Lock(); for (int i = 0; i < newImg.Width; i++) { for (int j = 0; j < newImg.Height; j++) { newImg.SetPixel(i, j, emptyPixel); } } newImg.Unlock(); return(newImg); }
public AVQ(string sSourceFileName) { originalImageValid = true; originalImage = new FastImage(new Bitmap(sSourceFileName)); imageBitmap = new bool[originalImage.Width, originalImage.Height]; Bitmap blackImageBitmap = new Bitmap(originalImage.Width, originalImage.Height, PixelFormat.Format24bppRgb); Bitmap blackImageBitmap2 = new Bitmap(originalImage.Width, originalImage.Height, PixelFormat.Format24bppRgb); workImage = new FastImage(blackImageBitmap); bitmapBlocks = new FastImage(blackImageBitmap2); dictionary = new Dictionary <Block, int>(); dictionaryBackup = new List <Block>(); currentDictionaryLength = 256; //Position firstGrowingPoint = new Position(0, 0); //poolGrowingPoints.Add(firstGrowingPoint); }
private float CompareImages(FastImage originalImage, FastImage decompressedImage) { float diff = 0; for (int y = 0; y < originalImage.Height; y++) { for (int x = 0; x < originalImage.Width; x++) { int pixel1 = originalImage.GetPixel(x, y); int pixel2 = decompressedImage.GetPixel(x, y); originalImage.GetPixel(x, y); decompressedImage.GetPixel(x, y); diff += Math.Abs(pixel1 - pixel2); } } //Console.WriteLine("diff: {0} %", 100 * (diff / 255) / (img1.Width * img1.Height * 3)); return(100 * (diff / 255) / (originalImage.Width * originalImage.Height * 3)); }
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 StartDeCompression(string inputFile) { ReadFromFile(inputFile); Bitmap blackImageBitmap = new Bitmap(imageWidth, imageHeight, PixelFormat.Format24bppRgb); workImage = new FastImage(blackImageBitmap); workImage.Lock(); 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++; } //TryAddGrowingPoint(growingPoint, widthStep, heightStep); //TryAddGrowingPoint(new Position(i + widthStep, j)); if (i != 0 && j != 0) { UpdateDictionary(growingPoint, index); } UpdateGPPool(); } Console.WriteLine("NumberBlocksFinded = {0} numberErrorPX = {1}", numberBlocksFinded, numberErrorPX); workImage.Unlock(); 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)); }