private void recompressToolStripMenuItem_Click(object sender, EventArgs e) { // Set bit depth correctly var bitDepth = ImageCompression.ColorModel.RGB.ColorDepth.TwentyFour; if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.EightBit)) { bitDepth = ImageCompression.ColorModel.RGB.ColorDepth.Eight; } else if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.FifteenBit)) { bitDepth = ImageCompression.ColorModel.RGB.ColorDepth.Fifteen; } else if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.EighteenBit)) { bitDepth = ImageCompression.ColorModel.RGB.ColorDepth.Eighteen; } else if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.TwentyFourBit)) { bitDepth = ImageCompression.ColorModel.RGB.ColorDepth.TwentyFour; } // Re-Load the modified data this.modifiedData.data = this.originalImage.GetPixelMatrix(bitDepth); ImageCompression.Interfaces.IEncodable[] data = this.modifiedData.data.Flatten(); // If huffman is enabled if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.Huffman)) { var huffmanData = Huffman <ImageCompression.Interfaces.IEncodable> .Encode(data); } // If run length is enabled if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.RunLength)) { data = RunLength.Encode <ImageCompression.Interfaces.IEncodable>(data); } // If LZ77 is enabled if (this.compressionFlags.FlagIsSet((byte)CompressionFlags.LZ77)) { var encodedData = LZ77.Encode(data, 255, 255); data = encodedData.ToArray <ImageCompression.Interfaces.IEncodable>(); } // Pack the bytes this.compressedForm = ImageCompression.Helpers.BytePacker.Pack(data.ToList()); // Update compressed size this.compressedSizeLabelBytes.Text = ((this.compressedForm.Length + this.compressionFlags) / 1024) + " KB"; // Update compression radio this.compressionRatio.Text = this.CalculateCompressionRatio( int.Parse(this.originalSizeLabelBytes.Text.Substring(0, this.originalSizeLabelBytes.Text.Length - 3)), int.Parse(this.compressedSizeLabelBytes.Text.Substring(0, this.originalSizeLabelBytes.Text.Length - 3))); // Update MSE this.meanSquaredError.Text = this.originalImage.MeanSquaredError(this.modifiedData.data).ToString(); // Update the preview tab with the preview data if (this.compressedPictureBox.Image != null) { this.compressedPictureBox.Image.Dispose(); this.compressedImage.Dispose(); } // Save the modified data as a temporary image var modifiedBitmap = this.modifiedData.GetBitmap(); modifiedBitmap.Save(@"D:\GitHub\SE3IA11-Image-Analysis\ImageCompression\TestImage\Output\temp.bmp", System.Drawing.Imaging.ImageFormat.Bmp); this.compressedImage = new StandardImage(new Bitmap(@"D:\GitHub\SE3IA11-Image-Analysis\ImageCompression\TestImage\Output\temp.bmp")); this.compressedPictureBox.Image = this.compressedImage.GetBitmap(); }