Beispiel #1
0
    private ImageData GetDefineBitsJPEG2ImageData(DefineBitsJPEG2Tag defineBitsJPEG2)
    {
        var imageData = new ImageData();

        imageData.characterID = defineBitsJPEG2.characterID;
        bool isJpg = defineBitsJPEG2.imageData[0] == 0xFF && (defineBitsJPEG2.imageData[1] == 0xD8 || defineBitsJPEG2.imageData[1] == 0xD9);
        bool isPng = defineBitsJPEG2.imageData[0] == 0x89 &&
                     defineBitsJPEG2.imageData[1] == 0x50 &&
                     defineBitsJPEG2.imageData[2] == 0x4E &&
                     defineBitsJPEG2.imageData[3] == 0x47 &&
                     defineBitsJPEG2.imageData[4] == 0x0D &&
                     defineBitsJPEG2.imageData[5] == 0x0A &&
                     defineBitsJPEG2.imageData[6] == 0x1A &&
                     defineBitsJPEG2.imageData[7] == 0x0A;
        bool isGif = defineBitsJPEG2.imageData[0] == 0x47 &&
                     defineBitsJPEG2.imageData[1] == 0x49 &&
                     defineBitsJPEG2.imageData[2] == 0x46 &&
                     defineBitsJPEG2.imageData[3] == 0x38 &&
                     defineBitsJPEG2.imageData[4] == 0x39 &&
                     defineBitsJPEG2.imageData[5] == 0x61;

        if (isPng)
        {
            imageData.type = ImageType.Png;
        }
        else if (isJpg || isGif)
        {
            imageData.type = ImageType.Jpg;
        }
        imageData.bytes = defineBitsJPEG2.imageData;
        return(imageData);
    }
Beispiel #2
0
        public void DefineBitsJPEG2Test()
        {
            var file = new SwfFile();

            file.FileInfo.Version = 10;

            var tag = new DefineBitsJPEG2Tag();

            tag.CharacterID = 1;
            tag.ImageData   = GetEmbeddedResourceData("DefineBitsJPEG2.jpg");
            var visitor = new SwfTagSerializer(file);
            var res     = visitor.GetTagData(tag);
            var mem     = new MemoryStream();
            var writer  = new SwfStreamWriter(mem);

            writer.WriteTagData(res);

            var etalon = GetTagFullBinariesFromSwfResource("DefineBitsJPEG2.swf")
                         .FirstOrDefault(item => item.Type == SwfTagType.DefineBitsJPEG2);

            if (etalon.Binary == null)
            {
                throw new InvalidOperationException("Couldn't find etalon tag");
            }

            AssertExt.AreEqual(etalon.Binary, mem.ToArray(), "Checking DefineBitsJPEG2");
        }
Beispiel #3
0
 SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineBitsJPEG2Tag tag, ISwfStreamWriter writer)
 {
     writer.WriteUInt16(tag.CharacterID);
     if (tag.ImageData != null)
     {
         writer.WriteBytes(tag.ImageData);
     }
     return(null);
 }
        public void DefineBitsJPEG2Test()
        {
            var file = new SwfFile();
            file.FileInfo.Version = 10;

            var tag = new DefineBitsJPEG2Tag();
            tag.CharacterID = 1;
            tag.ImageData = GetEmbeddedResourceData("DefineBitsJPEG2.jpg");
            var visitor = new SwfTagSerializer(file);
            var res = visitor.GetTagData(tag);
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);
            writer.WriteTagData(res);

            var etalon = GetTagFullBinariesFromSwfResource("DefineBitsJPEG2.swf")
                .FirstOrDefault(item => item.Type == SwfTagType.DefineBitsJPEG2);
            if (etalon.Binary == null) throw new InvalidOperationException("Couldn't find etalon tag");

            AssertExt.AreEqual(etalon.Binary, mem.ToArray(), "Checking DefineBitsJPEG2");
        }
Beispiel #5
0
 SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineBitsJPEG2Tag tag, ISwfStreamReader reader)
 {
     tag.CharacterID = reader.ReadUInt16();
     tag.ImageData   = reader.ReadRest();
     return(tag);
 }
Beispiel #6
0
 ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineBitsJPEG2Tag tag, object arg)
 {
     return(new DefineBitsJPEG2TagFormatter());
 }