BitMiracle.LibJpeg.Classic.Internal.jpeg_d_coef_controller.smoothing_ok C# (CSharp) Method

smoothing_ok() private method

Determine whether block smoothing is applicable and safe. We also latch the current states of the coef_bits[] entries for the AC coefficients; otherwise, if the input side of the decompressor advances into a new scan, we might think the coefficients are known more accurately than they really are.
private smoothing_ok ( ) : bool
return bool
        private bool smoothing_ok()
        {
            if (!m_cinfo.m_progressive_mode || m_cinfo.m_coef_bits == null)
                return false;

            /* Allocate latch area if not already done */
            if (m_coef_bits_latch == null)
            {
                m_coef_bits_latch = new int[m_cinfo.m_num_components * SAVED_COEFS];
                m_coef_bits_savedOffset = 0;
            }

            bool smoothing_useful = false;
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                /* All components' quantization values must already be latched. */
                JQUANT_TBL qtable = m_cinfo.Comp_info[ci].quant_table;
                if (qtable == null)
                    return false;

                /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
                if (qtable.quantval[0] == 0 || qtable.quantval[Q01_POS] == 0 ||
                    qtable.quantval[Q10_POS] == 0 || qtable.quantval[Q20_POS] == 0 ||
                    qtable.quantval[Q11_POS] == 0 || qtable.quantval[Q02_POS] == 0)
                {
                    return false;
                }

                /* DC values must be at least partly known for all components. */
                if (m_cinfo.m_coef_bits[ci][0] < 0)
                    return false;

                /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
                for (int coefi = 1; coefi <= 5; coefi++)
                {
                    m_coef_bits_latch[m_coef_bits_savedOffset + coefi] = m_cinfo.m_coef_bits[ci][coefi];
                    if (m_cinfo.m_coef_bits[ci][coefi] != 0)
                        smoothing_useful = true;
                }

                m_coef_bits_savedOffset += SAVED_COEFS;
            }

            return smoothing_useful;
        }