DefineBitsJpeg3Tag is used to define a transparent JPEG encoded image.

It extends the DefineBitsJpeg2Tag class by including a separate zlib compressed table of alpha channel values. This allows the transparency of existing JPEG encoded images to be changed without re-encoding the original image.

Although the encoding table defines how the image is compressed it is not essential. If a DefineBitsJpeg3Tag object is created with an empty encoding table then the Flash Player will still display the JPEG image correctly. The empty encoding table is not a null object. It contains four bytes: 0xFF, 0xD9, 0xFF, 0xD8. Note however that this is reversed from StartOfImage (SOI, 0xFFD8) and EndOfImage (EOI, 0xFFD9) tags defined in the JPEG file format specification. This appears to be a bug in Flash. However the order is preserved to ensure compatibility although code has been tested with the normal order for the tags and the images were displayed correctly.

This tag was introduced in Flash 3.

상속: DefineBitsJpeg2Tag
예제 #1
0
        /// <summary>
        /// Construct a new DefineBitsJpeg3Tag object
        /// from a file.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public new static DefineBitsJpeg3Tag FromFile(ushort characterId, string fileName)
        {
            FileStream         stream = File.OpenRead(fileName);
            DefineBitsJpeg3Tag res    = FromStream(characterId, stream);

            stream.Close();
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Construct a new DefineBitsJpeg3Tag object
        /// from a stream.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="stream">Stream.</param>
        /// <returns></returns>
        public new static DefineBitsJpeg3Tag FromStream(ushort characterId, Stream stream)
        {
            DefineBitsJpeg3Tag jpegTag = new DefineBitsJpeg3Tag();

            jpegTag.CharacterId = characterId;

            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);

            byte[] buffer2 = new byte[buffer.Length + 4];
            buffer2[0] = 0xFF;
            buffer2[1] = 0xD9;
            buffer2[2] = 0xFF;
            buffer2[3] = 0xD8;
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer2[i + 4] = buffer[i];
            }

            jpegTag.JpegData = buffer2;

            return(jpegTag);
        }
예제 #3
0
        /// <summary>
        /// Construct a new DefineBitsJpeg3Tag object 
        /// from a stream.
        /// </summary>
        /// <param name="characterId">Character id.</param>
        /// <param name="stream">Stream.</param>
        /// <returns></returns>
        public static new DefineBitsJpeg3Tag FromStream(ushort characterId, Stream stream)
        {
            DefineBitsJpeg3Tag jpegTag = new DefineBitsJpeg3Tag();
            jpegTag.CharacterId = characterId;

            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);

            byte[] buffer2 = new byte[buffer.Length + 4];
            buffer2[0] = 0xFF;
            buffer2[1] = 0xD9;
            buffer2[2] = 0xFF;
            buffer2[3] = 0xD8;
            for (int i = 0; i < buffer.Length; i++)
                buffer2[i + 4] = buffer[i];

            jpegTag.JpegData = buffer2;

            return jpegTag;
        }
예제 #4
0
 static Tuple<int, Image> DecodeJpeg3(DefineBitsJpeg3Tag tag)
 {
     return Tuple.Create((int)tag.CharacterId, tag.DecompileToImage());
 }
