Exemplo n.º 1
0
        private static CalculationQuantization CalculateQuantization(CalculationDCT calculationDCT)
        {
            var arrayHeight = calculationDCT.ArrayY.GetLength(0);
            var arrayWidth  = calculationDCT.ArrayY.GetLength(1);

            int[,] arrayY  = new int[arrayHeight, arrayWidth];
            int[,] arrayCb = new int[arrayHeight, arrayWidth];
            int[,] arrayCr = new int[arrayHeight, arrayWidth];

            for (var i = 0; i < arrayHeight; i++)
            {
                for (var j = 0; j < arrayWidth; j++)
                {
                    arrayY[i, j]  = (int)Math.Round((calculationDCT.ArrayY[i, j] / K1Table[i, j]));
                    arrayCb[i, j] = (int)Math.Round((calculationDCT.ArrayCb[i, j] / K2Table[i, j]));
                    arrayCr[i, j] = (int)Math.Round((calculationDCT.ArrayCr[i, j] / K2Table[i, j]));
                }
            }
            CalculationQuantization calculatedQuantization = new CalculationQuantization(arrayY, arrayCb, arrayCr);

            return(calculatedQuantization);
        }
Exemplo n.º 2
0
        private static CalculationDCT CalculateDCT(Pixel[,] array)
        {
            var arrayHeight = array.GetLength(0);
            var arrayWidth  = array.GetLength(1);

            double[,] arrayY  = new double[arrayHeight, arrayWidth];
            double[,] arrayCb = new double[arrayHeight, arrayWidth];
            double[,] arrayCr = new double[arrayHeight, arrayWidth];
            double cu;
            double cv;
            double dctY;
            double dctCb;
            double dctCr;
            double summY;
            double summCb;
            double summCr;

            for (var u = 0; u < arrayHeight; ++u)
            {
                for (var v = 0; v < arrayWidth; ++v)
                {
                    if (u == 0)
                    {
                        cu = 1.0 / Math.Sqrt(2.0);
                    }
                    else
                    {
                        cu = 1.0;
                    }
                    if (v == 0)
                    {
                        cv = 1.0 / Math.Sqrt(2.0);
                    }
                    else
                    {
                        cv = 1.0;
                    }
                    summY  = 0;
                    summCb = 0;
                    summCr = 0;
                    for (var i = 0; i < arrayHeight; i++)
                    {
                        for (var j = 0; j < arrayWidth; j++)
                        {
                            dctY    = array[i, j].V1 * Math.Cos((2 * i + 1) * u * Math.PI / 16.0) * Math.Cos((2 * j + 1) * v * Math.PI / 16.0);
                            dctCb   = array[i, j].V2 * Math.Cos((2 * i + 1) * u * Math.PI / 16.0) * Math.Cos((2 * j + 1) * v * Math.PI / 16.0);
                            dctCr   = array[i, j].V3 * Math.Cos((2 * i + 1) * u * Math.PI / 16.0) * Math.Cos((2 * j + 1) * v * Math.PI / 16.0);
                            summY  += dctY;
                            summCb += dctCb;
                            summCr += dctCr;
                        }
                    }
                    arrayY[u, v]  = 0.25 * cu * cv * summY;
                    arrayCb[u, v] = 0.25 * cu * cv * summCb;
                    arrayCr[u, v] = 0.25 * cu * cv * summCr;
                }
            }
            CalculationDCT calculatedDCT = new CalculationDCT(arrayY, arrayCb, arrayCr);

            return(calculatedDCT);
        }