Пример #1
0
        public int chromaSubsampling()
        {
            /* Detect Chroma Subsampling
             * Set General.chr:
             * 0--> 4:4:4
             * 1--> 4:4:0
             * 2--> 4:2:2
             * 3--> 4:2:0
             */

            int mcu = mcuStructure();

            Console.WriteLine("MCU: " + mcu);
            switch (mcu)
            {
            case 0:
                Global.yccList = blockListWith1Y;
                Global.chr     = 0;
                Global.rgbList = Dequantizer.ycc2rgbBlockList(Global.yccList, 0);
                break;

            case 1:
                Global.yccList = blockListWith2Y;
                Global.chr     = layout();
                // if chr==1 General.rgbList is already setted in layout() method
                break;

            default:
                Global.yccList = blockListWith4Y;
                Global.chr     = 3;
                Global.rgbList = Dequantizer.ycc2rgbBlockList(Global.yccList, 3);
                break;
            }
            return(mcu);
        }
Пример #2
0
        int layout()
        {
            // build rgbList as 4:4:0
            List <double[][]>[] verList = Dequantizer.ycc2rgbBlockList(Global.yccList, 1);
            // build rgbList as 4:2:2
            List <double[][]>[] horList = Dequantizer.ycc2rgbBlockList(Global.yccList, 2);

            List <double[]> verDiff = new List <double[]>(); // 0->tbDiff, 1->lrDiff
            List <double[]> horDiff = new List <double[]>(); // 0->tbDiff, 1->lrDiff

            for (int i = 0; i < verList[0].Count; i += 2)
            {
                verDiff.Add(borderDiff(new double[][][] { verList[0][i], verList[1][i], verList[2][i] }, new double[][][] { verList[0][i + 1], verList[1][i + 1], verList[2][i + 1] }));
            }

            for (int i = 0; i < horList[0].Count; i += 2)
            {
                horDiff.Add(borderDiff(new double[][][] { horList[0][i], horList[1][i], horList[2][i] }, new double[][][] { horList[0][i + 1], horList[1][i + 1], horList[2][i + 1] }));
            }


            if ((verDiff.Average(i => i[0]) < horDiff.Average(i => i[1])) && (verDiff.Average(i => i[1]) > horDiff.Average(i => i[0])))
            {
                Global.rgbList = verList;
                return(1);
            }

            Global.rgbList = horList;
            return(2);
        }