コード例 #1
0
        void RemapPixels()
        {
            int len = pixels.Length;

            indexedPixels = new byte[len];

            if (firstFrame || !useGlobalColorTable)
            {
                // initialize quantizer
                nq       = new NeuQuant(pixels, len, quality);
                colorTab = nq.Process();                 // create reduced palette
            }

            for (int i = 0; i < len; i++)
            {
                int index = nq.Map(pixels[i].r & 0xff, pixels[i].g & 0xff, pixels[i].b & 0xff);
                usedEntry[index] = true;
                indexedPixels[i] = (byte)index;

                if (dispose == 1 && prevIndexedPixels != null)
                {
                    if (indexedPixels[i] == prevIndexedPixels[i])
                    {
                        indexedPixels[i] = (byte)transIndex;
                    }
                    else
                    {
                        prevIndexedPixels[i] = (byte)index;
                    }
                }
            }
            colorDepth = 8;
            palSize    = 7;
            // get closest match to transparent color if specified
            if (transparent.HasValue)
            {
                var c = transparent.Value;
                //transIndex = FindClosest(transparent);
                transIndex = nq.Map(c.b, c.g, c.r);
            }

            if (dispose == 1 && prevIndexedPixels == null)
            {
                prevIndexedPixels = indexedPixels.Clone() as byte[];
            }
        }
コード例 #2
0
ファイル: GIFEncoder.cs プロジェクト: simonwittber/uGIF
        public void Finish()
        {
            if (!started)
                throw new InvalidOperationException ("Start() must be called before Finish()");

            started = false;

            ms.WriteByte (0x3b); // gif trailer
            ms.Flush ();

            // reset for subsequent use
            transIndex = 0;
            pixels = null;
            indexedPixels = null;
            prevIndexedPixels = null;
            colorTab = null;
            firstFrame = true;
            nq = null;
        }
コード例 #3
0
ファイル: GIFEncoder.cs プロジェクト: simonwittber/uGIF
        void RemapPixels()
        {
            int len = pixels.Length;
            indexedPixels = new byte[len];

            if (firstFrame || !useGlobalColorTable) {
                // initialize quantizer
                nq = new NeuQuant (pixels, len, quality);
                colorTab = nq.Process (); // create reduced palette
            }

            for (int i = 0; i < len; i++) {
                int index = nq.Map (pixels [i].r & 0xff, pixels [i].g & 0xff, pixels [i].b & 0xff);
                usedEntry [index] = true;
                indexedPixels [i] = (byte)index;

                if (dispose == 1 && prevIndexedPixels != null) {
                    if (indexedPixels [i] == prevIndexedPixels [i]) {
                        indexedPixels [i] = (byte)transIndex;
                    } else {
                        prevIndexedPixels [i] = (byte)index;
                    }
                }
            }
            colorDepth = 8;
            palSize = 7;
            // get closest match to transparent color if specified
            if (transparent.HasValue) {
                var c = transparent.Value;
                //transIndex = FindClosest(transparent);
                transIndex = nq.Map (c.b, c.g, c.r);
            }

            if (dispose == 1 && prevIndexedPixels == null)
                prevIndexedPixels = indexedPixels.Clone () as byte[];
        }