Пример #1
0
        public BmpImage predicate()
        {
            var oldData = this.image.Data;

            byte[] newData = new byte[oldData.GetRealSize()];

            int width  = oldData.Width;
            int height = oldData.Height;

            Position pos = new Position();

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    //TODO: to calculate every predicated pixel value
                    pos.x = i;
                    pos.y = j;
                    newData[i * width + j] =
                        (byte)((oldData.Data[i * width + j] - PredictSinglePixel(pos)) / 2 + 128);
                }
            }

            BmpImage pImage = BmpImageAllocator.NewGrayScaleImage(width, height, newData);

            ImageFile.SaveBmpImage(pImage, savedFilePath + "//" + fileName + ".bmp");

            HuffmanCompression huffCompress = new HuffmanCompression(newData);

            huffCompress.Compress(savedFilePath + "//" + fileName + ".dat");

            return(pImage);
        }
Пример #2
0
        public BmpImage GetDCTImage()
        {
            if (Image.Data.ColorMode != BitmapColorMode.TwoFiftySixColors)
            {
                throw new NotThisColorModeException();
            }

            BmpImage result = BmpImageAllocator.NewGrayScaleImage(Image.Data.Width, Image.Data.Height);

            DCTData = new double[Image.Data.Width, Image.Data.Height];

            for (int i = 0; i < Image.Data.Width / BlockSize; i++)
            {
                for (int k = 0; k < Image.Data.Height / BlockSize; k++)
                {
                    int[,] block = new int[BlockSize, BlockSize];
                    for (int m = 0; m < BlockSize; m++)
                    {
                        for (int n = 0; n < BlockSize; n++)
                        {
                            block[m, n] = Image.Data.Get8BitDataAt(BlockSize * i + m, BlockSize * k + n);
                        }
                    }
                    double[,] dctBlock = GenerateDCTBlock(block);

                    double min = 99999999;
                    double max = -99999999;
                    for (int m = 0; m < BlockSize; m++)
                    {
                        for (int n = 0; n < BlockSize; n++)
                        {
                            if (dctBlock[m, n] > max)
                            {
                                max = dctBlock[m, n];
                            }
                            if (dctBlock[m, n] < min)
                            {
                                min = dctBlock[m, n];
                            }
                        }
                    }

                    for (int m = 0; m < BlockSize; m++)
                    {
                        for (int n = 0; n < BlockSize; n++)
                        {
                            result.Data.Set8BitDataAt(
                                BlockSize * i + m, BlockSize * k + n,
                                (byte)((dctBlock[m, n] - min) / (max - min) * 255));
                            DCTData[BlockSize * i + m, BlockSize *k + n] = dctBlock[m, n];
                        }
                    }
                }
            }

            return(result);
        }
Пример #3
0
        public BmpImage GetDCTReverseImage(double compressRatio)
        {
            if (Image.Data.ColorMode != BitmapColorMode.TwoFiftySixColors)
            {
                throw new NotThisColorModeException();
            }
            if (DCTData == null)
            {
                throw new UnauthorizedAccessException();
            }
            if (compressRatio < 1.0)
            {
                throw new ArgumentOutOfRangeException();
            }

            BmpImage result = BmpImageAllocator.NewGrayScaleImage(Image.Data.Width, Image.Data.Height);

            for (int i = 0; i < Image.Data.Width / BlockSize; i++)
            {
                for (int k = 0; k < Image.Data.Height / BlockSize; k++)
                {
                    double[,] block = new double[BlockSize, BlockSize];
                    for (int m = 0; m < BlockSize; m++)
                    {
                        for (int n = 0; n < BlockSize; n++)
                        {
                            if ((m + n > BlockSize * BlockSize / (compressRatio * compressRatio)))
                            {
                                block[m, n] = 0;
                            }
                            else
                            {
                                block[m, n] = DCTData[BlockSize * i + m, BlockSize *k + n];
                            }
                        }
                    }
                    int[,] dctReverseBlock = GenerateDCTReverseBlock(block);
                    for (int m = 0; m < BlockSize; m++)
                    {
                        for (int n = 0; n < BlockSize; n++)
                        {
                            result.Data.Set8BitDataAt(
                                BlockSize * i + m, BlockSize * k + n,
                                (byte)dctReverseBlock[m, n]);
                        }
                    }
                }
            }

            return(result);
        }