Esempio n. 1
0
 SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineBitsJPEG4Tag tag, ISwfStreamWriter writer)
 {
     writer.WriteUInt16(tag.CharacterID);
     writer.WriteUInt32((uint)tag.ImageData.Length);
     writer.WriteUInt16(tag.DeblockParam);
     writer.WriteBytes(tag.ImageData);
     writer.WriteBytes(tag.BitmapAlphaData);
     return(null);
 }
Esempio n. 2
0
        SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineBitsJPEG4Tag tag, ISwfStreamReader reader)
        {
            tag.CharacterID = reader.ReadUInt16();
            var alphaDataOffset = reader.ReadUInt32();

            tag.DeblockParam    = reader.ReadUInt16();
            tag.ImageData       = reader.ReadBytes((int)alphaDataOffset);
            tag.BitmapAlphaData = reader.ReadRest();
            return(tag);
        }
Esempio n. 3
0
    private ImageData GetDefineBitsJPEG4ImageData(DefineBitsJPEG4Tag defineBitsJPEG4)
    {
        var imageData = new ImageData();

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

        if (isPng)
        {
            imageData.type = ImageType.Png;
            var texture = new Texture2D(16, 16);         //宽高可以任意LoadImage()时会自动调整
            texture.LoadImage(defineBitsJPEG4.imageData);
            texture.Apply();
            var colors = texture.GetPixels32();
            var len    = defineBitsJPEG4.bitmapAlphaData.Length;

            var alphaData = new byte[len];
            Array.Copy(defineBitsJPEG4.bitmapAlphaData, alphaData, len);
            FlipVerticalBitmapAlphaData(alphaData, (ushort)texture.width, (ushort)texture.height);
            for (var i = 0; i < len; i++)
            {
                colors[i].a = alphaData[i];
            }
            texture.SetPixels32(colors);
            texture.Apply();
            imageData.bytes = texture.EncodeToJPG(100);
        }
        else if (isJpg || isGif)
        {
            imageData.type  = ImageType.Jpg;         //.gif也导出为jpg
            imageData.bytes = defineBitsJPEG4.imageData;
        }
        return(imageData);
    }
Esempio n. 4
0
 ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineBitsJPEG4Tag tag, object arg)
 {
     return(new DefineBitsJPEG4TagFormatter());
 }