예제 #1
0
        protected void AnalyzePixels()
        {
            int len  = this.pixels.Length;
            int nPix = len / 3;

            this.indexedPixels = new byte[nPix];
            NeuQuant nq = new NeuQuant(this.pixels, len, this.sample);

            // initialize quantizer
            this.colorTab = nq.Process(); // create reduced palette
            int k = 0;

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(this.pixels[k++] & 0xff, this.pixels[k++] & 0xff, this.pixels[k++] & 0xff);
                this.usedEntry[index] = true;
                this.indexedPixels[i] = (byte)index;
            }
            this.pixels     = null;
            this.colorDepth = 8;
            this.palSize    = 7;
            // get closest match to transparent color if specified
            if (this.transparent != Color.Empty)
            {
                this.transIndex = this.FindClosest(this.transparent);
            }
        }
예제 #2
0
        /**
         * Analyzes image colors and creates color map.
         */

        protected void AnalyzePixels()
        {
            int len  = this.pixels.Length;
            int nPix = len / 3;

            this.indexedPixels = new byte[nPix];
            NeuQuant nq = new NeuQuant(this.pixels, len, this.sample);

            // initialize quantizer
            this.colorTab = nq.Process(); // create reduced palette
            // 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;
            //			}
            // map image pixels to new palette
            int k = 0;

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(this.pixels[k++] & 0xff, this.pixels[k++] & 0xff, this.pixels[k++] & 0xff);
                this.usedEntry[index] = true;
                this.indexedPixels[i] = (byte)index;
            }
            this.pixels     = null;
            this.colorDepth = 8;
            this.palSize    = 7;
            // get closest match to transparent color if specified
            if (this.transparent != Color.Empty)
            {
                this.transIndex = this.FindClosest(this.transparent);
            }
        }