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); } } } } } }
/// <summary> /// Loads transparency table for palette. /// </summary> /// <param name="palette"> /// One-based palette index. /// </param> /// <returns> /// Assigned transparency table. /// </returns> public static TransparencyTable GetTransparencyTable(int palette) { if(tables[palette] == null) { int fi, si; if(!Common.E(palette, out fi, out si))return null; using(FileStream stream = new FileStream(Paths.TransparencyTablesN.Format(fi), FileMode.Open)) { XLDNavigator nav = XLDNavigator.ReadToIndex(stream, (short)si); if(nav.SubfileLength != 196608)return null; tables[palette] = new TransparencyTable(palette, nav); } } return tables[palette]; }