Beispiel #1
0
 public GfxImage(Byte[] buffer, Palette palette, int paletteOffset)
 {
     this.buffer        = buffer;
     this.palette       = palette;
     this.paletteOffset = paletteOffset;
 }
Beispiel #2
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));
                    value = Math.Max((byte)paletteOffset + 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 += count * 4;
                    i           = offset;
                    dataLength += 1;
                }
            }

            return(newData.ToArray());
            //while (j < length) {
            //	int value = pos >= buffer.Length ? 0 : buffer[pos];
            //	pos++;

            //	UInt32 color;
            //	int count = 1;

            //	if (value <= 1) {
            //		count = pos >= buffer.Length ? 1 : buffer[pos];
            //		pos++;

            //		if (value == 0) {
            //			color = 0xFF0000FF;
            //		} else {
            //			color = 0xFF00FF00;
            //		}
            //	} else {
            //		color = palette.GetColor(paletteOffset + value);
            //	}

            //	for (int i = 0; (i < count) && (j < length); i++) {
            //		imgData[j++] = color;
            //	}
            //}
        }