jdiv_round_up() 공개 정적인 메소드

Compute a/b rounded up to next integer, ie, ceil(a/b) Assumes a >= 0, b > 0
public static jdiv_round_up ( long a, long b ) : long
a long
b long
리턴 long
예제 #1
0
        /// <summary>
        /// Do computations that are needed before processing a JPEG scan
        /// cinfo.comps_in_scan and cinfo.cur_comp_info[] were set from SOS marker
        /// </summary>
        private void per_scan_setup()
        {
            if (m_cinfo.m_comps_in_scan == 1)
            {
                /* Noninterleaved (single-component) scan */
                jpeg_component_info componentInfo = m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[0]];

                /* Overall image size in MCUs */
                m_cinfo.m_MCUs_per_row     = componentInfo.Width_in_blocks;
                m_cinfo.m_MCU_rows_in_scan = componentInfo.height_in_blocks;

                /* For noninterleaved scan, always one block per MCU */
                componentInfo.MCU_width        = 1;
                componentInfo.MCU_height       = 1;
                componentInfo.MCU_blocks       = 1;
                componentInfo.MCU_sample_width = componentInfo.DCT_scaled_size;
                componentInfo.last_col_width   = 1;

                /* For noninterleaved scans, it is convenient to define last_row_height
                 * as the number of block rows present in the last iMCU row.
                 */
                int tmp = componentInfo.height_in_blocks % componentInfo.V_samp_factor;
                if (tmp == 0)
                {
                    tmp = componentInfo.V_samp_factor;
                }
                componentInfo.last_row_height = tmp;
                m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[0]] = componentInfo;

                /* Prepare array describing MCU composition */
                m_cinfo.m_blocks_in_MCU     = 1;
                m_cinfo.m_MCU_membership[0] = 0;
            }
            else
            {
                /* Interleaved (multi-component) scan */
                if (m_cinfo.m_comps_in_scan <= 0 || m_cinfo.m_comps_in_scan > JpegConstants.MAX_COMPS_IN_SCAN)
                {
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_COMPONENT_COUNT, m_cinfo.m_comps_in_scan, JpegConstants.MAX_COMPS_IN_SCAN);
                }

                /* Overall image size in MCUs */
                m_cinfo.m_MCUs_per_row = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width, m_cinfo.m_max_h_samp_factor * JpegConstants.DCTSIZE);

                m_cinfo.m_MCU_rows_in_scan = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_height, m_cinfo.m_max_v_samp_factor * JpegConstants.DCTSIZE);

                m_cinfo.m_blocks_in_MCU = 0;

                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]];

                    /* Sampling factors give # of blocks of component in each MCU */
                    componentInfo.MCU_width        = componentInfo.H_samp_factor;
                    componentInfo.MCU_height       = componentInfo.V_samp_factor;
                    componentInfo.MCU_blocks       = componentInfo.MCU_width * componentInfo.MCU_height;
                    componentInfo.MCU_sample_width = componentInfo.MCU_width * componentInfo.DCT_scaled_size;

                    /* Figure number of non-dummy blocks in last MCU column & row */
                    int tmp = componentInfo.Width_in_blocks % componentInfo.MCU_width;
                    if (tmp == 0)
                    {
                        tmp = componentInfo.MCU_width;
                    }
                    componentInfo.last_col_width = tmp;

                    tmp = componentInfo.height_in_blocks % componentInfo.MCU_height;
                    if (tmp == 0)
                    {
                        tmp = componentInfo.MCU_height;
                    }
                    componentInfo.last_row_height = tmp;

                    /* Prepare array describing MCU composition */
                    int mcublks = componentInfo.MCU_blocks;
                    if (m_cinfo.m_blocks_in_MCU + mcublks > JpegConstants.D_MAX_BLOCKS_IN_MCU)
                    {
                        m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_MCU_SIZE);
                    }

                    m_cinfo.Comp_info[m_cinfo.m_cur_comp_info[ci]] = componentInfo;

                    while (mcublks-- > 0)
                    {
                        m_cinfo.m_MCU_membership[m_cinfo.m_blocks_in_MCU++] = ci;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Routines to calculate various quantities related to the size of the image.
        /// Called once, when first SOS marker is reached
        /// </summary>
        private void initial_setup()
        {
            /* Make sure image isn't bigger than I can handle */
            if (m_cinfo.m_image_height > JpegConstants.JPEG_MAX_DIMENSION ||
                m_cinfo.m_image_width > JpegConstants.JPEG_MAX_DIMENSION)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_IMAGE_TOO_BIG, (int)JpegConstants.JPEG_MAX_DIMENSION);
            }

            /* For now, precision must match compiled-in value... */
            if (m_cinfo.m_data_precision != JpegConstants.BITS_IN_JSAMPLE)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_PRECISION, m_cinfo.m_data_precision);
            }

            /* Check that number of components won't exceed internal array sizes */
            if (m_cinfo.m_num_components > JpegConstants.MAX_COMPONENTS)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_COMPONENT_COUNT, m_cinfo.m_num_components, JpegConstants.MAX_COMPONENTS);
            }

            /* Compute maximum sampling factors; check factor validity */
            m_cinfo.m_max_h_samp_factor = 1;
            m_cinfo.m_max_v_samp_factor = 1;

            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                if (m_cinfo.Comp_info[ci].H_samp_factor <= 0 || m_cinfo.Comp_info[ci].H_samp_factor > JpegConstants.MAX_SAMP_FACTOR ||
                    m_cinfo.Comp_info[ci].V_samp_factor <= 0 || m_cinfo.Comp_info[ci].V_samp_factor > JpegConstants.MAX_SAMP_FACTOR)
                {
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_SAMPLING);
                }

                m_cinfo.m_max_h_samp_factor = Math.Max(m_cinfo.m_max_h_samp_factor, m_cinfo.Comp_info[ci].H_samp_factor);
                m_cinfo.m_max_v_samp_factor = Math.Max(m_cinfo.m_max_v_samp_factor, m_cinfo.Comp_info[ci].V_samp_factor);
            }

            /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
             * In the full decompressor, this will be overridden jpeg_decomp_master;
             * but in the transcoder, jpeg_decomp_master is not used, so we must do it here.
             */
            m_cinfo.m_min_DCT_scaled_size = JpegConstants.DCTSIZE;

            /* Compute dimensions of components */
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                m_cinfo.Comp_info[ci].DCT_scaled_size = JpegConstants.DCTSIZE;

                /* Size in DCT blocks */
                m_cinfo.Comp_info[ci].Width_in_blocks = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width * m_cinfo.Comp_info[ci].H_samp_factor,
                    m_cinfo.m_max_h_samp_factor * JpegConstants.DCTSIZE);

                m_cinfo.Comp_info[ci].height_in_blocks = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_height * m_cinfo.Comp_info[ci].V_samp_factor,
                    m_cinfo.m_max_v_samp_factor * JpegConstants.DCTSIZE);

                /* downsampled_width and downsampled_height will also be overridden by
                 * jpeg_decomp_master if we are doing full decompression.  The transcoder library
                 * doesn't use these values, but the calling application might.
                 */
                /* Size in samples */
                m_cinfo.Comp_info[ci].downsampled_width = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width * m_cinfo.Comp_info[ci].H_samp_factor,
                    m_cinfo.m_max_h_samp_factor);

                m_cinfo.Comp_info[ci].downsampled_height = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_height * m_cinfo.Comp_info[ci].V_samp_factor,
                    m_cinfo.m_max_v_samp_factor);

                /* Mark component needed, until color conversion says otherwise */
                m_cinfo.Comp_info[ci].component_needed = true;

                /* Mark no quantization table yet saved for component */
                m_cinfo.Comp_info[ci].quant_table = null;
            }

            /* Compute number of fully interleaved MCU rows. */
            m_cinfo.m_total_iMCU_rows = JpegUtils.jdiv_round_up(
                m_cinfo.m_image_height, m_cinfo.m_max_v_samp_factor * JpegConstants.DCTSIZE);

            /* Decide whether file contains multiple scans */
            if (m_cinfo.m_comps_in_scan < m_cinfo.m_num_components || m_cinfo.m_progressive_mode)
            {
                m_cinfo.m_inputctl.m_has_multiple_scans = true;
            }
            else
            {
                m_cinfo.m_inputctl.m_has_multiple_scans = false;
            }
        }
