Neural Quantization Class
Ejemplo n.º 1
0
        /// <summary>
        /// Analyzes image colors and creates color map.
        /// </summary>
        private void AnalyzePixels()
        {
            int len  = _pixels.Length;
            int nPix = len / 3;

            _indexedPixels = new byte[nPix];

            //Initialize quantizer.
            var nq = new NeuQuant(_pixels, len, _sample);

            //Create reduced palette.
            _colorTab = nq.Process();

            #region BGR to RGB

            for (int i = 0; i < _colorTab.Length; i += 3)
            {
                //Only swap Red with Blue. Green stays.
                byte temp = _colorTab[i];
                _colorTab[i]      = _colorTab[i + 2];
                _colorTab[i + 2]  = temp;
                _usedEntry[i / 3] = false;
            }

            #endregion

            //Map image pixels to new palette.
            int k = 0;
            _usedEntry = new bool[256];

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(
                    _pixels[k++],
                    _pixels[k++],
                    _pixels[k++]);

                _usedEntry[index] = true;
                _indexedPixels[i] = (byte)index;
            }

            _colorDepth = 8;
            _palSize    = 7;

            //Get closest match to transparent color if specified.
            if (_transparent != Color.Empty)
            {
                _transIndex = nq.Map(_transparent.B, _transparent.G, _transparent.R);
            }

            _pixels = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Analyzes image colors and creates color map.
        /// </summary>
        private void AnalyzePixels()
        {
            int len  = _pixels.Length;
            int nPix = len / 3;

            _indexedPixels = new byte[nPix];

            var nq = new NeuQuant(_pixels, len, _sample);

            //Initialize quantizer.
            _colorTab = nq.Process(); //Create reduced palette

            #region Not used

            // convert map from BGR to RGB
            //for (int i = 0; i < colorTab.Length; i += 3)
            //{
            //    byte temp = colorTab[i];
            //    colorTab[i] = colorTab[i + 2];
            //    colorTab[i + 2] = temp;
            //    usedEntry[i / 3] = false;
            //}

            #endregion

            //Map image pixels to new palette.
            int k = 0;
            _usedEntry = new bool[256]; //Here is the fix from the internet, codeproject.

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(_pixels[k++] & 0xff,
                                   _pixels[k++] & 0xff,
                                   _pixels[k++] & 0xff);

                _usedEntry[index] = true;
                _indexedPixels[i] = (byte)index;
            }

            _pixels     = null;
            _colorDepth = 8;
            _palSize    = 7;

            //Get closest match to transparent color if specified.
            if (_transparent != Color.Empty)
            {
                //_transIndex = FindClosest(_transparent);
                _transIndex = nq.Map(_transparent.B, _transparent.G, _transparent.R);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Analyzes image colors and creates color map.
        /// </summary>
        private void AnalyzePixels()
        {
            int len = _pixels.Length;
            int nPix = len / 3;
            _indexedPixels = new byte[nPix];

            var nq = new NeuQuant(_pixels, len, _sample);

            //Initialize quantizer.
            _colorTab = nq.Process(); //Create reduced palette

            #region Not used

            // convert map from BGR to RGB
            //for (int i = 0; i < colorTab.Length; i += 3)
            //{
            //    byte temp = colorTab[i];
            //    colorTab[i] = colorTab[i + 2];
            //    colorTab[i + 2] = temp;
            //    usedEntry[i / 3] = false;
            //}

            #endregion

            //Map image pixels to new palette.
            int k = 0;
            _usedEntry = new bool[256]; //Here is the fix from the internet, codeproject.

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(_pixels[k++] & 0xff,
                    _pixels[k++] & 0xff,
                    _pixels[k++] & 0xff);

                _usedEntry[index] = true;
                _indexedPixels[i] = (byte)index;
            }

            _pixels = null;
            _colorDepth = 8;
            _palSize = 7;

            //Get closest match to transparent color if specified.
            if (_transparent != Color.Empty)
            {
                //_transIndex = FindClosest(_transparent);
                _transIndex = nq.Map(_transparent.B, _transparent.G, _transparent.R);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Analyzes image colors and creates color map.
        /// </summary>
        private void AnalyzePixels()
        {
            int len = _pixels.Length;
            int nPix = len / 3;
            _indexedPixels = new byte[nPix];

            //Initialize quantizer.
            var nq = new NeuQuant(_pixels, len, _sample);
            //Create reduced palette.
            _colorTab = nq.Process(); 

            #region BGR to RGB

            for (int i = 0; i < _colorTab.Length; i += 3)
            {
                //Only swap Red with Blue. Green stays.
                byte temp = _colorTab[i];
                _colorTab[i] = _colorTab[i + 2];
                _colorTab[i + 2] = temp;
                _usedEntry[i / 3] = false;
            }

            #endregion

            //Map image pixels to new palette.
            int k = 0;
            _usedEntry = new bool[256];

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(
                    _pixels[k++],
                    _pixels[k++],
                    _pixels[k++]);

                _usedEntry[index] = true;
                _indexedPixels[i] = (byte)index;
            }

            _colorDepth = 8;
            _palSize = 7;

            //Get closest match to transparent color if specified.
            if (_transparent != Color.Empty)
            {
                _transIndex = nq.Map(_transparent.B, _transparent.G, _transparent.R);
            }

            _pixels = null;
        }