/// <summary>
        /// Jpeg_set_defaultses this instance.
        /// </summary>
        /// <remarks>Uses only the input image's color space (property <see cref="jpeg_compress_struct.In_color_space"/>, 
        /// which must already be set in <see cref="jpeg_compress_struct"/>). Many applications will only need 
        /// to use this routine and perhaps <see cref="jpeg_compress_struct.jpeg_set_quality"/>.
        /// </remarks>
        /// <seealso href="ce3f6712-3633-4a58-af07-626a4fba9ae4.htm" target="_self">Compression parameter selection</seealso>
        public void jpeg_set_defaults()
        {
            /* 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);

            /* Allocate comp_info array large enough for maximum component count.
            * Array is made permanent in case application wants to compress
            * multiple images at same param settings.
            */
            if (m_comp_info == null)
            {
                m_comp_info = jpeg_component_info.createArrayOfComponents(JpegConstants.MAX_COMPONENTS);
            }

            /* Initialize everything not dependent on the color space */

            m_data_precision = JpegConstants.BITS_IN_JSAMPLE;

            /* Set up two quantization tables using default quality of 75 */
            jpeg_set_quality(75, true);

            /* Set up two Huffman tables */
            std_huff_tables();

            /* Default is no multiple-scan output */
            m_scan_info = null;
            m_num_scans = 0;

            /* Expect normal source image, not raw downsampled data */
            m_raw_data_in = false;

            /* By default, don't do extra passes to optimize entropy coding */
            m_optimize_coding = false;

            /* The standard Huffman tables are only valid for 8-bit data precision.
            * If the precision is higher, force optimization on so that usable
            * tables will be computed.  This test can be removed if default tables
            * are supplied that are valid for the desired precision.
            */
            if (m_data_precision > 8)
                m_optimize_coding = true;

            /* By default, use the simpler non-cosited sampling alignment */
            m_CCIR601_sampling = false;

            /* No input smoothing */
            m_smoothing_factor = 0;

            /* DCT algorithm preference */
            m_dct_method = JpegConstants.JDCT_DEFAULT;

            /* No restart markers */
            m_restart_interval = 0;
            m_restart_in_rows = 0;

            /* Fill in default JFIF marker parameters.  Note that whether the marker
            * will actually be written is determined by jpeg_set_colorspace.
            *
            * By default, the library emits JFIF version code 1.01.
            * An application that wants to emit JFIF 1.02 extension markers should set
            * JFIF_minor_version to 2.  We could probably get away with just defaulting
            * to 1.02, but there may still be some decoders in use that will complain
            * about that; saying 1.01 should minimize compatibility problems.
            */
            m_JFIF_major_version = 1; /* Default JFIF version = 1.01 */
            m_JFIF_minor_version = 1;
            m_density_unit = DensityUnit.Unknown;    /* Pixel size is unknown by default */
            m_X_density = 1;       /* Pixel aspect ratio is square by default */
            m_Y_density = 1;

            /* Choose JPEG colorspace based on input space, set defaults accordingly */
            jpeg_default_colorspace();
        }
        /// <summary>
        /// Set default decompression parameters.
        /// </summary>
        private void default_decompress_parms()
        {
            /* Guess the input colorspace, and set output colorspace accordingly. */
            /* (Wish JPEG committee had provided a real way to specify this...) */
            /* Note application may override our guesses. */
            switch (m_num_components)
            {
                case 1:
                    m_jpeg_color_space = J_COLOR_SPACE.JCS_GRAYSCALE;
                    m_out_color_space = J_COLOR_SPACE.JCS_GRAYSCALE;
                    break;

                case 3:
                    if (m_saw_JFIF_marker)
                    {
                        /* JFIF implies YCbCr */
                        m_jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr;
                    }
                    else if (m_saw_Adobe_marker)
                    {
                        switch (m_Adobe_transform)
                        {
                            case 0:
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_RGB;
                                break;
                            case 1:
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr;
                                break;
                            default:
                                WARNMS(J_MESSAGE_CODE.JWRN_ADOBE_XFORM, m_Adobe_transform);
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr; /* assume it's YCbCr */
                                break;
                        }
                    }
                    else
                    {
                        /* Saw no special markers, try to guess from the component IDs */
                        int cid0 = m_comp_info[0].Component_id;
                        int cid1 = m_comp_info[1].Component_id;
                        int cid2 = m_comp_info[2].Component_id;

                        if (cid0 == 1 && cid1 == 2 && cid2 == 3)
                        {
                            /* assume JFIF w/out marker */
                            m_jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr;
                        }
                        else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
                        {
                            /* ASCII 'R', 'G', 'B' */
                            m_jpeg_color_space = J_COLOR_SPACE.JCS_RGB;
                        }
                        else
                        {
                            TRACEMS(1, J_MESSAGE_CODE.JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
                            /* assume it's YCbCr */
                            m_jpeg_color_space = J_COLOR_SPACE.JCS_YCbCr;
                        }
                    }
                    /* Always guess RGB is proper output colorspace. */
                    m_out_color_space = J_COLOR_SPACE.JCS_RGB;
                    break;

                case 4:
                    if (m_saw_Adobe_marker)
                    {
                        switch (m_Adobe_transform)
                        {
                            case 0:
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_CMYK;
                                break;
                            case 2:
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_YCCK;
                                break;
                            default:
                                WARNMS(J_MESSAGE_CODE.JWRN_ADOBE_XFORM, m_Adobe_transform);
                                /* assume it's YCCK */
                                m_jpeg_color_space = J_COLOR_SPACE.JCS_YCCK;
                                break;
                        }
                    }
                    else
                    {
                        /* No special markers, assume straight CMYK. */
                        m_jpeg_color_space = J_COLOR_SPACE.JCS_CMYK;
                    }

                    m_out_color_space = J_COLOR_SPACE.JCS_CMYK;
                    break;

                default:
                    m_jpeg_color_space = J_COLOR_SPACE.JCS_UNKNOWN;
                    m_out_color_space = J_COLOR_SPACE.JCS_UNKNOWN;
                    break;
            }

            /* Set defaults for other decompression parameters. */
            m_scale_num = 1;       /* 1:1 scaling */
            m_scale_denom = 1;
            m_buffered_image = false;
            m_raw_data_out = false;
            m_dct_method = JpegConstants.JDCT_DEFAULT;
            m_do_fancy_upsampling = true;
            m_do_block_smoothing = true;
            m_quantize_colors = false;

            /* We set these in case application only sets quantize_colors. */
            m_dither_mode = J_DITHER_MODE.JDITHER_FS;
            m_two_pass_quantize = true;
            m_desired_number_of_colors = 256;
            m_colormap = null;

            /* Initialize for no mode change in buffered-image mode. */
            m_enable_1pass_quant = false;
            m_enable_external_quant = false;
            m_enable_2pass_quant = false;
        }