コード例 #1
0
        // Maps image colors to the color map
        protected void AnalyzePixels()
        {
            int len  = m_Pixels.Length;
            int nPix = len / 3;

            m_IndexedPixels = new byte[nPix];
            // Analyze image colors and create color map (original, expensive, Moments Recorder behaviour)
            if (m_FramesPerColorSample == 0)
            {
                nq         = new NeuQuant(m_Pixels, len, (int)m_SampleInterval);
                m_ColorTab = nq.Process();                 // Create reduced palette
            }
            // Map image pixels to new palette
            int k = 0;

            for (int i = 0; i < nPix; i++)
            {
                int index = nq.Map(m_Pixels[k++] & 0xff, m_Pixels[k++] & 0xff, m_Pixels[k++] & 0xff);
                m_UsedEntry[index] = true;
                m_IndexedPixels[i] = (byte)index;
            }

            m_Pixels      = null;
            m_ColorDepth  = 8;
            m_PaletteSize = 7;
        }
コード例 #2
0
        /// <summary>
        /// Builds a colour map out of the combined colours from several frames.
        /// </summary>
        /// <param name="frames">List of frames to sample colour palette from</param>
        public void BuildPalette(ref FixedSizedQueue <GifFrame> frames)
        {
            // Do not build the color palette here if user wants separate palettes created per frame
            if (m_FramesPerColorSample == 0)
            {
                return;
            }

            GifFrame frame = frames.ElementAt(0);

            // Initialize a large image
            Byte[] combinedPixels = new Byte[3 * frame.Width * frame.Height * (1 + frames.Count() / m_FramesPerColorSample)];
            int    count          = 0;

            // Stich the large image together out of pixels from several frames
            for (int i = 0; i < frames.Count(); i += m_FramesPerColorSample)
            {
                frame = frames.ElementAt(0);
                Color32[] p = frame.Data;
                // Texture data is layered down-top, so flip it
                for (int th = frame.Height - 1; th >= 0; th--)
                {
                    for (int tw = 0; tw < frame.Width; tw++)
                    {
                        Color32 color = p[th * frame.Width + tw];
                        combinedPixels[count] = color.r; count++;
                        combinedPixels[count] = color.g; count++;
                        combinedPixels[count] = color.b; count++;
                    }
                }
            }
            // Run the quantizer over our stitched together image and create reduced palette
            nq         = new NeuQuant(combinedPixels, combinedPixels.Length, (int)m_SampleInterval);
            m_ColorTab = nq.Process();
        }