Esempio n. 1
0
        public static List <int> Compress(Color[,] colors, Color[] table, int tableSize)
        {
            List <int> codeStream = new List <int>();

            List <int> indexStream = colors.Cast <Color>()
                                     .Select(x => Array.FindIndex(table, y =>
                                                                  y.B == x.B &&
                                                                  y.R == x.R &&
                                                                  y.G == x.G)).ToList();

            Initialize(tableSize);

            codeStream.Add(tableSize);

            List <int> buffer = new List <int>()
            {
                indexStream[0]
            };

            for (int i = 1; i < indexStream.Count; i++)
            {
                List <int> code = new List <int>()
                {
                    indexStream[i]
                };

                List <int> bufferWithCode = buffer.Concat(code).ToList();

                if (_dictionary.Values.Any(x => x.SequenceEqual(bufferWithCode)))
                {
                    buffer = bufferWithCode;
                }
                else
                {
                    _dictionary.Add(_dictionary.Count, bufferWithCode);
                    codeStream.Add(GetCode(buffer));

                    if (_dictionary.Count == MaxDictionarySize)
                    {
                        Initialize(tableSize);
                        codeStream.Add(tableSize);
                        buffer = new List <int>()
                        {
                            indexStream[i]
                        };
                        continue;
                    }
                    buffer = code;
                }
            }

            codeStream.Add(GetCode(buffer));
            codeStream.Add(_dictionary[tableSize + 1].First());

            return(codeStream);
        }
Esempio n. 2
0
 private static Color[] GetTable(Color[,] colors)
 {
     Color[] result = colors.Cast <Color>().ToArray();
     return(result.GroupBy(x => new { x.R, x.G, x.B })
            .Select(x => new Color()
     {
         R = x.Key.R,
         G = x.Key.G,
         B = x.Key.B
     }).ToArray());
 }
Esempio n. 3
0
 public Color CalculateAverageColorArr(Color[,] colors)
 {
     return(CalculateAverageColor(colors.Cast <Color>()));
 }
Esempio n. 4
0
 public override int GetHashCode()
 {
     return(Utils.GetHashCode(Position.Concat(Colors.Cast <int>())));
 }