BitMiracle.LibJpeg.Classic.Internal.my_2pass_cquantizer.my_2pass_cquantizer C# (CSharp) Method

my_2pass_cquantizer() public method

Module initialization routine for 2-pass color quantization.
public my_2pass_cquantizer ( jpeg_decompress_struct cinfo ) : System
cinfo jpeg_decompress_struct
return System
        public my_2pass_cquantizer(jpeg_decompress_struct cinfo)
        {
            m_cinfo = cinfo;

            /* Make sure jdmaster didn't give me a case I can't handle */
            if (cinfo.m_out_color_components != 3)
                cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NOTIMPL);

            /* Allocate the histogram/inverse colormap storage */
            m_histogram = new ushort[HIST_C0_ELEMS][];
            for (int i = 0; i < HIST_C0_ELEMS; i++)
                m_histogram[i] = new ushort[HIST_C1_ELEMS * HIST_C2_ELEMS];

            m_needs_zeroed = true; /* histogram is garbage now */

            /* Allocate storage for the completed colormap, if required.
            * We do this now since it is FAR storage and may affect
            * the memory manager's space calculations.
            */
            if (cinfo.m_enable_2pass_quant)
            {
                /* Make sure color count is acceptable */
                int desired_local = cinfo.m_desired_number_of_colors;

                /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
                if (desired_local < 8)
                    cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_FEW_COLORS, 8);

                /* Make sure colormap indexes can be represented by JSAMPLEs */
                if (desired_local > MAXNUMCOLORS)
                    cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);

                m_sv_colormap = jpeg_common_struct.AllocJpegSamples(desired_local, 3);
                m_desired = desired_local;
            }

            /* Only F-S dithering or no dithering is supported. */
            /* If user asks for ordered dither, give him F-S. */
            if (cinfo.m_dither_mode != J_DITHER_MODE.JDITHER_NONE)
                cinfo.m_dither_mode = J_DITHER_MODE.JDITHER_FS;

            /* Allocate Floyd-Steinberg workspace if necessary.
            * This isn't really needed until pass 2, but again it is FAR storage.
            * Although we will cope with a later change in dither_mode,
            * we do not promise to honor max_memory_to_use if dither_mode changes.
            */
            if (cinfo.m_dither_mode == J_DITHER_MODE.JDITHER_FS)
            {
                m_fserrors = new short[(cinfo.m_output_width + 2) * 3];

                /* Might as well create the error-limiting table too. */
                init_error_limit();
            }
        }