private Image BeginVilenkinCompress() { p = new List <int>(); ArrayUtils.Fill(p, int.Parse(p_textBox.Text), 30); Timer timer = Timer.GetInstance(); timer.Clear(); if (vilenkin == null) { timer.Start(MAIN, PREPARATION); vilenkin = new VilenkinTransform(p, int.Parse(N_textBox.Text) - 1); timer.End(MAIN, PREPARATION); } blockSize = vilenkin.GetBlockSize(); chunkSize = blockSize * 2; var originalWidth = sourceImageBox.Image.Width; var originalHeight = sourceImageBox.Image.Height; var rgbImage = new RGBImage(sourceImageBox.Image); var fittedToChunksImage = ImageUtils.FitToBlockSize(rgbImage, chunkSize); var chunks = fittedToChunksImage.ToBlockArray(chunkSize, out int widthBlocks, out int heightBlocks); var vilenkinChunks = new VilenkinChunk[chunks.Length]; var parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = 4 }; timer.Start(MAIN, TRANSFORM); var flag = Parallel.ForEach(chunks, parallelOptions, (elem, loopState, elementIndex) => { var vilenkinChunk = new VilenkinChunk(vilenkin, new Chunk(chunks[elementIndex], blockSize)); vilenkinChunk.ZeroCoeffs(zeroPercentY, zeroPercentCb, zeroPercentCr); vilenkinChunks[elementIndex] = vilenkinChunk; }); while (!flag.IsCompleted) { ; } timer.End(MAIN, TRANSFORM); foreach (VilenkinChunk chunk in vilenkinChunks) { coeffsCount += chunk.CoeffsCount(); zeroCoeffsCount += chunk.ZeroCoeffsCount(); } var listOfDecompressedImages = new YCbCrImage[vilenkinChunks.Length]; var listOfDecompressedChunks = new Chunk[vilenkinChunks.Length]; var matrix = new YCbCrImage[widthBlocks, heightBlocks]; timer.Start(MAIN, REVERSE_TRANSFORM); flag = Parallel.ForEach(vilenkinChunks, parallelOptions, (elem, loopState, i) => { listOfDecompressedChunks[i] = new Chunk(vilenkinChunks[i], vilenkin); listOfDecompressedImages[i] = YCbCrImage.FromChunk(listOfDecompressedChunks[i]); var j = i / widthBlocks; matrix[i - j * widthBlocks, j] = listOfDecompressedImages[i]; }); while (!flag.IsCompleted) { ; } timer.End(MAIN, REVERSE_TRANSFORM); timer.DisplayIntervals(); var decompressedImage = YCbCrImage.FromMatrix(matrix).ToRGBImage(originalWidth, originalHeight); return(decompressedImage.ToImage()); }
private void p_textBox_TextChanged(object sender, EventArgs e) { p = new List <int>(); ArrayUtils.Fill(p, int.Parse(p_textBox.Text), 10); vilenkin = null; }
public override string ToString() { return(ArrayUtils.ArrayToString(p, "p") + ArrayUtils.ArrayToString(m, "m")); }