BitMiracle.LibJpeg.Classic.jpeg_compress_struct.jpeg_add_quant_table C# (CSharp) Method

jpeg_add_quant_table() public method

Allows an arbitrary quantization table to be created.
public jpeg_add_quant_table ( int which_tbl, int basic_table, int scale_factor, bool force_baseline ) : void
which_tbl int Indicates which table slot to fill.
basic_table int An array of 64 unsigned integers given in normal array order. /// These values are multiplied by scale_factor/100 and then clamped to the range 1..65535 /// (or to 1..255 if force_baseline is true).
/// The basic table should be given in JPEG zigzag order. ///
scale_factor int Multiplier for values in basic_table.
force_baseline bool Defines range of values in basic_table. /// If true - 1..255, otherwise - 1..65535.
return void
        public void jpeg_add_quant_table(int which_tbl, int[] basic_table, int scale_factor, bool force_baseline)
        {
            /* Safety check to ensure start_compress not called yet. */
            if (m_global_state != JpegState.CSTATE_START)
                ERREXIT(J_MESSAGE_CODE.JERR_BAD_STATE, (int)m_global_state);

            if (which_tbl < 0 || which_tbl >= JpegConstants.NUM_QUANT_TBLS)
                ERREXIT(J_MESSAGE_CODE.JERR_DQT_INDEX, which_tbl);

            if (m_quant_tbl_ptrs[which_tbl] == null)
                m_quant_tbl_ptrs[which_tbl] = new JQUANT_TBL();

            for (int i = 0; i < JpegConstants.DCTSIZE2; i++)
            {
                int temp = (basic_table[i] * scale_factor + 50) / 100;

                /* limit the values to the valid range */
                if (temp <= 0)
                    temp = 1;

                /* max quantizer needed for 12 bits */
                if (temp > 32767)
                    temp = 32767;

                /* limit to baseline range if requested */
                if (force_baseline && temp > 255)
                    temp = 255;

                m_quant_tbl_ptrs[which_tbl].quantval[i] = (short)temp;
            }

            /* Initialize sent_table false so table will be written to JPEG file. */
            m_quant_tbl_ptrs[which_tbl].Sent_table = false;
        }