예제 #5
0
        /// <summary>
        /// Read next tag from swf input stream.
        /// </summary>
        /// <param name="version">Version.</param>
        /// <param name="binaryReader">Binary reader.</param>
        /// <param name="tagList">Tag list.</param>
        /// <returns></returns>
        internal static BaseTag ReadTag(byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList)
        {
            long posBefore = binaryReader.BaseStream.Position;
            RecordHeader rh = new RecordHeader();
            rh.ReadData(binaryReader);

            int offset = (int)(binaryReader.BaseStream.Position - posBefore);
            binaryReader.BaseStream.Position = posBefore;

            BaseTag resTag = null;

            switch (rh.TagCode)
            {
                case (int)TagCodeEnum.DefineBits: resTag = new DefineBitsTag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg2: resTag = new DefineBitsJpeg2Tag(); break;
                case (int)TagCodeEnum.DefineBitsJpeg3: resTag = new DefineBitsJpeg3Tag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess: resTag = new DefineBitsLossLessTag(); break;
                case (int)TagCodeEnum.DefineBitsLossLess2: resTag = new DefineBitsLossLess2Tag(); break;
                case (int)TagCodeEnum.DefineButton: resTag = new DefineButtonTag(); break;
                case (int)TagCodeEnum.DefineButton2: resTag = new DefineButton2Tag(); break;
                case (int)TagCodeEnum.DefineButtonCxForm: resTag = new DefineButtonCxFormTag(); break;
                case (int)TagCodeEnum.DefineButtonSound: resTag = new DefineButtonSoundTag(); break;
                case (int)TagCodeEnum.DefineEditText: resTag = new DefineEditTextTag(); break;
                case (int)TagCodeEnum.DefineFont: resTag = new DefineFontTag(); break;
                case (int)TagCodeEnum.DefineFont2: resTag = new DefineFont2Tag(); break;
                case (int)TagCodeEnum.DefineFontInfo: resTag = new DefineFontInfoTag(); break;
                case (int)TagCodeEnum.DefineFontInfo2: resTag = new DefineFontInfo2Tag(); break;
                case (int)TagCodeEnum.DefineMorphShape: resTag = new DefineMorphShapeTag(); break;
                case (int)TagCodeEnum.DefineShape: resTag = new DefineShapeTag(); break;
                case (int)TagCodeEnum.DefineShape2: resTag = new DefineShape2Tag(); break;
                case (int)TagCodeEnum.DefineShape3: resTag = new DefineShape3Tag(); break;
                case (int)TagCodeEnum.DefineSound: resTag = new DefineSoundTag(); break;
                case (int)TagCodeEnum.DefineSprite: resTag = new DefineSpriteTag(); break;
                case (int)TagCodeEnum.DefineText: resTag = new DefineTextTag(); break;
                case (int)TagCodeEnum.DefineText2: resTag = new DefineText2Tag(); break;
                case (int)TagCodeEnum.DefineVideoStream: resTag = new DefineVideoStreamTag(); break;
                case (int)TagCodeEnum.DoAction: resTag = new DoActionTag(); break;
                case (int)TagCodeEnum.EnableDebugger: resTag = new EnableDebuggerTag(); break;
                case (int)TagCodeEnum.EnableDebugger2: resTag = new EnableDebugger2Tag(); break;
                case (int)TagCodeEnum.End: resTag = new EndTag(); break;
                case (int)TagCodeEnum.ExportAssets: resTag = new ExportAssetsTag(); break;
                case (int)TagCodeEnum.FrameLabel: resTag = new FrameLabelTag(); break;
                case (int)TagCodeEnum.ImportAssets: resTag = new ImportAssetsTag(); break;
                case (int)TagCodeEnum.InitAction: resTag = new InitActionTag(); break;
                case (int)TagCodeEnum.JpegTable: resTag = new JpegTableTag(); break;
                case (int)TagCodeEnum.PlaceObject: resTag = new PlaceObjectTag(); break;
                case (int)TagCodeEnum.PlaceObject2:	resTag = new PlaceObject2Tag(); break;
                case (int)TagCodeEnum.Protect: resTag = new ProtectTag(); break;
                case (int)TagCodeEnum.RemoveObject: resTag = new RemoveObjectTag(); break;
                case (int)TagCodeEnum.RemoveObject2: resTag = new RemoveObject2Tag(); break;
                case (int)TagCodeEnum.ScriptLimit: resTag = new ScriptLimitTag(); break;
                case (int)TagCodeEnum.SetBackgroundColor: resTag = new SetBackgroundColorTag(); break;
                case (int)TagCodeEnum.SetTabIndex: resTag = new SetTabIndexTag(); break;
                case (int)TagCodeEnum.ShowFrame: resTag = new ShowFrameTag(); break;
                case (int)TagCodeEnum.SoundStreamBlock: resTag = new SoundStreamBlockTag(); break;
                case (int)TagCodeEnum.SoundStreamHead: resTag = new SoundStreamHeadTag(); break;
                case (int)TagCodeEnum.SoundStreamHead2: resTag = new SoundStreamHead2Tag(); break;
                case (int)TagCodeEnum.StartSound: resTag = new StartSoundTag(); break;
                //TODO: Sorenson Codec
                case (int)TagCodeEnum.VideoFrame: resTag = ReadVideoFrameTag(binaryReader, tagList); break;
                default: resTag = new BaseTag(binaryReader.ReadBytes(System.Convert.ToInt32(rh.TagLength + offset))); break;
            }

            //Read the data of the current tag
            resTag.ReadData(version, binaryReader);

            //LOG
            long mustRead = rh.TagLength + offset;
            if (posBefore + mustRead != binaryReader.BaseStream.Position)
            {
                binaryReader.BaseStream.Position = posBefore + rh.TagLength + offset;
                if (log.IsErrorEnabled)
                    log.Error(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....KO");
            }
            else if (log.IsInfoEnabled)
                log.Info(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....OK (" + mustRead + ")");

            return resTag;
        }