예제 #3
0
        /// <summary>
        /// Do computations that are needed before processing a JPEG scan
        /// cinfo.comps_in_scan and cinfo.cur_comp_info[] are already set
        /// </summary>
        private void per_scan_setup()
        {
            if (m_cinfo.m_comps_in_scan == 1)
            {
                /* Noninterleaved (single-component) scan */
                int compIndex = m_cinfo.m_cur_comp_info[0];

                /* Overall image size in MCUs */
                m_cinfo.m_MCUs_per_row     = m_cinfo.Component_info[compIndex].Width_in_blocks;
                m_cinfo.m_MCU_rows_in_scan = m_cinfo.Component_info[compIndex].height_in_blocks;

                /* For noninterleaved scan, always one block per MCU */
                m_cinfo.Component_info[compIndex].MCU_width        = 1;
                m_cinfo.Component_info[compIndex].MCU_height       = 1;
                m_cinfo.Component_info[compIndex].MCU_blocks       = 1;
                m_cinfo.Component_info[compIndex].MCU_sample_width = JpegConstants.DCTSIZE;
                m_cinfo.Component_info[compIndex].last_col_width   = 1;

                /* For noninterleaved scans, it is convenient to define last_row_height
                 * as the number of block rows present in the last iMCU row.
                 */
                int tmp = m_cinfo.Component_info[compIndex].height_in_blocks % m_cinfo.Component_info[compIndex].V_samp_factor;
                if (tmp == 0)
                {
                    tmp = m_cinfo.Component_info[compIndex].V_samp_factor;
                }
                m_cinfo.Component_info[compIndex].last_row_height = tmp;

                /* Prepare array describing MCU composition */
                m_cinfo.m_blocks_in_MCU     = 1;
                m_cinfo.m_MCU_membership[0] = 0;
            }
            else
            {
                /* Interleaved (multi-component) scan */
                if (m_cinfo.m_comps_in_scan <= 0 || m_cinfo.m_comps_in_scan > JpegConstants.MAX_COMPS_IN_SCAN)
                {
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_COMPONENT_COUNT, m_cinfo.m_comps_in_scan, JpegConstants.MAX_COMPS_IN_SCAN);
                }

                /* Overall image size in MCUs */
                m_cinfo.m_MCUs_per_row = JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width, m_cinfo.m_max_h_samp_factor * JpegConstants.DCTSIZE);

                m_cinfo.m_MCU_rows_in_scan = JpegUtils.jdiv_round_up(m_cinfo.m_image_height,
                                                                     m_cinfo.m_max_v_samp_factor * JpegConstants.DCTSIZE);

                m_cinfo.m_blocks_in_MCU = 0;

                for (int ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
                {
                    int compIndex = m_cinfo.m_cur_comp_info[ci];

                    /* Sampling factors give # of blocks of component in each MCU */
                    m_cinfo.Component_info[compIndex].MCU_width        = m_cinfo.Component_info[compIndex].H_samp_factor;
                    m_cinfo.Component_info[compIndex].MCU_height       = m_cinfo.Component_info[compIndex].V_samp_factor;
                    m_cinfo.Component_info[compIndex].MCU_blocks       = m_cinfo.Component_info[compIndex].MCU_width * m_cinfo.Component_info[compIndex].MCU_height;
                    m_cinfo.Component_info[compIndex].MCU_sample_width = m_cinfo.Component_info[compIndex].MCU_width * JpegConstants.DCTSIZE;

                    /* Figure number of non-dummy blocks in last MCU column & row */
                    int tmp = m_cinfo.Component_info[compIndex].Width_in_blocks % m_cinfo.Component_info[compIndex].MCU_width;
                    if (tmp == 0)
                    {
                        tmp = m_cinfo.Component_info[compIndex].MCU_width;
                    }
                    m_cinfo.Component_info[compIndex].last_col_width = tmp;

                    tmp = m_cinfo.Component_info[compIndex].height_in_blocks % m_cinfo.Component_info[compIndex].MCU_height;
                    if (tmp == 0)
                    {
                        tmp = m_cinfo.Component_info[compIndex].MCU_height;
                    }
                    m_cinfo.Component_info[compIndex].last_row_height = tmp;

                    /* Prepare array describing MCU composition */
                    int mcublks = m_cinfo.Component_info[compIndex].MCU_blocks;
                    if (m_cinfo.m_blocks_in_MCU + mcublks > JpegConstants.C_MAX_BLOCKS_IN_MCU)
                    {
                        m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_MCU_SIZE);
                    }

                    while (mcublks-- > 0)
                    {
                        m_cinfo.m_MCU_membership[m_cinfo.m_blocks_in_MCU++] = ci;
                    }
                }
            }

            /* Convert restart specified in rows to actual MCU count. */
            /* Note that count must fit in 16 bits, so we provide limiting. */
            if (m_cinfo.m_restart_in_rows > 0)
            {
                int nominal = m_cinfo.m_restart_in_rows * m_cinfo.m_MCUs_per_row;
                m_cinfo.m_restart_interval = Math.Min(nominal, 65535);
            }
        }
