Esempio n. 1
0
        public static void TestDCT_Quantize()
        {
            Dct dct = new Dct();

            print("DCT Test");
            var d = dct.Go(testdata);

            print("Quantized dct");
            Quantizer.QuantizeLuminance(ref d);
            d.PrintArray();
            print("Quantized Inverse");
            Quantizer.InverseQuantizeLuminance(ref d);
            print("Dct Inverse");
            dct.GoBack(d).PrintArray();
        }
Esempio n. 2
0
        public static void TestWhole()
        {
            // down sample
            List <List <double> > data = new List <List <double> >();

            for (int i = 0; i < bigtestdata.GetLength(0); i++)
            {
                if (i % 2 != 0)
                {
                    continue;
                }
                List <double> row = new List <double>();
                for (int j = 0; j < bigtestdata.GetLength(1); j++)
                {
                    if (j % 2 != 0)
                    {
                        continue;
                    }
                    row.Add(bigtestdata[i, j]);
                }
                data.Add(row);
            }
            double[,] narr = new double[8, 8];
            for (int i = 0; i < data.Count; i++)
            {
                for (int j = 0; j < data[i].Count; j++)
                {
                    narr[i, j] = data[i][j];
                }
            }
            print("Down Sampled");
            narr.PrintArray();

            Dct dct     = new Dct();
            var dctdata = dct.Go(narr);

            print("dct go");
            dctdata.PrintArray();

            Quantizer.QuantizeLuminance(ref dctdata);
            print("quantized");
            dctdata.PrintArray();

            var            zagged  = ZigZag.Run(dctdata);
            var            bzagged = zagged.Select(x => (sbyte)x).ToArray();
            List <sbyte[]> zaglist = new List <sbyte[]>()
            {
                bzagged
            };

            sbyte[] rled = Rle.BetterEncode(zaglist);

            // reversing
            var unrle = Rle.DecodeRle(rled);
            var unzag = ZigZag.Inverse(unrle[0].Select(x => (int)x).ToArray());

            Quantizer.InverseQuantizeLuminance(ref unzag);
            var idct = dct.GoBack(unzag);

            idct.PrintArray();
        }