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

jpeg_default_colorspace() public method

Select an appropriate JPEG colorspace based on jpeg_compress_struct.In_color_space, and calls jpeg_compress_struct.jpeg_set_colorspace
This is actually a subroutine of jpeg_set_defaults. It's broken out in case you want to change just the colorspace-dependent JPEG parameters.
public jpeg_default_colorspace ( ) : void
return void
        public void jpeg_default_colorspace()
        {
            switch (m_in_color_space)
            {
                case J_COLOR_SPACE.JCS_UNKNOWN:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_UNKNOWN);
                    break;

                case J_COLOR_SPACE.JCS_GRAYSCALE:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_GRAYSCALE);
                    break;
                case J_COLOR_SPACE.JCS_RGB:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_YCbCr);
                    break;
                case J_COLOR_SPACE.JCS_YCbCr:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_YCbCr);
                    break;
                case J_COLOR_SPACE.JCS_CMYK:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_CMYK); /* By default, no translation */
                    break;
                case J_COLOR_SPACE.JCS_YCCK:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_YCCK);
                    break;
                case J_COLOR_SPACE.JCS_BG_RGB:
                    /* No translation for now -- conversion to BG_YCC not yet supportet */
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_BG_RGB);
                    break;
                case J_COLOR_SPACE.JCS_BG_YCC:
                    jpeg_set_colorspace(J_COLOR_SPACE.JCS_BG_YCC);
                    break;
                default:
                    ERREXIT(J_MESSAGE_CODE.JERR_BAD_IN_COLORSPACE);
                    break;
            }
        }

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_default_colorspace