예제 #4
0
        /// <summary>
        /// Routines to calculate various quantities related to the size of the image.
        /// Called once, when first SOS marker is reached
        /// </summary>
        private void initial_setup()
        {
            /* Make sure image isn't bigger than I can handle */
            if (m_cinfo.m_image_height > JpegConstants.JPEG_MAX_DIMENSION ||
                m_cinfo.m_image_width > JpegConstants.JPEG_MAX_DIMENSION)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_IMAGE_TOO_BIG, (int)JpegConstants.JPEG_MAX_DIMENSION);
            }

            /* Only 8 to 12 bits data precision are supported for DCT based JPEG */
            if (m_cinfo.m_data_precision < 8 || m_cinfo.m_data_precision > 12)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_PRECISION, m_cinfo.m_data_precision);
            }

            /* Check that number of components won't exceed internal array sizes */
            if (m_cinfo.m_num_components > JpegConstants.MAX_COMPONENTS)
            {
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_COMPONENT_COUNT, m_cinfo.m_num_components, JpegConstants.MAX_COMPONENTS);
            }

            /* Compute maximum sampling factors; check factor validity */
            m_cinfo.m_max_h_samp_factor = 1;
            m_cinfo.m_max_v_samp_factor = 1;

            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                if (m_cinfo.Comp_info[ci].H_samp_factor <= 0 || m_cinfo.Comp_info[ci].H_samp_factor > JpegConstants.MAX_SAMP_FACTOR ||
                    m_cinfo.Comp_info[ci].V_samp_factor <= 0 || m_cinfo.Comp_info[ci].V_samp_factor > JpegConstants.MAX_SAMP_FACTOR)
                {
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_SAMPLING);
                }

                m_cinfo.m_max_h_samp_factor = Math.Max(m_cinfo.m_max_h_samp_factor, m_cinfo.Comp_info[ci].H_samp_factor);
                m_cinfo.m_max_v_samp_factor = Math.Max(m_cinfo.m_max_v_samp_factor, m_cinfo.Comp_info[ci].V_samp_factor);
            }

            /* Derive block_size, natural_order, and lim_Se */
            if (m_cinfo.is_baseline || (m_cinfo.m_progressive_mode && m_cinfo.m_comps_in_scan != 0))
            {
                /* no pseudo SOS marker */
                m_cinfo.block_size    = JpegConstants.DCTSIZE;
                m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
            }
            else
            {
                switch (m_cinfo.m_Se)
                {
                case (1 * 1 - 1):
                    m_cinfo.block_size    = 1;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;     /* not needed */
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (2 * 2 - 1):
                    m_cinfo.block_size    = 2;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order2;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (3 * 3 - 1):
                    m_cinfo.block_size    = 3;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order3;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (4 * 4 - 1):
                    m_cinfo.block_size    = 4;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order4;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (5 * 5 - 1):
                    m_cinfo.block_size    = 5;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order5;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (6 * 6 - 1):
                    m_cinfo.block_size    = 6;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order6;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (7 * 7 - 1):
                    m_cinfo.block_size    = 7;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order7;
                    m_cinfo.lim_Se        = m_cinfo.m_Se;
                    break;

                case (8 * 8 - 1):
                    m_cinfo.block_size    = 8;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (9 * 9 - 1):
                    m_cinfo.block_size    = 9;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (10 * 10 - 1):
                    m_cinfo.block_size    = 10;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (11 * 11 - 1):
                    m_cinfo.block_size    = 11;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (12 * 12 - 1):
                    m_cinfo.block_size    = 12;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (13 * 13 - 1):
                    m_cinfo.block_size    = 13;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (14 * 14 - 1):
                    m_cinfo.block_size    = 14;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (15 * 15 - 1):
                    m_cinfo.block_size    = 15;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                case (16 * 16 - 1):
                    m_cinfo.block_size    = 16;
                    m_cinfo.natural_order = JpegUtils.jpeg_natural_order;
                    m_cinfo.lim_Se        = JpegConstants.DCTSIZE2 - 1;
                    break;

                default:
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_BAD_PROGRESSION,
                                    m_cinfo.m_Ss, m_cinfo.m_Se, m_cinfo.m_Ah, m_cinfo.m_Al);
                    break;
                }
            }

            /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
             * In the full decompressor,
             * this will be overridden by jpeg_calc_output_dimensions in jdmaster.c;
             * but in the transcoder,
             * jpeg_calc_output_dimensions is not used, so we must do it here.
             */
            m_cinfo.min_DCT_h_scaled_size = m_cinfo.block_size;
            m_cinfo.min_DCT_v_scaled_size = m_cinfo.block_size;

            /* Compute dimensions of components */
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                jpeg_component_info compptr = m_cinfo.Comp_info[ci];
                compptr.DCT_h_scaled_size = m_cinfo.block_size;
                compptr.DCT_v_scaled_size = m_cinfo.block_size;

                /* Size in DCT blocks */
                compptr.Width_in_blocks = (int)JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width * compptr.H_samp_factor,
                    m_cinfo.m_max_h_samp_factor * m_cinfo.block_size);

                compptr.height_in_blocks = (int)JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_height * compptr.V_samp_factor,
                    m_cinfo.m_max_v_samp_factor * m_cinfo.block_size);

                /* downsampled_width and downsampled_height will also be overridden by
                 * jpeg_decomp_master if we are doing full decompression.  The transcoder library
                 * doesn't use these values, but the calling application might.
                 */
                /* Size in samples */
                compptr.downsampled_width = (int)JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_width * compptr.H_samp_factor,
                    m_cinfo.m_max_h_samp_factor);

                compptr.downsampled_height = (int)JpegUtils.jdiv_round_up(
                    m_cinfo.m_image_height * compptr.V_samp_factor,
                    m_cinfo.m_max_v_samp_factor);

                /* Mark component needed, until color conversion says otherwise */
                compptr.component_needed = true;

                /* Mark no quantization table yet saved for component */
                compptr.quant_table = null;
            }

            /* Compute number of fully interleaved MCU rows. */
            m_cinfo.m_total_iMCU_rows = (int)JpegUtils.jdiv_round_up(
                m_cinfo.m_image_height, m_cinfo.m_max_v_samp_factor * m_cinfo.block_size);

            /* Decide whether file contains multiple scans */
            if (m_cinfo.m_comps_in_scan < m_cinfo.m_num_components || m_cinfo.m_progressive_mode)
            {
                m_cinfo.m_inputctl.m_has_multiple_scans = true;
            }
            else
            {
                m_cinfo.m_inputctl.m_has_multiple_scans = false;
            }
        }
