BitMiracle.LibJpeg.Classic.Internal.jpeg_input_controller.latch_quant_tables C# (CSharp) Method

latch_quant_tables() private method

Save away a copy of the Q-table referenced by each component present in the current scan, unless already saved during a prior scan. In a multiple-scan JPEG file, the encoder could assign different components the same Q-table slot number, but change table definitions between scans so that each component uses a different Q-table. (The IJG encoder is not currently capable of doing this, but other encoders might.) Since we want to be able to dequantize all the components at the end of the file, this means that we have to save away the table actually used for each component. We do this by copying the table at the start of the first scan containing the component. The JPEG spec prohibits the encoder from changing the contents of a Q-table slot between scans of a component using that slot. If the encoder does so anyway, this decoder will simply use the Q-table values that were current at the start of the first scan for the component. The decompressor output side looks only at the saved quant tables, not at the current Q-table slots.
private latch_quant_tables ( ) : void
return void
        private void latch_quant_tables()
        {
            for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
            {
                jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]];

                /* No work if we already saved Q-table for this component */
                if (componentInfo.quant_table != null)
                    continue;

                /* Make sure specified quantization table is present */
                int qtblno = componentInfo.Quant_tbl_no;
                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);

                /* OK, save away the quantization table */
                JQUANT_TBL qtbl = new JQUANT_TBL();
                Buffer.BlockCopy(m_cinfo.m_quant_tbl_ptrs[qtblno].quantval, 0,
                    qtbl.quantval, 0, qtbl.quantval.Length * sizeof(short));
                qtbl.Sent_table = m_cinfo.m_quant_tbl_ptrs[qtblno].Sent_table;
                componentInfo.quant_table = qtbl;
                m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]] = componentInfo;
            }
        }