コード例 #1
0
ファイル: GifFile.cs プロジェクト: rob3c/ScreenToGif
        private byte[] IndexPixels(List <Color> palette)
        {
            var pixels = new byte[NonIndexedPixels.Count];

            //TODO: Parallel foreach.
            int pixelCount = 0;

            foreach (Color color in NonIndexedPixels)
            {
                var index = palette.IndexOf(color);

                if (index == -1)
                {
                    //Search for nearby colors.
                    index = ColorExtensions.ClosestColorRgb(palette, color);
                    //index = ColorExtensions.ClosestColorHue(palette, color);
                    //index = ColorExtensions.ClosestColorRsb(palette, color);

                    //Add colors to a dictionary, if available, no need to search.
                    //TODO: Make this available for choice.
                }

                //Map the pixel to a color in the Color Table.
                pixels[pixelCount] = (byte)index;
                pixelCount++;
            }

            return(pixels);
        }
コード例 #2
0
        private byte[] IndexPixels(List <Color> palette)
        {
            return(NonIndexedPixels.AsParallel().Select((x, i) => new { Index = i, Indexed = (byte)ColorExtensions.ClosestColorRgb(palette, x) }).Select(x => x.Indexed).ToArray());

            #region Old code

            //var pixels = new byte[NonIndexedPixels.Count];
            //var pixelCount = 0;
            //foreach (var color in NonIndexedPixels)
            //{
            //    var index = palette.IndexOf(color);

            //    if (index == -1)
            //    {
            //        //Search for nearby colors.
            //        index = ColorExtensions.ClosestColorRgb(palette, color);
            //        //index = ColorExtensions.ClosestColorHue(palette, color);
            //        //index = ColorExtensions.ClosestColorRsb(palette, color);

            //        //Add colors to a dictionary, if available, no need to search.
            //        //TODO: Make this available for choice.
            //    }

            //    //Map the pixel to a color in the Color Table.
            //    pixels[pixelCount] = (byte)index;
            //    pixelCount++;
            //}

            //return pixels;

            #endregion
        }