public byte GetResultingColorIndex(byte overlaying, byte underlaying, TransparencyType type) { switch(type) { case TransparencyType.None: return overlaying; case TransparencyType.Dark: return dark[underlaying*256+overlaying]; case TransparencyType.Main: return main[underlaying*256+overlaying]; case TransparencyType.Light: return light[underlaying*256+overlaying]; default: throw new ArgumentException("Unknown type.", "type"); } }
private void ApplyBake(byte[] tobake) { int width = Background.GetWidth(); int height = Background.GetHeight(); TransparencyTable trans = TransparencyTable; foreach (GraphicObject obj in Objects) { if (obj == null || obj.Image == null) { continue; } for (int y = 0; y < obj.Image.GetHeight(); y++) { for (int x = 0; x < obj.Image.GetWidth(); x++) { if (x + obj.Location.X >= 0 && y + obj.Location.Y >= 0 && x + obj.Location.X < width && y + obj.Location.Y < height) { byte color = obj.Image.ImageData[obj.Image.GetWidth() * y + x]; if (color == obj.TransparentIndex) { continue; } int index = width * (y + obj.Location.Y) + obj.Location.X + x; if (trans == null || obj.Transparency == TransparencyType.None) { tobake[index] = color; } else { tobake[index] = trans.GetResultingColorIndex(color, tobake[index], obj.Transparency); } } } } } }