public Tag(SwfReader swf) { ushort tagInfo = swf.ReadUI16(); Code = (ushort)(tagInfo >> 6); Length = (ulong)(tagInfo & 0x3f); // Is this a long data block? if (Length == 0x3f) { Length = swf.ReadUI32(); } switch (Code) { // DefineBitsLossless2 case 36: ulong remainingLength = Length - 7; Png.CharacterId = swf.ReadUI16(); Png.BitmapFormat = swf.ReadUI8(); Png.BitmapWidth = swf.ReadUI16(); Png.BitmapHeight = swf.ReadUI16(); List<byte> compressedPixelData = new List<byte>(); for (ulong b = 0; b < remainingLength; b++) { compressedPixelData.Add(swf.ReadByte()); } byte[] compressedBitMapPixelData = compressedPixelData.ToArray(); Stream pixelStream = new MemoryStream(compressedBitMapPixelData); pixelStream.ReadByte(); pixelStream.ReadByte(); DeflateStream inflatedStream = new DeflateStream(pixelStream, CompressionMode.Decompress); pixelStream = inflatedStream; for (long c = 0; c < Png.BitmapArea; c++) { byte alpha = Convert.ToByte(pixelStream.ReadByte()); byte red = Convert.ToByte(pixelStream.ReadByte()); byte green = Convert.ToByte(pixelStream.ReadByte()); byte blue = Convert.ToByte(pixelStream.ReadByte()); Png.BitmapPixelData.AddRange(new[] { blue, green, red, alpha }); } break; // SymbolClass case 76: ushort numSymbols = swf.ReadUI16(); for (ushort s = 0; s < numSymbols; s++) { short tagId = swf.ReadSI16(); string tagName = swf.ReadSTRING(); string prettyName = Regex.Replace(tagName, @"ImagePack_((items)|(masteryIcons)|(spells))_Embeds__e_(Spell_)?", ""); if (!Symbols.ContainsKey(tagId)) { Symbols[tagId] = prettyName; } } break; // Everything Else default: for (ulong index = 0; index < Length; index++) { swf.Stream.ReadByte(); } break; } }
public Tag(SwfReader swf) { ushort tagInfo = swf.ReadUI16(); Code = (ushort)(tagInfo >> 6); Length = (ulong)(tagInfo & 0x3f); // Is this a long data block? if (Length == 0x3f) { Length = swf.ReadUI32(); } switch (Code) { // DefineBitsLossless2 case 36: ulong remainingLength = Length - 7; Png.CharacterId = swf.ReadUI16(); Png.BitmapFormat = swf.ReadUI8(); Png.BitmapWidth = swf.ReadUI16(); Png.BitmapHeight = swf.ReadUI16(); List <byte> compressedPixelData = new List <byte>(); for (ulong b = 0; b < remainingLength; b++) { compressedPixelData.Add(swf.ReadByte()); } byte[] compressedBitMapPixelData = compressedPixelData.ToArray(); Stream pixelStream = new MemoryStream(compressedBitMapPixelData); pixelStream.ReadByte(); pixelStream.ReadByte(); DeflateStream inflatedStream = new DeflateStream(pixelStream, CompressionMode.Decompress); pixelStream = inflatedStream; for (long c = 0; c < Png.BitmapArea; c++) { byte alpha = Convert.ToByte(pixelStream.ReadByte()); byte red = Convert.ToByte(pixelStream.ReadByte()); byte green = Convert.ToByte(pixelStream.ReadByte()); byte blue = Convert.ToByte(pixelStream.ReadByte()); Png.BitmapPixelData.AddRange(new[] { blue, green, red, alpha }); } break; // SymbolClass case 76: ushort numSymbols = swf.ReadUI16(); for (ushort s = 0; s < numSymbols; s++) { short tagId = swf.ReadSI16(); string tagName = swf.ReadSTRING(); string prettyName = Regex.Replace(tagName, @"ImagePack_((items)|(masteryIcons)|(spells))_Embeds__e_(Spell_)?", ""); if (!Symbols.ContainsKey(tagId)) { Symbols[tagId] = prettyName; } } break; // Everything Else default: for (ulong index = 0; index < Length; index++) { swf.Stream.ReadByte(); } break; } }