Beispiel #1
0
        private void TestSingleImage(int numberOfColours, QuantizerType qt)
        {
            Bitmap image = MakeBitmap(numberOfColours);

            _pa = new PixelAnalysis(image, qt);
            _pa.Analyse();
            CheckColourTable(numberOfColours);
            CheckIndexedPixels(numberOfColours);
        }
Beispiel #2
0
 public Quantize(float start, float end, int samples, QuantizerType type = QuantizerType.Clamp)
 {
     Start     = start;
     End       = end;
     Range     = End - Start;
     Samples   = samples;
     Increment = Range / Samples;
     Type      = type;
 }
 /// <summary>
 /// Default constructor.
 /// Sets repeat count to 0 (repeat indefinitely)
 /// Sets colour table strategy to UseGlobal
 /// Sets image quantization quality to 10.
 /// Sets quantizer type to NeuQuant.
 /// Screen size defaults to size of first frame.
 /// </summary>
 public AnimatedGifEncoder()
 {
     _frames            = new Collection <GifFrame>();
     _strategy          = ColourTableStrategy.UseGlobal;
     _quality           = 10;
     _quantizerType     = QuantizerType.NeuQuant;
     _logicalScreenSize = Size.Empty;
     _palette           = new Palette();
 }
        public PixelAnalysis(Image imageToStudy, QuantizerType quantizerType)
        {
            _imageToStudy  = imageToStudy;
            _colourQuality = 10;
            _quantizerType = quantizerType;
            GetColours(imageToStudy);

            if (_distinctColours.Count > 256)
            {
                switch (quantizerType)
                {
                case QuantizerType.NeuQuant:
                    break;

                case QuantizerType.Octree:
                    _oq = new OctreeQuantizer(255, 8);
                    // TODO: progress counters for Octree
                    break;
                }
            }
        }
