コード例 #1
0
 public SwfDisplayList Visit(DefineBitsLosslessTag tag, SwfDisplayList dl)
 {
     AddBitmapToLibrary(
         tag.CharacterId,
         tag.BitmapWidth,
         tag.BitmapHeight,
         tag.ToARGB32());
     return(dl);
 }
コード例 #2
0
    private ImageData GetDefineBitsLosslessImageData(DefineBitsLosslessTag defineBitsLossless)
    {
        var texture = new Texture2D(defineBitsLossless.bitmapWidth, defineBitsLossless.bitmapHeight);

        if (defineBitsLossless.bitmapFormat == 3)
        {
            //ColorMapDataRecord
            var colorMapDataRecord = (ColorMapDataRecord)defineBitsLossless.zlibBitmapData;
            int length             = colorMapDataRecord.colormapPixelData.Length;
            var colors             = new Color32[length];
            for (int i = 0; i < length; i++)
            {
                var colorIndex = colorMapDataRecord.colormapPixelData[i];
                var rgb        = colorMapDataRecord.colorTableRGB[colorIndex];
                colors[i] = new Color32(rgb.red, rgb.green, rgb.blue, 255);
            }
            colors = FlipVerticalBitmapColors(colors, defineBitsLossless.bitmapWidth, defineBitsLossless.bitmapHeight);
            texture.SetPixels32(colors);
            texture.Apply();
        }
        else if (defineBitsLossless.bitmapFormat == 4 || defineBitsLossless.bitmapFormat == 5)
        {
            //BitmapDataRecord
            var bitmapDataRecord = (BitmapDataRecord)defineBitsLossless.zlibBitmapData;
            int length           = bitmapDataRecord.bitmapPixelData.Length;
            var colors           = new Color32[length];
            if (defineBitsLossless.bitmapFormat == 4)
            {
                for (int i = 0; i < length; i++)
                {
                    var pix15 = (Pix15Record)bitmapDataRecord.bitmapPixelData[i];
                    colors[i] = new Color32(pix15.red, pix15.green, pix15.blue, 255);
                }
            }
            else if (defineBitsLossless.bitmapFormat == 5)
            {
                for (int i = 0; i < length; i++)
                {
                    var pix24 = (Pix24Record)bitmapDataRecord.bitmapPixelData[i];
                    colors[i] = new Color32(pix24.red, pix24.green, pix24.blue, 255);
                }
            }
            colors = FlipVerticalBitmapColors(colors, defineBitsLossless.bitmapWidth, defineBitsLossless.bitmapHeight);
            texture.SetPixels32(colors);
            texture.Apply();
        }
        var imageData = new ImageData();

        imageData.characterID = defineBitsLossless.characterID;
        //Png或Jpg都可以
        //imageData.type=ImageType.Png;
        imageData.type  = ImageType.Jpg;
        imageData.bytes = texture.EncodeToJPG();
        return(imageData);
    }
コード例 #3
0
ファイル: SwfTagDeserializer.cs プロジェクト: shhadi/SwfLib
 SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineBitsLosslessTag 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);
 }
コード例 #4
0
        private void ParseDefineBitsLossless(DefineBitsLosslessTag tag)
        {
            //DDW.Vex.ImageFill bf = new DDW.Vex.ImageFill();
            //string path = v.ResourceFolder + @"/" + VexObject.BitmapPrefix + tag.CharacterId + ".png";

            //WriteLosslessBitmapToDisk(path, tag);

            //Image img = new Vex.Image(path, v.NextId());
            //img.Id = tag.CharacterId;
            //img.StrokeBounds = new Rectangle(0, 0, tag.Width, tag.Height);

            //bitmapPaths.Add(img.Id, path);
            //v.Definitions.Add(img.Id, img);
        }
コード例 #5
0
 SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineBitsLosslessTag 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);
 }
コード例 #6
0
        public static BitmapFrame ToBitmapFrame(this DefineBitsLosslessTag tag)
        {
            if (tag == null)
            {
                return(null);
            }

            BitmapFrame frame;

            try
            {
                using (var stream = new MemoryStream())
                {
                    tag.GetBitmap().Save(stream, ImageFormat.Png);
                    frame = BitmapFrame.Create(stream,
                                               BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.OnLoad);
                }
            }
            catch (NotSupportedException)
            {
                return(null);
            }
            return(frame);
        }
コード例 #7
0
        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));
            }
        }
コード例 #8
0
 ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineBitsLosslessTag tag, object arg)
 {
     return(new DefineBitsLosslessTagFormatter());
 }
コード例 #9
0
        private void ParseTag(ISwfTag tag)
        {
            switch (tag.TagType)
            {
            case TagType.DefineSprite:
                ParseDefineSpriteTag((DefineSpriteTag)tag);
                break;

            case TagType.DefineShape:
                ParseDefineShapeTag((DefineShapeTag)tag);
                break;

            case TagType.DefineShape2:
                ParseDefineShape2Tag((DefineShape2Tag)tag);
                break;

            case TagType.DefineShape3:
                ParseDefineShape3Tag((DefineShape3Tag)tag);
                break;

            case TagType.DefineShape4:
                ParseDefineShape4Tag((DefineShape4Tag)tag);
                break;

            case TagType.JPEGTables:
                // not retained
                break;

            case TagType.DefineBits:
                ParseDefineBits((DefineBitsTag)tag);
                break;

            case TagType.DefineBitsJPEG2:
                ParseDefineBits((DefineBitsTag)tag);
                break;

            case TagType.DefineBitsJPEG3:
                ParseDefineBits((DefineBitsTag)tag);
                break;

            case TagType.DefineBitsLossless:
                ParseDefineBitsLossless((DefineBitsLosslessTag)tag);
                break;

            case TagType.DefineBitsLossless2:
                if (!addedFullBitmap)
                {
                    addedFullBitmap = true;
                    DefineBitsLosslessTag t = (DefineBitsLosslessTag)tag;
                    fullBitmapId = t.CharacterId;
                    //DefineBitsLosslessTag t = new DefineBitsLosslessTag(true);
                    //t.CharacterId = ot.CharacterId;
                    //t.BitmapFormat = ot.BitmapFormat;
                    t.Width         = (uint)fullBitmap.Bitmap.Width;
                    t.Height        = (uint)fullBitmap.Bitmap.Height;
                    t.OrgBitmapData = null;
                    uint   pxCount = t.Width * t.Height;
                    RGBA[] pxs     = new RGBA[pxCount];

                    fullBitmap.LockBitmap();
                    for (int i = 0; i < pxCount; i++)
                    {
                        int       x  = (int)(i % t.Width);
                        int       y  = (int)(Math.Floor((double)(i / t.Width)));
                        PixelData pd = fullBitmap.GetPixel(x, y);
                        pxs[i] = new RGBA(pd.red, pd.green, pd.blue, pd.alpha);
                    }
                    t.BitmapData = pxs;
                    fullBitmap.UnlockBitmap();
                }
                break;

            case TagType.UnsupportedDefinition:
                break;
            }
        }