/// <summary> /// constructor /// </summary> /// <param name="h">header data</param> /// <param name="clp">swf action blocks (clip actions)</param> public PlaceObject2Tag(byte[] h,ClipActionRec[] clp) { header = h; clipActions = clp; _tagCode = (int)TagCodeEnum.PlaceObject2; }
/************************************************** * Read SWF Tags **************************************************/ /// <summary> /// Read and parse PlaceObject2Tag, leave non-bytecode data as raw byte-array /// </summary> protected PlaceObject2Tag ReadPlaceObject2Tag() { ReadRecordHeader(); // get flags byte byte0 = br.ReadByte(); BitArray flags = new BitArray(new byte[1] { byte0 }); BitParser.BytewiseReverse(flags); byte[] depth = br.ReadBytes(2); byte[] chId; byte[] matrix; byte[] ctf; byte[] ratio; byte[] name; byte[] clpd; bool hasActions; // even if length is 0 byte[] actionHead; // contains byte code data ClipActionRec[] clipActions; // read data, depending on flag settings if (flags[6]) { chId = br.ReadBytes(2); } else { chId = new byte[0]; } if (flags[5]) { matrix = ReadMatrixData(); } else { matrix = new byte[0]; } if (flags[4]) { ctf = ReadCXFormWithAlphaData(); } else { ctf = new byte[0]; } if (flags[3]) { ratio = br.ReadBytes(2); } else { ratio = new byte[0]; } if (flags[2]) { // save stream position long startStream = br.BaseStream.Position; // read characters byte ch; do { ch = br.ReadByte(); } while (ch != 0); // block length int len = Convert.ToInt32(br.BaseStream.Position - startStream); // reset stream position br.BaseStream.Position = startStream; // read name name = br.ReadBytes(len); } else { name = new byte[0]; } // clip id if (flags[1]) { clpd = br.ReadBytes(2); } else { clpd = new byte[0]; } hasActions = flags[0]; // get bytecode actions if (hasActions) { // different behaviour for Flash 6+ actionHead = (version >= 6) ? br.ReadBytes(6) : br.ReadBytes(4); // read clip action records to list ArrayList clpAc = new ArrayList(); ClipActionRec a; do { a = ReadClipActionRec(); if (a != null) { clpAc.Add(a); } } while (a != null); // copy list to array clipActions = new ClipActionRec[clpAc.Count]; clpAc.CopyTo(clipActions, 0); } else { // no actions -> null return(null); } // tag-header (non-bytecode data before clipActionRec in tag) size varies with flags int size = 3 // flags + chId.Length + matrix.Length + ctf.Length + ratio.Length + name.Length + clpd.Length + actionHead.Length; byte[] header = new byte[size]; int pos = 1; // copy all data to our tag-header array header[0] = byte0; depth.CopyTo(header, 1); pos += depth.Length; chId.CopyTo(header, pos); pos += chId.Length; matrix.CopyTo(header, pos); pos += matrix.Length; ctf.CopyTo(header, pos); pos += ctf.Length; ratio.CopyTo(header, pos); pos += ratio.Length; name.CopyTo(header, pos); pos += name.Length; clpd.CopyTo(header, pos); pos += clpd.Length; actionHead.CopyTo(header, pos); // return tag return(new PlaceObject2Tag(header, clipActions)); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); bool placeFlagHasClipActions = binaryReader.ReadBoolean(); bool placeFlagHasClipDepth = binaryReader.ReadBoolean(); bool placeFlagHasName = binaryReader.ReadBoolean(); bool placeFlagHasRatio = binaryReader.ReadBoolean(); bool placeFlagHasColorTransform = binaryReader.ReadBoolean(); bool placeFlagHasMatrix = binaryReader.ReadBoolean(); bool placeFlagHasCharacter = binaryReader.ReadBoolean(); placeFlagMove = binaryReader.ReadBoolean(); depth = binaryReader.ReadUInt16(); characterId = 0; if (placeFlagHasCharacter) { characterId = binaryReader.ReadUInt16(); } matrix = null; if (placeFlagHasMatrix) { matrix = new Matrix(); matrix.ReadData(binaryReader); } colorTransform = null; if (placeFlagHasColorTransform) { colorTransform = new CXFormWithAlphaData(); colorTransform.ReadData(binaryReader); } ratio = 0; if (placeFlagHasRatio) { ratio = binaryReader.ReadUInt16() / 65535.0f; } name = null; if (placeFlagHasName) { name = binaryReader.ReadString(); } clipDepth = 0; if (placeFlagHasClipDepth) { clipDepth = binaryReader.ReadUInt16(); } // get bytecode actions clipActions = null; if (placeFlagHasClipActions) { // different behaviour for Flash 6+ actionHead = (version >= 6) ? binaryReader.ReadBytes(6) : binaryReader.ReadBytes(4); // read clip action records to list ArrayList clpAc = new ArrayList(); //ClipActionRec a = null; bool res = true; do { ClipActionRec action = new ClipActionRec(); res = action.ReadData(binaryReader, version); if (res) { clpAc.Add(action); } }while (res); // copy list to array clipActions = new ClipActionRec[clpAc.Count]; clpAc.CopyTo(clipActions, 0); } }