示例#1
0
        public static unsafe SKPixmap WaveletUpscale(this SKImage image, Wavelet wavelet)
        {
            int width          = image.Width;
            int height         = image.Height;
            int upscaledWidth  = width * 2;
            int upscaledHeight = height * 2;

            float[,] y  = new float[upscaledWidth, upscaledWidth];
            float[,] cb = new float[upscaledWidth, upscaledWidth];
            float[,] cr = new float[upscaledWidth, upscaledWidth];
            float[,] a  = new float[upscaledWidth, upscaledWidth];

            image.ToYCbCrAArrays(y, cb, cr, a);

            WaveletTransform2D wavelet2D;
            WaveletTransform2D upscaledWavelet2D;

            switch (wavelet)
            {
            case Wavelet.Haar:
                wavelet2D         = new HaarWavelet2D(width, height);
                upscaledWavelet2D = new HaarWavelet2D(upscaledWidth, upscaledHeight);
                break;

            case Wavelet.Biorthogonal53:
            default:
                wavelet2D         = new Biorthogonal53Wavelet2D(width, height);
                upscaledWavelet2D = new Biorthogonal53Wavelet2D(upscaledWidth, upscaledHeight);
                break;
            }

            wavelet2D.Transform2D(y);
            wavelet2D.Transform2D(cb);
            wavelet2D.Transform2D(cr);
            wavelet2D.Transform2D(a);

            upscaledWavelet2D.ReverseTransform2D(y);
            upscaledWavelet2D.ReverseTransform2D(cb);
            upscaledWavelet2D.ReverseTransform2D(cr);
            upscaledWavelet2D.ReverseTransform2D(a);

            for (int row = 0; row < upscaledHeight; row++)
            {
                for (int col = 0; col < upscaledWidth; col++)
                {
                    y[col, row]  *= 4.0f;
                    cb[col, row] *= 4.0f;
                    cr[col, row] *= 4.0f;
                    a[col, row]  *= 4.0f;
                }
            }

            SKImageInfo info   = new SKImageInfo(upscaledWidth, upscaledHeight, SKColorType.Rgba8888);
            SKImage     output = SKImage.Create(info);

            SKPixmap pixmap = output.ToRGBAPixmap(y, cb, cr, a);

            return(pixmap);
        }