private static void WriteImage(DefineBitsLossless2Tag image, string path) { if (File.Exists(path)) { return; } System.Drawing.Color[,] table = image.GetARGBMap(); int width = table.GetLength(0); int height = table.GetLength(1); using (var payload = new Image <Rgba32>(width, height)) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { System.Drawing.Color pixel = table[x, y]; payload[x, y] = new Rgba32(pixel.R, pixel.G, pixel.B, pixel.A); } } using (var output = new StreamWriter(path)) { payload.SaveAsPng(output.BaseStream); } } }
protected virtual FlashTag ReadTag(FlashReader reader, TagRecord header) { FlashTag tag = null; switch (header.TagType) { default: tag = new UnknownTag(Reader, header); break; case FlashTagType.DoABC: tag = new DoABCTag(Reader, header); _abcFiles.Add(((DoABCTag)tag).ABC); break; case FlashTagType.DefineBitsLossless2: tag = new DefineBitsLossless2Tag(Reader, header); break; case FlashTagType.DefineBinaryData: tag = new DefineBinaryDataTag(Reader, header); break; } var character = (tag as ICharacter); if (character != null) { // Add ICharacter tag to the global dictionary. Dictionary.Characters[ character.CharacterId] = character; } return(tag); }
public SwfDisplayList Visit(DefineBitsLossless2Tag tag, SwfDisplayList dl) { AddBitmapToLibrary( tag.CharacterId, tag.BitmapWidth, tag.BitmapHeight, tag.ToARGB32()); return(dl); }
SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineBitsLossless2Tag tag, ISwfStreamReader reader) { tag.CharacterID = reader.ReadUInt16(); tag.BitmapFormat = reader.ReadByte(); tag.BitmapWidth = reader.ReadUInt16(); tag.BitmapHeight = reader.ReadUInt16(); if (tag.BitmapFormat == 3) { tag.BitmapColorTableSize = reader.ReadByte(); } tag.ZlibBitmapData = reader.ReadRest(); return(tag); }
SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineBitsLossless2Tag tag, ISwfStreamWriter writer) { writer.WriteUInt16(tag.CharacterID); writer.WriteByte(tag.BitmapFormat); writer.WriteUInt16(tag.BitmapWidth); writer.WriteUInt16(tag.BitmapHeight); if (tag.BitmapFormat == 3) { writer.WriteByte(tag.BitmapColorTableSize); } if (tag.ZlibBitmapData != null) { writer.WriteBytes(tag.ZlibBitmapData); } return(null); }
private ImageData GetDefineBitsLossless2ImageData(DefineBitsLossless2Tag defineBitsLossless2) { var texture = new Texture2D(defineBitsLossless2.bitmapWidth, defineBitsLossless2.bitmapHeight); if (defineBitsLossless2.bitmapFormat == 3) { //AlphaColorMapDataRecord var alphaColorMapDataRecord = (AlphaColorMapDataRecord)defineBitsLossless2.zlibBitmapData; int length = alphaColorMapDataRecord.colormapPixelData.Length; var colors = new Color32[length]; for (int j = 0; j < length; j++) { var colorIndex = alphaColorMapDataRecord.colormapPixelData[j]; var rgba = alphaColorMapDataRecord.colorTableRGB[colorIndex]; colors[j] = new Color32(rgba.red, rgba.green, rgba.blue, rgba.alpha); } colors = FlipVerticalBitmapColors(colors, defineBitsLossless2.bitmapWidth, defineBitsLossless2.bitmapHeight); texture.SetPixels32(colors); texture.Apply(); } else if (defineBitsLossless2.bitmapFormat == 4 || defineBitsLossless2.bitmapFormat == 5) { //AlphaBitmapDataRecord var alphaBitmapDataRecord = (AlphaBitmapDataRecord)defineBitsLossless2.zlibBitmapData; int length = alphaBitmapDataRecord.bitmapPixelData.Length; var colors = new Color32[length]; for (int j = 0; j < length; j++) { var argb = alphaBitmapDataRecord.bitmapPixelData[j]; colors[j] = new Color32(argb.red, argb.green, argb.blue, argb.alpha); } colors = FlipVerticalBitmapColors(colors, defineBitsLossless2.bitmapWidth, defineBitsLossless2.bitmapHeight); texture.SetPixels32(colors); texture.Apply(); } var imageData = new ImageData(); imageData.characterID = defineBitsLossless2.characterID; imageData.type = ImageType.Png; imageData.bytes = texture.EncodeToPNG(); return(imageData); }
static SwfTagBase Create(SwfTagData tag_data) { var reader = new SwfStreamReader(tag_data.TagData); switch (tag_data.TagId) { // Display list case (int)SwfTagType.PlaceObject: return(PlaceObjectTag.Create(reader)); case (int)SwfTagType.PlaceObject2: return(PlaceObject2Tag.Create(reader)); case (int)SwfTagType.PlaceObject3: return(PlaceObject3Tag.Create(reader)); case (int)SwfTagType.RemoveObject: return(RemoveObjectTag.Create(reader)); case (int)SwfTagType.RemoveObject2: return(RemoveObject2Tag.Create(reader)); case (int)SwfTagType.ShowFrame: return(ShowFrameTag.Create(reader)); // Control case (int)SwfTagType.SetBackgroundColor: return(SetBackgroundColorTag.Create(reader)); case (int)SwfTagType.FrameLabel: return(FrameLabelTag.Create(reader)); case (int)SwfTagType.Protect: return(ProtectTag.Create(reader)); case (int)SwfTagType.End: return(EndTag.Create(reader)); case (int)SwfTagType.ExportAssets: return(ExportAssetsTag.Create(reader)); case (int)SwfTagType.ImportAssets: return(UnsupportedTag.Create(SwfTagType.ImportAssets)); case (int)SwfTagType.EnableDebugger: return(EnableDebuggerTag.Create(reader)); case (int)SwfTagType.EnableDebugger2: return(EnableDebugger2Tag.Create(reader)); case (int)SwfTagType.ScriptLimits: return(ScriptLimitsTag.Create(reader)); case (int)SwfTagType.SetTabIndex: return(UnsupportedTag.Create(SwfTagType.SetTabIndex)); case (int)SwfTagType.ImportAssets2: return(UnsupportedTag.Create(SwfTagType.ImportAssets2)); case (int)SwfTagType.SymbolClass: return(SymbolClassTag.Create(reader)); case (int)SwfTagType.Metadata: return(MetadataTag.Create(reader)); case (int)SwfTagType.DefineScalingGrid: return(UnsupportedTag.Create(SwfTagType.DefineScalingGrid)); case (int)SwfTagType.DefineSceneAndFrameLabelData: return(DefineSceneAndFrameLabelDataTag.Create(reader)); // Actions case (int)SwfTagType.DoAction: return(UnsupportedTag.Create(SwfTagType.DoAction)); case (int)SwfTagType.DoInitAction: return(UnsupportedTag.Create(SwfTagType.DoInitAction)); case (int)SwfTagType.DoABC: return(DoABCTag.Create(reader)); // Shape case (int)SwfTagType.DefineShape: return(DefineShapeTag.Create(reader)); case (int)SwfTagType.DefineShape2: return(DefineShape2Tag.Create(reader)); case (int)SwfTagType.DefineShape3: return(DefineShape3Tag.Create(reader)); case (int)SwfTagType.DefineShape4: return(DefineShape4Tag.Create(reader)); // Bitmaps case (int)SwfTagType.DefineBits: return(UnsupportedTag.Create(SwfTagType.DefineBits)); case (int)SwfTagType.JPEGTables: return(UnsupportedTag.Create(SwfTagType.JPEGTables)); case (int)SwfTagType.DefineBitsJPEG2: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG2)); case (int)SwfTagType.DefineBitsJPEG3: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG3)); case (int)SwfTagType.DefineBitsLossless: return(DefineBitsLosslessTag.Create(reader)); case (int)SwfTagType.DefineBitsLossless2: return(DefineBitsLossless2Tag.Create(reader)); case (int)SwfTagType.DefineBitsJPEG4: return(UnsupportedTag.Create(SwfTagType.DefineBitsJPEG4)); // Shape Morphing case (int)SwfTagType.DefineMorphShape: return(UnsupportedTag.Create(SwfTagType.DefineMorphShape)); case (int)SwfTagType.DefineMorphShape2: return(UnsupportedTag.Create(SwfTagType.DefineMorphShape2)); // Fonts and Text case (int)SwfTagType.DefineFont: return(UnsupportedTag.Create(SwfTagType.DefineFont)); case (int)SwfTagType.DefineFontInfo: return(UnsupportedTag.Create(SwfTagType.DefineFontInfo)); case (int)SwfTagType.DefineFontInfo2: return(UnsupportedTag.Create(SwfTagType.DefineFontInfo2)); case (int)SwfTagType.DefineFont2: return(UnsupportedTag.Create(SwfTagType.DefineFont2)); case (int)SwfTagType.DefineFont3: return(UnsupportedTag.Create(SwfTagType.DefineFont3)); case (int)SwfTagType.DefineFontAlignZones: return(UnsupportedTag.Create(SwfTagType.DefineFontAlignZones)); case (int)SwfTagType.DefineFontName: return(UnsupportedTag.Create(SwfTagType.DefineFontName)); case (int)SwfTagType.DefineText: return(UnsupportedTag.Create(SwfTagType.DefineText)); case (int)SwfTagType.DefineText2: return(UnsupportedTag.Create(SwfTagType.DefineText2)); case (int)SwfTagType.DefineEditText: return(UnsupportedTag.Create(SwfTagType.DefineEditText)); case (int)SwfTagType.CSMTextSettings: return(UnsupportedTag.Create(SwfTagType.CSMTextSettings)); case (int)SwfTagType.DefineFont4: return(UnsupportedTag.Create(SwfTagType.DefineFont4)); // Sounds case (int)SwfTagType.DefineSound: return(UnsupportedTag.Create(SwfTagType.DefineSound)); case (int)SwfTagType.StartSound: return(UnsupportedTag.Create(SwfTagType.StartSound)); case (int)SwfTagType.StartSound2: return(UnsupportedTag.Create(SwfTagType.StartSound2)); case (int)SwfTagType.SoundStreamHead: return(UnsupportedTag.Create(SwfTagType.SoundStreamHead)); case (int)SwfTagType.SoundStreamHead2: return(UnsupportedTag.Create(SwfTagType.SoundStreamHead2)); case (int)SwfTagType.SoundStreamBlock: return(UnsupportedTag.Create(SwfTagType.SoundStreamBlock)); // Buttons case (int)SwfTagType.DefineButton: return(UnsupportedTag.Create(SwfTagType.DefineButton)); case (int)SwfTagType.DefineButton2: return(UnsupportedTag.Create(SwfTagType.DefineButton2)); case (int)SwfTagType.DefineButtonCxform: return(UnsupportedTag.Create(SwfTagType.DefineButtonCxform)); case (int)SwfTagType.DefineButtonSound: return(UnsupportedTag.Create(SwfTagType.DefineButtonSound)); // Sprites and Movie Clips case (int)SwfTagType.DefineSprite: return(DefineSpriteTag.Create(reader)); // Video case (int)SwfTagType.DefineVideoStream: return(UnsupportedTag.Create(SwfTagType.DefineVideoStream)); case (int)SwfTagType.VideoFrame: return(UnsupportedTag.Create(SwfTagType.VideoFrame)); // Metadata case (int)SwfTagType.FileAttributes: return(FileAttributesTag.Create(reader)); case (int)SwfTagType.EnableTelemetry: return(EnableTelemetryTag.Create(reader)); case (int)SwfTagType.DefineBinaryData: return(DefineBinaryDataTag.Create(reader)); default: return(UnknownTag.Create(tag_data.TagId)); } }
ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineBitsLossless2Tag tag, object arg) { return(new DefineBitsLossless2TagFormatter()); }
protected virtual TagItem ReadTag(HeaderRecord header, FlashReader input) { TagItem tag = null; switch (header.Kind) { case TagKind.DefineBinaryData: tag = new DefineBinaryDataTag(header, input); break; case TagKind.DefineBitsLossless2: tag = new DefineBitsLossless2Tag(header, input); break; case TagKind.DefineFontName: tag = new DefineFontNameTag(header, input); break; case TagKind.DefineSound: tag = new DefineSoundTag(header, input); break; case TagKind.DoABC: tag = new DoABCTag(header, input); break; case TagKind.End: tag = new EndTag(header); break; case TagKind.ExportAssets: tag = new ExportAssetsTag(header, input); break; case TagKind.FileAttributes: tag = new FileAttributesTag(header, input); break; case TagKind.FrameLabel: tag = new FrameLabelTag(header, input); break; case TagKind.ProductInfo: tag = new ProductInfoTag(header, input); break; case TagKind.ScriptLimits: tag = new ScriptLimitsTag(header, input); break; case TagKind.SetBackgroundColor: tag = new SetBackgroundColorTag(header, input); break; case TagKind.ShowFrame: tag = new ShowFrameTag(header); break; case TagKind.SymbolClass: tag = new SymbolClassTag(header, input); break; default: case TagKind.Unknown: tag = new UnknownTag(header, input); break; } return(tag); }