Exemple #1
0
        public static void Expand(CompressionHeader *header, VoidPtr dstAddr, int dstLen)
        {
            switch (header->Algorithm)
            {
            case CompressionType.LZ77:
            case CompressionType.ExtendedLZ77:
            {
                LZ77.Expand(header, dstAddr, dstLen);
                break;
            }

            case CompressionType.RunLength:
            {
                RunLength.Expand(header, dstAddr, dstLen);
                break;
            }

            //case CompressionType.Huffman: { Huffman.Expand(header, dstAddr, dstLen); break; }
            //case CompressionType.Differential: { Differential.Expand(header, dstAddr, dstLen); break; }
            default:
                throw new InvalidCompressionException("Unknown compression type.");
            }
        }
Exemple #2
0
        public static unsafe void Compact(CompressionType type, VoidPtr srcAddr, int srcLen, Stream outStream,
                                          ResourceNode r)
        {
            switch (type)
            {
            case CompressionType.LZ77:
            {
                LZ77.Compact(srcAddr, srcLen, outStream, r, false);
                break;
            }

            case CompressionType.ExtendedLZ77:
            {
                LZ77.Compact(srcAddr, srcLen, outStream, r, true);
                break;
            }

            case CompressionType.RunLength:
            {
                RunLength.Compact(srcAddr, srcLen, outStream, r);
                break;
            }

            case CompressionType.RunLengthYAZ0:
            {
                RunLength.CompactYAZ0(srcAddr, srcLen, outStream, r);
                break;
            }

            case CompressionType.RunLengthYAY0:
            {
                RunLength.CompactYAY0(srcAddr, srcLen, outStream, r);
                break;
            }
            }
        }
        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();
        }
Exemple #4
0
 public static void Expand(YAY0 *header, VoidPtr dstAddr, int dstLen)
 {
     RunLength.ExpandYAY0(header, dstAddr, dstLen);
 }