예제 #5
0
        /*
         * Compute output image dimensions and related values.
         * NOTE: this is exported for possible use by application.
         * Hence it mustn't do anything that can't be done twice.
         */
        /* Do computations that are needed before master selection phase.
         * This function is used for transcoding and full decompression.
         */
        public void jpeg_core_output_dimensions()
        {
            /* Compute actual output image dimensions and DCT scaling choices. */
            if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom)
            {
                /* Provide 1/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 1;
                m_cinfo.min_DCT_v_scaled_size = 1;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 2)
            {
                /* Provide 2/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 2L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 2L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 2;
                m_cinfo.min_DCT_v_scaled_size = 2;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 3)
            {
                /* Provide 3/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 3L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 3L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 3;
                m_cinfo.min_DCT_v_scaled_size = 3;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 4)
            {
                /* Provide 4/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 4L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 4L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 4;
                m_cinfo.min_DCT_v_scaled_size = 4;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 5)
            {
                /* Provide 5/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 5L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 5L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 5;
                m_cinfo.min_DCT_v_scaled_size = 5;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 6)
            {
                /* Provide 6/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 6L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 6L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 6;
                m_cinfo.min_DCT_v_scaled_size = 6;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 7)
            {
                /* Provide 7/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 7L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 7L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 7;
                m_cinfo.min_DCT_v_scaled_size = 7;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 8)
            {
                /* Provide 8/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 8L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 8L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 8;
                m_cinfo.min_DCT_v_scaled_size = 8;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 9)
            {
                /* Provide 9/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 9L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 9L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 9;
                m_cinfo.min_DCT_v_scaled_size = 9;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 10)
            {
                /* Provide 10/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 10L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 10L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 10;
                m_cinfo.min_DCT_v_scaled_size = 10;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 11)
            {
                /* Provide 11/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 11L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 11L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 11;
                m_cinfo.min_DCT_v_scaled_size = 11;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 12)
            {
                /* Provide 12/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 12L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 12L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 12;
                m_cinfo.min_DCT_v_scaled_size = 12;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 13)
            {
                /* Provide 13/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 13L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 13L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 13;
                m_cinfo.min_DCT_v_scaled_size = 13;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 14)
            {
                /* Provide 14/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 14L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 14L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 14;
                m_cinfo.min_DCT_v_scaled_size = 14;
            }
            else if (m_cinfo.m_scale_num * m_cinfo.block_size <= m_cinfo.m_scale_denom * 15)
            {
                /* Provide 15/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 15L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 15L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 15;
                m_cinfo.min_DCT_v_scaled_size = 15;
            }
            else
            {
                /* Provide 16/block_size scaling */
                m_cinfo.m_output_width = (int)
                                         JpegUtils.jdiv_round_up((long)m_cinfo.m_image_width * 16L, (long)m_cinfo.block_size);
                m_cinfo.m_output_height = (int)
                                          JpegUtils.jdiv_round_up((long)m_cinfo.m_image_height * 16L, (long)m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 16;
                m_cinfo.min_DCT_v_scaled_size = 16;
            }

            /* Recompute dimensions of components */
            for (int ci = 0; ci < m_cinfo.m_num_components; ci++)
            {
                jpeg_component_info compptr = m_cinfo.Comp_info[ci];
                compptr.DCT_h_scaled_size = m_cinfo.min_DCT_h_scaled_size;
                compptr.DCT_v_scaled_size = m_cinfo.min_DCT_v_scaled_size;
            }
        }