Beispiel #5
0
		public PixelAnalysis( Image imageToStudy, QuantizerType quantizerType )
		{
			_imageToStudy = imageToStudy;
			_colourQuality = 10;
			_quantizerType = quantizerType;
			GetColours( imageToStudy );
			
			if( _distinctColours.Count > 256 )
			{
				switch( quantizerType )
				{
					case QuantizerType.NeuQuant:
						break;
						
					case QuantizerType.Octree:
						_oq = new OctreeQuantizer( 255, 8 );
						// TODO: progress counters for Octree
						break;
				}
			}
		}
        /// <summary>
        /// Initialize for each processing pass.
        /// </summary>
        public virtual void start_pass(bool is_pre_scan)
        {
            /* Only F-S dithering or no dithering is supported. */
            /* If user asks for ordered dither, give him F-S. */
            if (m_cinfo.m_dither_mode != J_DITHER_MODE.JDITHER_NONE)
                m_cinfo.m_dither_mode = J_DITHER_MODE.JDITHER_FS;

            if (is_pre_scan)
            {
                /* Set up method pointers */
                m_quantizer = QuantizerType.prescan_quantizer;
                m_useFinishPass1 = true;
                m_needs_zeroed = true; /* Always zero histogram */
            }
            else
            {
                /* Set up method pointers */
                if (m_cinfo.m_dither_mode == J_DITHER_MODE.JDITHER_FS)
                    m_quantizer = QuantizerType.pass2_fs_dither_quantizer;
                else
                    m_quantizer = QuantizerType.pass2_no_dither_quantizer;

                m_useFinishPass1 = false;

                /* Make sure color count is acceptable */
                int i = m_cinfo.m_actual_number_of_colors;
                if (i < 1)
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_FEW_COLORS, 1);

                if (i > MAXNUMCOLORS)
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);

                if (m_cinfo.m_dither_mode == J_DITHER_MODE.JDITHER_FS)
                {
                    /* Allocate Floyd-Steinberg workspace if we didn't already. */
                    if (m_fserrors == null)
                    {
                        int arraysize = (m_cinfo.m_output_width + 2) * 3;
                        m_fserrors = new short[arraysize];
                    }
                    else
                    {
                        /* Initialize the propagated errors to zero. */
                        Array.Clear(m_fserrors, 0, m_fserrors.Length);
                    }

                    /* Make the error-limit table if we didn't already. */
                    if (m_error_limiter == null)
                        init_error_limit();

                    m_on_odd_row = false;
                }
            }

            /* Zero the histogram or inverse color map, if necessary */
            if (m_needs_zeroed)
            {
                for (int i = 0; i < HIST_C0_ELEMS; i++)
                    Array.Clear(m_histogram[i], 0, m_histogram[i].Length);

                m_needs_zeroed = false;
            }
        }
 private void TestSingleImage( int numberOfColours, QuantizerType qt )
 {
     Bitmap image = MakeBitmap( numberOfColours );
     _pa = new PixelAnalysis( image, qt );
     _pa.Analyse();
     CheckColourTable( numberOfColours );
     CheckIndexedPixels( numberOfColours );
 }
        /// <summary>
        /// Initialize for one-pass color quantization.
        /// </summary>
        public virtual void start_pass(bool is_pre_scan)
        {
            /* Install my colormap. */
            m_cinfo.m_colormap = m_sv_colormap;
            m_cinfo.m_actual_number_of_colors = m_sv_actual;

            /* Initialize for desired dithering mode. */
            switch (m_cinfo.m_dither_mode)
            {
                case J_DITHER_MODE.JDITHER_NONE:
                    if (m_cinfo.m_out_color_components == 3)
                        m_quantizer = QuantizerType.color_quantizer3;
                    else
                        m_quantizer = QuantizerType.color_quantizer;

                    break;
                case J_DITHER_MODE.JDITHER_ORDERED:
                    if (m_cinfo.m_out_color_components == 3)
                        m_quantizer = QuantizerType.quantize3_ord_dither_quantizer;
                    else
                        m_quantizer = QuantizerType.quantize3_ord_dither_quantizer;

                    /* initialize state for ordered dither */
                    m_row_index = 0;

                    /* If user changed to ordered dither from another mode,
                     * we must recreate the color index table with padding.
                     * This will cost extra space, but probably isn't very likely.
                     */
                    if (!m_is_padded)
                        create_colorindex();

                    /* Create ordered-dither tables if we didn't already. */
                    if (m_odither[0] == null)
                        create_odither_tables();

                    break;
                case J_DITHER_MODE.JDITHER_FS:
                    m_quantizer = QuantizerType.quantize_fs_dither_quantizer;

                    /* initialize state for F-S dither */
                    m_on_odd_row = false;

                    /* Allocate Floyd-Steinberg workspace if didn't already. */
                    if (m_fserrors[0] == null)
                        alloc_fs_workspace();

                    /* Initialize the propagated errors to zero. */
                    int arraysize = m_cinfo.m_output_width + 2;
                    for (int i = 0; i < m_cinfo.m_out_color_components; i++)
                        Array.Clear(m_fserrors[i], 0, arraysize);

                    break;
                default:
                    m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NOT_COMPILED);
                    break;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Initialize for one-pass color quantization.
        /// </summary>
        public virtual void start_pass(bool is_pre_scan)
        {
            /* Install my colormap. */
            m_cinfo.m_colormap = m_sv_colormap;
            m_cinfo.m_actual_number_of_colors = m_sv_actual;

            /* Initialize for desired dithering mode. */
            switch (m_cinfo.m_dither_mode)
            {
            case J_DITHER_MODE.JDITHER_NONE:
                if (m_cinfo.m_out_color_components == 3)
                {
                    m_quantizer = QuantizerType.color_quantizer3;
                }
                else
                {
                    m_quantizer = QuantizerType.color_quantizer;
                }

                break;

            case J_DITHER_MODE.JDITHER_ORDERED:
                if (m_cinfo.m_out_color_components == 3)
                {
                    m_quantizer = QuantizerType.quantize3_ord_dither_quantizer;
                }
                else
                {
                    m_quantizer = QuantizerType.quantize3_ord_dither_quantizer;
                }

                /* initialize state for ordered dither */
                m_row_index = 0;

                /* If user changed to ordered dither from another mode,
                 * we must recreate the color index table with padding.
                 * This will cost extra space, but probably isn't very likely.
                 */
                if (!m_is_padded)
                {
                    create_colorindex();
                }

                /* Create ordered-dither tables if we didn't already. */
                if (m_odither[0] == null)
                {
                    create_odither_tables();
                }

                break;

            case J_DITHER_MODE.JDITHER_FS:
                m_quantizer = QuantizerType.quantize_fs_dither_quantizer;

                /* initialize state for F-S dither */
                m_on_odd_row = false;

                /* Allocate Floyd-Steinberg workspace if didn't already. */
                if (m_fserrors[0] == null)
                {
                    alloc_fs_workspace();
                }

                /* Initialize the propagated errors to zero. */
                int arraysize = m_cinfo.m_output_width + 2;
                for (int i = 0; i < m_cinfo.m_out_color_components; i++)
                {
                    Array.Clear(m_fserrors[i], 0, arraysize);
                }

                break;

            default:
                m_cinfo.ERREXIT(J_MESSAGE_CODE.JERR_NOT_COMPILED);
                break;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initialize for one-pass color quantization.
        /// </summary>
        public virtual void StartPass(bool is_pre_scan)
        {
            /* Install my colormap. */
            m_cinfo.m_colormap       = m_sv_colormap;
            m_cinfo.actualColorCount = m_sv_actual;

            /* Initialize for desired dithering mode. */
            switch (m_cinfo.ditherMode)
            {
            case JDitherMode.JDITHER_NONE:
                if (m_cinfo.outColorComponents == 3)
                {
                    m_quantizer = QuantizerType.color_quantizer3;
                }
                else
                {
                    m_quantizer = QuantizerType.color_quantizer;
                }

                break;

            case JDitherMode.JDITHER_ORDERED:
                if (m_cinfo.outColorComponents == 3)
                {
                    m_quantizer = QuantizerType.quantize3_ord_dither_quantizer;
                }
                else
                {
                    m_quantizer = QuantizerType.quantize_ord_dither_quantizer;
                }

                /* initialize state for ordered dither */
                m_row_index = 0;

                /* If user changed to ordered dither from another mode,
                 * we must recreate the color index table with padding.
                 * This will cost extra space, but probably isn't very likely.
                 */
                if (!m_is_padded)
                {
                    CreateColorIndex();
                }

                /* Create ordered-dither tables if we didn't already. */
                if (m_odither[0] is null)
                {
                    CreateODitherTable();
                }

                break;

            case JDitherMode.JDITHER_FS:
                m_quantizer = QuantizerType.quantize_fs_dither_quantizer;

                /* initialize state for F-S dither */
                m_on_odd_row = false;

                /* Allocate Floyd-Steinberg workspace if didn't already. */
                if (m_fserrors[0] is null)
                {
                    AllocFsWorkspace();
                }

                /* Initialize the propagated errors to zero. */
                var arraysize = m_cinfo.outputWidth + 2;
                for (var i = 0; i < m_cinfo.outColorComponents; i++)
                {
                    Array.Clear(m_fserrors[i], 0, arraysize);
                }

                break;

            default:
                m_cinfo.ErrExit(JMessageCode.JERR_NOT_COMPILED);
                break;
            }
        }
Beispiel #11
0
 /// <summary>
 /// Constructor.
 /// Be sure to call the Analyse method after calling the constructor.
 /// </summary>
 /// <param name="imagesToStudy">
 /// The images for which to analyse the pixels.
 /// </param>
 public PixelAnalysis(Collection <Image> imagesToStudy)
 {
     _imagesToStudy = imagesToStudy;
     _colourQuality = 10;
     _quantizerType = QuantizerType.NeuQuant;
 }
Beispiel #12
0
		/// <summary>
		/// Constructor.
		/// Be sure to call the Analyse method after calling the constructor.
		/// </summary>
		/// <param name="imagesToStudy">
		/// The images for which to analyse the pixels.
		/// </param>
		public PixelAnalysis( Collection<Image> imagesToStudy ) 
		{
			_imagesToStudy = imagesToStudy;
			_colourQuality = 10;
			_quantizerType = QuantizerType.NeuQuant;
		}
Beispiel #13
0
		/// <summary>
		/// Default constructor.
		/// Sets repeat count to 0 (repeat indefinitely)
		/// Sets colour table strategy to UseGlobal
		/// Sets image quantization quality to 10.
		/// Sets quantizer type to NeuQuant.
		/// Screen size defaults to size of first frame.
		/// </summary>
		public AnimatedGifEncoder()
		{
			_frames = new Collection<GifFrame>();
			_strategy = ColourTableStrategy.UseGlobal;
			_quality = 10;
			_quantizerType = QuantizerType.NeuQuant;
			_logicalScreenSize = Size.Empty;
			_palette = new Palette();
		}