Beispiel #1
0
            public void Set(Color c, Action <PixelData> func)
            {
                queue.Add(c);
                if (queue.Count == 16)
                {
                    var colorsWindows = Enumerable.Range(0, 16).Select(j => queue[order3ds[order3ds[order3ds[j]]]]);                     // invert order3ds
                    var alpha         = colorsWindows.Reverse().Aggregate(0ul, (a, b) => (a * 16) | (byte)(b.A / 16));
                    var colors        = colorsWindows.Select(c2 => new RGB(c2.R, c2.G, c2.B)).ToList();

                    Block block;
                    // special case 1: this block has all 16 pixels exactly the same color
                    if (colors.All(color => color == colors[0]))
                    {
                        block = PackSolidColor(colors[0]);
                    }
                    // special case 2: this block was previously etc1-compressed
                    else if (!Optimizer.RepackEtc1CompressedBlock(colors, out block))
                    {
                        block = Optimizer.Encode(colors);
                    }

                    func(new PixelData {
                        Alpha = alpha, Block = block
                    });
                    queue.Clear();
                }
            }
Beispiel #2
0
        public Etc1PixelData EncodeColors(IList <Color> colorBatch)
        {
            var colorsWindows = Enumerable.Range(0, 16).Select(j => _zOrdered ?
                                                               colorBatch[Constants.ZOrder[Constants.ZOrder[Constants.ZOrder[j]]]] :
                                                               colorBatch[Constants.NormalOrder[j]]).ToArray();

            var alpha  = colorsWindows.Reverse().Aggregate(0ul, (a, b) => (a * 16) | (byte)(b.A / 16));
            var colors = colorsWindows.Select(c2 => new RGB(c2.R, c2.G, c2.B)).ToList();

            Block block;

            // special case 1: this block has all 16 pixels exactly the same color
            if (colors.All(color => color == colors[0]))
            {
                block = PackSolidColor(colors[0]);
            }
            // special case 2: this block was previously etc1-compressed
            else if (!Optimizer.RepackEtc1CompressedBlock(colors, out block))
            {
                block = Optimizer.Encode(colors);
            }

            return(new Etc1PixelData {
                Alpha = alpha, Block = block
            });
        }