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

start_pass() public method

Prepare for an output pass. Here we select the proper IDCT routine for each component and build a matching multiplier table.
public start_pass ( ) : void
return void
        public void start_pass()
        {
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                jpeg_component_info componentInfo = m_cinfo.Comp_info[ci];

                inverse_method im = null;
                int method = 0;
                /* Select the proper IDCT routine for this component's scaling */
                switch ((componentInfo.DCT_h_scaled_size << 8) + componentInfo.DCT_v_scaled_size)
                {
                    case ((1 << 8) + 1):
                        im = jpeg_idct_1x1;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((2 << 8) + 2):
                        im = jpeg_idct_2x2;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((3 << 8) + 3):
                        im = jpeg_idct_3x3;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((4 << 8) + 4):
                        im = jpeg_idct_4x4;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((5 << 8) + 5):
                        im = jpeg_idct_5x5;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((6 << 8) + 6):
                        im = jpeg_idct_6x6;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((7 << 8) + 7):
                        im = jpeg_idct_7x7;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((9 << 8) + 9):
                        im = jpeg_idct_9x9;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((10 << 8) + 10):
                        im = jpeg_idct_10x10;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((11 << 8) + 11):
                        im = jpeg_idct_11x11;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((12 << 8) + 12):
                        im = jpeg_idct_12x12;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((13 << 8) + 13):
                        im = jpeg_idct_13x13;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((14 << 8) + 14):
                        im = jpeg_idct_14x14;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((15 << 8) + 15):
                        im = jpeg_idct_15x15;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((16 << 8) + 16):
                        im = jpeg_idct_16x16;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((16 << 8) + 8):
                        im = jpeg_idct_16x8;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((14 << 8) + 7):
                        im = jpeg_idct_14x7;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((12 << 8) + 6):
                        im = jpeg_idct_12x6;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((10 << 8) + 5):
                        im = jpeg_idct_10x5;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((8 << 8) + 4):
                        im = jpeg_idct_8x4;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((6 << 8) + 3):
                        im = jpeg_idct_6x3;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((4 << 8) + 2):
                        im = jpeg_idct_4x2;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((2 << 8) + 1):
                        im = jpeg_idct_2x1;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((8 << 8) + 16):
                        im = jpeg_idct_8x16;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((7 << 8) + 14):
                        im = jpeg_idct_7x14;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((6 << 8) + 12):
                        im = jpeg_idct_6x12;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((5 << 8) + 10):
                        im = jpeg_idct_5x10;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((4 << 8) + 8):
                        im = jpeg_idct_4x8;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((3 << 8) + 6):
                        im = jpeg_idct_3x6;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((2 << 8) + 4):
                        im = jpeg_idct_2x4;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((1 << 8) + 2):
                        im = jpeg_idct_1x2;
                        method = (int)J_DCT_METHOD.JDCT_ISLOW;    /* jidctint uses islow-style table */
                        break;
                    case ((JpegConstants.DCTSIZE << 8) + JpegConstants.DCTSIZE):
                        switch (m_cinfo.m_dct_method)
                        {
                            case J_DCT_METHOD.JDCT_ISLOW:
                                im = jpeg_idct_islow;
                                method = (int)J_DCT_METHOD.JDCT_ISLOW;
                                break;
                            case J_DCT_METHOD.JDCT_IFAST:
                                im = jpeg_idct_ifast;
                                method = (int)J_DCT_METHOD.JDCT_IFAST;
                                break;
                            case J_DCT_METHOD.JDCT_FLOAT:
                                im = jpeg_idct_float;
                                method = (int)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, componentInfo.DCT_h_scaled_size, componentInfo.DCT_v_scaled_size);
                        break;
                }

                m_inverse_DCT_method[ci] = im;

                /* Create multiplier table from quant table.
                 * However, we can skip this if the component is uninteresting
                 * or if we already built the table.  Also, if no quant table
                 * has yet been saved for the component, we leave the
                 * multiplier table all-zero; we'll be reading zeroes from the
                 * coefficient controller's buffer anyway.
                 */
                if (!componentInfo.component_needed || m_cur_method[ci] == method)
                    continue;

                if (componentInfo.quant_table == null)
                {
                    /* happens if no data yet for component */
                    continue;
                }

                m_cur_method[ci] = method;
                switch ((J_DCT_METHOD)method)
                {
                    case J_DCT_METHOD.JDCT_ISLOW:
                        /* For LL&M IDCT method, multipliers are equal to raw quantization
                         * coefficients, but are stored as ints to ensure access efficiency.
                         */
                        int[] ismtbl = m_dctTables[ci].int_array;
                        for (int i = 0; i < JpegConstants.DCTSIZE2; i++)
                            ismtbl[i] = componentInfo.quant_table.quantval[i];
                        break;

                    case J_DCT_METHOD.JDCT_IFAST:
                        /* For AA&N IDCT method, multipliers are equal to quantization
                         * coefficients scaled by scalefactor[row]*scalefactor[col], where
                         *   scalefactor[0] = 1
                         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
                         * For integer operation, the multiplier table is to be scaled by
                         * IFAST_SCALE_BITS.
                         */
                        int[] ifmtbl = m_dctTables[ci].int_array;

                        for (int i = 0; i < JpegConstants.DCTSIZE2; i++)
                        {
                            ifmtbl[i] = JpegUtils.DESCALE(
                                (int)componentInfo.quant_table.quantval[i] * (int)aanscales[i],
                                CONST_BITS - IFAST_SCALE_BITS);
                        }
                        break;

                    case J_DCT_METHOD.JDCT_FLOAT:
                        /* For float AA&N IDCT method, multipliers are equal to quantization
                         * coefficients scaled by scalefactor[row]*scalefactor[col], where
                         *   scalefactor[0] = 1
                         *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7
                         * We apply a further scale factor of 1/8.
                         */
                        float[] fmtbl = m_dctTables[ci].float_array;
                        int ii = 0;
                        for (int row = 0; row < JpegConstants.DCTSIZE; row++)
                        {
                            for (int col = 0; col < JpegConstants.DCTSIZE; col++)
                            {
                                fmtbl[ii] = (float)((double)componentInfo.quant_table.quantval[ii] * aanscalefactor[row] * aanscalefactor[col] * 0.125);
                                ii++;
                            }
                        }
                        break;

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