BitMiracle.LibJpeg.Classic.Internal.jpeg_forward_dct.start_pass C# (CSharp) Method

start_pass() public method

Initialize for a processing pass. Verify that all referenced Q-tables are present, and set up the divisor table for each one. In the current implementation, DCT of all components is done during the first pass, even if only some components will be output in the first scan. Hence all components should be examined here.
public start_pass ( ) : void
return void
        public virtual void start_pass()
        {
            J_DCT_METHOD method = 0;
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                /* Select the proper DCT routine for this component's scaling */
                jpeg_component_info compptr = m_cinfo.Component_info[ci];
                switch ((compptr.DCT_h_scaled_size << 8) + compptr.DCT_v_scaled_size)
                {
                    case ((1 << 8) + 1):
                        do_dct[ci] = jpeg_fdct_1x1;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((2 << 8) + 2):
                        do_dct[ci] = jpeg_fdct_2x2;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((3 << 8) + 3):
                        do_dct[ci] = jpeg_fdct_3x3;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((4 << 8) + 4):
                        do_dct[ci] = jpeg_fdct_4x4;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((5 << 8) + 5):
                        do_dct[ci] = jpeg_fdct_5x5;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((6 << 8) + 6):
                        do_dct[ci] = jpeg_fdct_6x6;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((7 << 8) + 7):
                        do_dct[ci] = jpeg_fdct_7x7;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((9 << 8) + 9):
                        do_dct[ci] = jpeg_fdct_9x9;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((10 << 8) + 10):
                        do_dct[ci] = jpeg_fdct_10x10;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((11 << 8) + 11):
                        do_dct[ci] = jpeg_fdct_11x11;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((12 << 8) + 12):
                        do_dct[ci] = jpeg_fdct_12x12;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((13 << 8) + 13):
                        do_dct[ci] = jpeg_fdct_13x13;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((14 << 8) + 14):
                        do_dct[ci] = jpeg_fdct_14x14;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((15 << 8) + 15):
                        do_dct[ci] = jpeg_fdct_15x15;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((16 << 8) + 16):
                        do_dct[ci] = jpeg_fdct_16x16;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((16 << 8) + 8):
                        do_dct[ci] = jpeg_fdct_16x8;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((14 << 8) + 7):
                        do_dct[ci] = jpeg_fdct_14x7;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((12 << 8) + 6):
                        do_dct[ci] = jpeg_fdct_12x6;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((10 << 8) + 5):
                        do_dct[ci] = jpeg_fdct_10x5;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((8 << 8) + 4):
                        do_dct[ci] = jpeg_fdct_8x4;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((6 << 8) + 3):
                        do_dct[ci] = jpeg_fdct_6x3;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((4 << 8) + 2):
                        do_dct[ci] = jpeg_fdct_4x2;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((2 << 8) + 1):
                        do_dct[ci] = jpeg_fdct_2x1;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((8 << 8) + 16):
                        do_dct[ci] = jpeg_fdct_8x16;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((7 << 8) + 14):
                        do_dct[ci] = jpeg_fdct_7x14;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((6 << 8) + 12):
                        do_dct[ci] = jpeg_fdct_6x12;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((5 << 8) + 10):
                        do_dct[ci] = jpeg_fdct_5x10;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((4 << 8) + 8):
                        do_dct[ci] = jpeg_fdct_4x8;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((3 << 8) + 6):
                        do_dct[ci] = jpeg_fdct_3x6;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((2 << 8) + 4):
                        do_dct[ci] = jpeg_fdct_2x4;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((1 << 8) + 2):
                        do_dct[ci] = jpeg_fdct_1x2;
                        method = J_DCT_METHOD.JDCT_ISLOW;    /* jfdctint uses islow-style table */
                        break;
                    case ((JpegConstants.DCTSIZE << 8) + JpegConstants.DCTSIZE):
                        switch (m_cinfo.m_dct_method)
                        {
                            case J_DCT_METHOD.JDCT_ISLOW:
                                do_dct[ci] = jpeg_fdct_islow;
                                method = J_DCT_METHOD.JDCT_ISLOW;
                                break;
                            case J_DCT_METHOD.JDCT_IFAST:
                                do_dct[ci] = jpeg_fdct_ifast;
                                method = J_DCT_METHOD.JDCT_IFAST;
                                break;
                            case J_DCT_METHOD.JDCT_FLOAT:
                                do_float_dct[ci] = jpeg_fdct_float;
                                method = J_DCT_METHOD.JDCT_FLOAT;
                                break;
                            default:
                                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NOT_COMPILED);
                                break;
                        }
                        break;
                    default:
                        m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_DCTSIZE, compptr.DCT_h_scaled_size, compptr.DCT_v_scaled_size);
                        break;
                }

                int qtblno = m_cinfo.Component_info[ci].Quant_tbl_no;

                /* Make sure specified quantization table is present */
                if (qtblno < 0 || qtblno >= JpegConstants.NUM_QUANT_TBLS || m_cinfo.m_quant_tbl_ptrs[qtblno] == null)
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NO_QUANT_TABLE, qtblno);

                JQUANT_TBL qtbl = m_cinfo.m_quant_tbl_ptrs[qtblno];
                int[] dtbl;

                /* Create divisor table from quant table */
                int i = 0;
                switch (method)
                {
                    case J_DCT_METHOD.JDCT_ISLOW:
                        /* For LL&M IDCT method, divisors are equal to raw quantization
                         * coefficients multiplied by 8 (to counteract scaling).
                         */
                        dtbl = m_dctTables[ci].int_array;
                        for (i = 0; i < JpegConstants.DCTSIZE2; i++)
                            dtbl[i] = ((int)qtbl.quantval[i]) << (compptr.component_needed ? 4 : 3);
                        forward_DCT[ci] = forwardDCTImpl;
                        break;

                    case J_DCT_METHOD.JDCT_IFAST:
                        dtbl = m_dctTables[ci].int_array;
                        for (i = 0; i < JpegConstants.DCTSIZE2; i++)
                            dtbl[i] = JpegUtils.DESCALE((int)qtbl.quantval[i] * (int)aanscales[i], compptr.component_needed ? CONST_BITS - 4 : CONST_BITS - 3);
                        forward_DCT[ci] = forwardDCTImpl;
                        break;

                    case J_DCT_METHOD.JDCT_FLOAT:
                        float[] fdtbl = m_dctTables[ci].float_array;
                        i = 0;
                        for (int row = 0; row < JpegConstants.DCTSIZE; row++)
                        {
                            for (int col = 0; col < JpegConstants.DCTSIZE; col++)
                            {
                                fdtbl[i] = (float)(1.0 / (((double)qtbl.quantval[i] * aanscalefactor[row] * aanscalefactor[col] * (compptr.component_needed ? 16.0 : 8.0))));
                                i++;
                            }
                        }
                        forward_DCT[ci] = forwardDCTFloatImpl;
                        break;

                    default:
                        m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NOT_COMPILED);
                        break;
                }
            }
        }