示例#1
0
 public Palette(Palette copy)
 {
     palette = (uint[])copy.palette.Clone();
 }
示例#2
0
 public GfxImage(byte[] buffer, Palette palette, int paletteOffset)
 {
     this.buffer        = buffer;
     this.palette       = palette;
     this.paletteOffset = paletteOffset;
 }
示例#3
0
        private byte[] CreateImageDataWithRunLengthEncoding(byte[] data, int length)
        {
            List <byte> newData = new List <byte>();

            int dataLength = 0;

            for (int i = 0; i < length; i += 4)
            {
                int value = 0;

                byte red   = data[i + 0];
                byte green = data[i + 1];
                byte blue  = data[i + 2];
                byte alpha = data[i + 3];

                bool valueIsOperator = false;

                if (red == 255 && green + blue == 0)
                {
                    value           = 0;//transparent
                    valueIsOperator = true;
                }
                else if (green == 255 && red + blue == 0)
                {
                    value           = 1;//shadow
                    valueIsOperator = true;
                }
                else
                {
                    value = palette.GetIndex(paletteOffset, Palette.RGBToPalette(red, green, blue));
                    if (value == -1)
                    {
                        Console.WriteLine($"Invalid color - not found in the palette! Color: R:{red}, G:{green}, B:{blue}");
                    }

                    value = value - paletteOffset;

                    if (value >= 252)
                    {
                        Console.WriteLine("Invalid color - not found in the palette!");
                    }

                    value = Math.Max((byte)2, (byte)value);
                }
                int count = 1;

                newData.Add((byte)value);
                dataLength += 1;

                if (valueIsOperator == true)
                {
                    int offset = 0;
                    count = GetSameValueCount(ref data, i, value, ref offset);
                    newData.Add((byte)count);

                    i           = offset;
                    dataLength += 1;
                }
            }

            return(newData.ToArray());
        }