예제 #6
0
        /*
         * Compute output image dimensions and related values.
         * NOTE: this is exported for possible use by application.
         * Hence it mustn't do anything that can't be done twice.
         */
        /* Do computations that are needed before master selection phase.
         * This function is used for transcoding and full decompression.
         */
        public void JpegCoreOutputDimensions()
        {
            /* Compute actual output image dimensions and DCT scaling choices. */
            if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom)
            {
                /* Provide 1/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 1;
                m_cinfo.min_DCT_v_scaled_size = 1;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 2)
            {
                /* Provide 2/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 2L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 2L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 2;
                m_cinfo.min_DCT_v_scaled_size = 2;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 3)
            {
                /* Provide 3/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 3L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 3L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 3;
                m_cinfo.min_DCT_v_scaled_size = 3;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 4)
            {
                /* Provide 4/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 4L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 4L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 4;
                m_cinfo.min_DCT_v_scaled_size = 4;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 5)
            {
                /* Provide 5/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 5L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 5L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 5;
                m_cinfo.min_DCT_v_scaled_size = 5;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 6)
            {
                /* Provide 6/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 6L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 6L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 6;
                m_cinfo.min_DCT_v_scaled_size = 6;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 7)
            {
                /* Provide 7/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 7L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 7L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 7;
                m_cinfo.min_DCT_v_scaled_size = 7;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 8)
            {
                /* Provide 8/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 8L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 8L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 8;
                m_cinfo.min_DCT_v_scaled_size = 8;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 9)
            {
                /* Provide 9/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 9L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 9L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 9;
                m_cinfo.min_DCT_v_scaled_size = 9;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 10)
            {
                /* Provide 10/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 10L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 10L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 10;
                m_cinfo.min_DCT_v_scaled_size = 10;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 11)
            {
                /* Provide 11/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 11L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 11L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 11;
                m_cinfo.min_DCT_v_scaled_size = 11;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 12)
            {
                /* Provide 12/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 12L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 12L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 12;
                m_cinfo.min_DCT_v_scaled_size = 12;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 13)
            {
                /* Provide 13/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 13L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 13L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 13;
                m_cinfo.min_DCT_v_scaled_size = 13;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 14)
            {
                /* Provide 14/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 14L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 14L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 14;
                m_cinfo.min_DCT_v_scaled_size = 14;
            }
            else if (m_cinfo.scaleNum * m_cinfo.block_size <= m_cinfo.scaleDenom * 15)
            {
                /* Provide 15/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 15L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 15L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 15;
                m_cinfo.min_DCT_v_scaled_size = 15;
            }
            else
            {
                /* Provide 16/block_size scaling */
                m_cinfo.outputWidth = (int)
                                      JpegUtils.jdiv_round_up(m_cinfo.imageWidth * 16L, m_cinfo.block_size);
                m_cinfo.outputHeight = (int)
                                       JpegUtils.jdiv_round_up(m_cinfo.imageHeight * 16L, m_cinfo.block_size);
                m_cinfo.min_DCT_h_scaled_size = 16;
                m_cinfo.min_DCT_v_scaled_size = 16;
            }

            /* Recompute dimensions of components */
            for (var ci = 0; ci < m_cinfo.numComponents; ci++)
            {
                var compptr = m_cinfo.CompInfo[ci];
                compptr.DCT_h_scaled_size = m_cinfo.min_DCT_h_scaled_size;
                compptr.DCT_v_scaled_size = m_cinfo.min_DCT_v_scaled_size;
            }
        }