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

jpeg_set_defaults() public method

Jpeg_set_defaultses this instance.
Uses only the input image's color space (property jpeg_compress_struct.In_color_space, which must already be set in jpeg_compress_struct). Many applications will only need to use this routine and perhaps jpeg_compress_struct.jpeg_set_quality.
public jpeg_set_defaults ( ) : void
return void
        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 */
            scale_num = 1;       /* 1:1 scaling */
            scale_denom = 1;
            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;

            /* The standard Huffman tables are only valid for 8-bit data precision.
             * If the precision is higher, use arithmetic coding.
             * (Alternatively, using Huffman coding would be possible with forcing
             * optimization on so that usable tables will be computed, or by
             * supplying default tables that are valid for the desired precision.)
             * Otherwise, use Huffman coding by default.
             */
            arith_code = (m_data_precision > 8);

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

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

            /* By default, apply fancy downsampling */
            do_fancy_downsampling = true;

            /* 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.
            *
            * For wide gamut colorspaces (BG_RGB and BG_YCC), the major version will be
            * overridden by jpeg_set_colorspace and set to 2.
            */
            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;

            /* No color transform */
            color_transform = J_COLOR_TRANSFORM.JCT_NONE;

            /* Choose JPEG colorspace based on input space, set defaults accordingly */
            jpeg_default_colorspace();
        }

Usage Example

        private static void compress(Stream input, CompressOptions options, Stream output)
        {
            Debug.Assert(input != null);
            Debug.Assert(options != null);
            Debug.Assert(output != null);

            jpeg_compress_struct cinfo = new jpeg_compress_struct(new cd_jpeg_error_mgr());

            /* Initialize JPEG parameters.
             * Much of this may be overridden later.
             * In particular, we don't yet know the input file's color space,
             * but we need to provide some value for jpeg_set_defaults() to work.
             */
            cinfo.In_color_space = J_COLOR_SPACE.JCS_RGB; /* arbitrary guess */
            cinfo.jpeg_set_defaults();

            /* Figure out the input file format, and set up to read it. */
            cjpeg_source_struct src_mgr = new bmp_source_struct(cinfo);
            src_mgr.input_file = input;

            /* Read the input file header to obtain file size & colorspace. */
            src_mgr.start_input();

            /* Now that we know input colorspace, fix colorspace-dependent defaults */
            cinfo.jpeg_default_colorspace();

            /* Adjust default compression parameters */
            if (!applyOptions(cinfo, options))
                return;

            /* Specify data destination for compression */
            cinfo.jpeg_stdio_dest(output);

            /* Start compressor */
            cinfo.jpeg_start_compress(true);

            /* Process data */
            while (cinfo.Next_scanline < cinfo.Image_height)
            {
                int num_scanlines = src_mgr.get_pixel_rows();
                cinfo.jpeg_write_scanlines(src_mgr.buffer, num_scanlines);
            }

            /* Finish compression and release memory */
            src_mgr.finish_input();
            cinfo.jpeg_finish_compress();

            /* All done. */
            if (cinfo.Err.Num_warnings != 0)
                Console.WriteLine("Corrupt-data warning count is not zero");
        }
All Usage Examples Of BitMiracle.LibJpeg.Classic.jpeg_compress_struct::jpeg_set_defaults