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 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 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)); }