/// <summary> /// /// </summary> /// <param name="inout"></param> /// <param name="bits"></param> public override void Parse(Stream inout, BitStream bits) { this._numbits = (UInt32)bits.GetBits(4); this._generalLineFlag = (0 != bits.GetBits(1)) ? true : false; if (this._generalLineFlag) { this._deltaX = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2); this._deltaY = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2); } else { this._vertLineFlag = (0 != bits.GetBits(1)) ? true : false; if (this._vertLineFlag) { this._deltaY = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2); } else { this._deltaX = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2); } } }
/// <summary> /// Parses this object out of a stream /// </summary> public void Parse(Stream input) { BitStream bits = new BitStream(input); bits.GetBitsFB(16, out this._alignmentCoordinate); bits.GetBitsFB(16, out this._range); }
/// <summary> /// Parses this object out of a stream /// </summary> public void Parse(BitStream bits, byte glyphBits, byte advancedBits) { this._glyphBits = glyphBits; this._advancedBits = advancedBits; this._glyphIndex = bits.GetBits((UInt32)glyphBits); this._glyphAdvance = bits.GetBitsSigned((UInt32)advancedBits); }
/// <summary> /// Parses this object out of a stream /// </summary> /// <param name="input">The input stream.</param> public override void Parse( Stream input ) { BitStream bits = new BitStream(input); bits.GetBits( 1 ); // reserved this._Red = (Byte)bits.GetBits( 5 ); this._Green = (Byte)bits.GetBits( 5 ); this._Blue = (Byte)bits.GetBits( 5 ); }
/// <summary> /// /// </summary> /// <param name="output"></param> public override void Write(Stream output) { BinaryWriter bw = new BinaryWriter(output); BitStream bits = new BitStream(output); bw.Write(this._initialSample); bits.WriteBits(6, (Int32)this._initialIndex); bits.WriteFlush(); output.Write(this._adpcmCodeData, 0, this._adpcmCodeData.Length); }
/// <summary> /// /// </summary> /// <param name="input"></param> public override void Parse(Stream input) { BinaryReader br = new BinaryReader(input); BitStream bits = new BitStream(input); this._initialSample = br.ReadInt16(); this._initialIndex = (Byte)bits.GetBits(6); this._adpcmCodeData = new Byte[(Int32)(input.Length - input.Position) + 2]; input.Read(this._adpcmCodeData, 0, this._adpcmCodeData.Length); }
/// <summary> /// /// </summary> /// <param name="input"></param> public void Parse(Stream input) { BitStream bits = new BitStream(input); if (_HasScale = (1 == bits.GetBits(1))) { _numScaleBits = (byte)bits.GetBits(5); bits.GetBitsFB(_numScaleBits, out _xScaleF); bits.GetBitsFB(_numScaleBits, out _yScaleF); } _numTranslateBits = (byte)bits.GetBits(5); _translateX = bits.GetBitsSigned(_numTranslateBits); _translateY = bits.GetBitsSigned(_numTranslateBits); }
/// <summary> /// Parses this object out of a stream /// </summary> /// <param name="input">The input stream.</param> internal void Parse(Stream input) { BinaryReader br = new BinaryReader(input); BitStream bs = new BitStream(input); this._HasAddTerms = 0 != bs.GetBits(1) ? true : false; this._HasMultTerms = 0 != bs.GetBits(1) ? true : false; this._Nbits = (Byte)bs.GetBits(4); this._RedMultTerm = (Byte)bs.GetBits(this._Nbits); this._GreenMultTerm = (Byte)bs.GetBits(this._Nbits); this._BlueMultTerm = (Byte)bs.GetBits(this._Nbits); this._RedAddTerm = (Byte)bs.GetBits(this._Nbits); this._GreenAddTerm = (Byte)bs.GetBits(this._Nbits); this._BlueAddTerm = (Byte)bs.GetBits(this._Nbits); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="type"></param> public void Parse(Stream input, SoundType type) { BitStream bits = new BitStream(input); this._ADPCMCodeSize = (Byte)bits.GetBits(2); if (type.Equals(SoundType.mono)) { AdpcmMonoPacket packet = new AdpcmMonoPacket(); packet.Parse(input); this._ADPCMPacket = packet; } else if (type.Equals(SoundType.stereo)) { AdpcmStereoPacket packet = new AdpcmStereoPacket(); packet.Parse(input); this._ADPCMPacket = packet; } }
/// <summary> /// Parses this object out of a stream /// </summary> public void Parse(Stream input) { BinaryReader br = new BinaryReader(input); this._numZoneData = br.ReadByte(); ZoneData temp = null; for (int i = 0; i < this._numZoneData; i++) { temp = new ZoneData(this._SwfVersion); temp.Parse(input); this._zoneData.Add(temp); } BitStream bits = new BitStream(input); bits.GetBits(6); //reserved this._zoneMaskY = ((0 != bits.GetBits(1)) ? true : false); this._zoneMaskX = ((0 != bits.GetBits(1)) ? true : false); }
/// <summary> /// /// </summary> /// <param name="output"></param> internal void Write(Stream output) { BinaryWriter bw = new BinaryWriter(output); BitStream bs = new BitStream(output); bs.WriteBits(1, false == this._HasAddTerms ? 0 : 1); bs.WriteBits(1, false == this._HasMultTerms ? 0 : 1); bs.WriteBits(4, this._Nbits ); bs.WriteBits(this._Nbits, this._RedMultTerm); bs.WriteBits(this._Nbits, this._GreenMultTerm); bs.WriteBits(this._Nbits, this._BlueMultTerm); bs.WriteBits(this._Nbits, this._RedAddTerm); bs.WriteBits(this._Nbits, this._GreenAddTerm); bs.WriteBits(this._Nbits, this._BlueAddTerm); bs.WriteFlush(); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public override void Parse( Stream input, TagTypes caller ) { BitStream bits = new BitStream( input ); this._spreadMode = ( SpreadMode )bits.GetBits( 2 ); this._interpolationMode = ( InterPolation )bits.GetBits( 2 ); this._numGradients = ( byte )bits.GetBits( 4 ); bits.Reset(); GradRecord temp = new GradRecord(this._SwfVersion); for ( int i = 0; i < _numGradients; i++ ) { temp = new GradRecord( this._SwfVersion ); temp.Parse( input, caller ); this._gradientRecords.Add(temp); } bits.GetBitsFB( 16, out this._focalPoint ); }
/// <summary> /// Parses this object out of a stream /// </summary> /// <param name="input">The input stream.</param> public override void Parse(Stream input) { BinaryReader br = new BinaryReader(input); this._startWidth = br.ReadUInt16(); this._endWidth = br.ReadUInt16(); BitStream bits = new BitStream(input); this._startCapStyle = (CapStyle)(Convert.ToByte(bits.GetBits(2))); this._joinstyle = (JoinStyle)(Convert.ToByte(bits.GetBits(2))); this._hasFillFlag = (0 != bits.GetBits(1) ? true : false); this._noHScale = (0 != bits.GetBits(1) ? true : false); this._noVScale = (0 != bits.GetBits(1) ? true : false); this._pixelHinting = (0 != bits.GetBits(1) ? true : false); bits.GetBits(5); // reserved must be null this._noClose = (0 != bits.GetBits(1) ? true : false); this._endCapStyle = (CapStyle)bits.GetBits(2); if (this._joinstyle.Equals(JoinStyle.Miter)) { this._miterLimtiFactor = br.ReadUInt16(); } if (!this._hasFillFlag) { this._startColor.Parse(input); this._endColor.Parse(input); } if (this._hasFillFlag) { //bits.Reset(); this._fillStyle.Parse(input); } }
/// <summary> /// /// </summary> /// <param name="input"></param> public virtual void Parse( Stream input ) { BitStream bits = new BitStream( input ); uint reserved = bits.GetBits( 2 ); if ( 0 != reserved ) { throw new SwfFormatException( "ButtonRecord reserved bits used" ); } _ButtonHasBlendMode = ( 0 != bits.GetBits( 1 ) ); _ButtonHasFilterList = ( 0 != bits.GetBits( 1 ) ); _ButtonStateHitTest = ( 0 != bits.GetBits( 1 ) ); _ButtonStateDown = ( 0 != bits.GetBits( 1 ) ); _ButtonStateOver = ( 0 != bits.GetBits( 1 ) ); _ButtonStateUp = ( 0 != bits.GetBits( 1 ) ); BinaryReader br = new BinaryReader( input ); _CharacterID = br.ReadUInt16(); _PlaceDepth = br.ReadUInt16(); _PlaceMatrix = new Matrix( this.Version ); _PlaceMatrix.Parse( input ); }
/// <summary> /// /// </summary> /// <param name="output"></param> /// <param name="version"></param> public virtual void Write( Stream output, byte version ) { BitStream bits = new BitStream( output ); // reserved bits.WriteBits( 2, 0 ); bits.WriteBits( 1, ( _ButtonHasBlendMode ? 1 : 0 ) ); bits.WriteBits( 1, ( _ButtonHasFilterList ? 1 : 0 ) ); bits.WriteBits( 1, ( _ButtonStateHitTest ? 1 : 0 ) ); bits.WriteBits( 1, ( _ButtonStateDown ? 1 : 0 ) ); bits.WriteBits( 1, ( _ButtonStateOver ? 1 : 0 ) ); bits.WriteBits( 1, ( _ButtonStateUp ? 1 : 0 ) ); bits.WriteFlush(); BinaryWriter bw = new BinaryWriter( output ); bw.Write( _CharacterID ); bw.Write( _PlaceDepth ); _PlaceMatrix.Write( output ); }
/// <summary> /// /// </summary> /// <param name="output"></param> public void Write( Stream output ) { this._fillStyles.Write( output ); this._lineStyles.Write( output ); BitStream bits = new BitStream( output ); bits.WriteBits( 4, ( Int32 )this._numFillBits ); bits.WriteBits( 4, ( Int32 )this._numLineBits ); }
/// <summary> /// /// </summary> /// <param name="output"></param> public override void Write(Stream output) { BitStream bits = new BitStream(output); BinaryWriter bw = new BinaryWriter(output); bw.Write(this._startWidth); bw.Write(this._endWidth); bits.WriteBits(2, (Int32)this._startCapStyle); bits.WriteBits(2, (Int32)this._joinstyle); bits.WriteBits(1, Convert.ToInt32(this._hasFillFlag)); bits.WriteBits(1, Convert.ToInt32(this._noHScale)); bits.WriteBits(1, Convert.ToInt32(this._noVScale)); bits.WriteBits(1, Convert.ToInt32(this._pixelHinting)); bits.WriteBits(5, 0); // reserved bits.WriteBits(1, Convert.ToInt32(this._noClose)); bits.WriteBits(2, (Int32)this._endCapStyle); bits.WriteFlush(); if (this._joinstyle.Equals(JoinStyle.Miter)) { bits.WriteBitsFB(16, this._miterLimtiFactor); } if (!this._hasFillFlag) { this._startColor.Write(output); this._endColor.Write(output); } else { this._fillStyle.Write(output); } }
/// <summary> /// /// </summary> /// <param name="output"></param> public void Write( Stream output ) { BitStream bits = new BitStream( output ); if ( _HasScale ) { int scaleBitsX = bits.CountNeededBitsFB( _xScaleF ); int scaleBitsY = bits.CountNeededBitsFB( _yScaleF ); int scaleBits = scaleBitsX > scaleBitsY ? scaleBitsX : scaleBitsY; bits.WriteBits( 1, 1 ); // HasScale bits.WriteBits( 5, scaleBits ); bits.WriteBitsFB( scaleBits, _xScaleF ); bits.WriteBitsFB( scaleBits, _yScaleF ); } else { bits.WriteBits( 1, 0 ); // Has no Scale } if ( _HasRotate ) { int rotateBits0 = bits.CountNeededBitsFB( _rotateSkew0F ); int rotateBits1 = bits.CountNeededBitsFB( _rotateSkew1F ); int rotateBits = rotateBits0 > rotateBits1 ? rotateBits0 : rotateBits1; bits.WriteBits( 1, 1 ); // HasRotate bits.WriteBits( 5, rotateBits ); bits.WriteBitsFB( rotateBits, _rotateSkew0F ); bits.WriteBitsFB( rotateBits, _rotateSkew1F ); } else { bits.WriteBits( 1, 0 ); // has no Rotate } int translateBits = bits.CountMaximumBits( _translateX, _translateY ); if (this._SwfVersion > 8) { bits.WriteBits(5, this._numTranslateBits); bits.WriteBits(this._numTranslateBits, _translateX); bits.WriteBits(this._numTranslateBits, _translateY); } else { bits.WriteBits(5, translateBits); bits.WriteBits(translateBits, _translateX); bits.WriteBits(translateBits, _translateY); } bits.WriteFlush(); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public void Parse( Stream input, TagTypes caller ) { this._fillStyles.Parse( input, caller ); this._lineStyles.Parse( input, caller ); BitStream bits = new BitStream( input ); this._numFillBits = (byte)bits.GetBits( 4 ); this._numLineBits = (byte)bits.GetBits( 4 ); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="bits"></param> public override void Parse(Stream input, BitStream bits) { bits.GetBits(6); bits.WriteFlush(); }
/// <summary> /// /// </summary> /// <param name="output"></param> /// <param name="bits"></param> public override void Write(Stream output, BitStream bits) { bits.WriteBits(6, 0); }
/// <summary> /// Writes this object back to a stream. /// </summary> /// <param name="output">The stream to write to.</param> public virtual void Write(Stream output) { BitStream bits = new BitStream(output); bits.WriteBits(4, (Int32)this._numFillBits); bits.WriteBits(4, (Int32)this._numLineBits); bits.WriteFlush(); output.Write(this._shapeRecordBuffer, 0, this._shapeRecordBuffer.Length); }
/// <summary> /// /// </summary> /// <param name="output"></param> public void Write(Stream output) { BitStream bits = new BitStream(output); if (_HasScale) { int scaleBitsX = bits.CountNeededBitsFB(_xScaleF); int scaleBitsY = bits.CountNeededBitsFB(_yScaleF); int scaleBits = scaleBitsX > scaleBitsY ? scaleBitsX : scaleBitsY; bits.WriteBits(1, 1); // HasScale bits.WriteBits(5, scaleBits); bits.WriteBitsFB(scaleBits, _xScaleF); bits.WriteBitsFB(scaleBits, _yScaleF); } else { bits.WriteBits(1, 0); // Has no Scale } bits.WriteBits(1, 0); // has no Rotate int translateBits = bits.CountMaximumBits(_translateX, _translateY); bits.WriteBits(5, translateBits); bits.WriteBits(translateBits, _translateX); bits.WriteBits(translateBits, _translateY); bits.WriteFlush(); }
/// <summary> /// /// </summary> /// <param name="input"></param> public void Parse( Stream input ) { BitStream bits = new BitStream( input ); _HasAddTerms = ( 1 == bits.GetBits( 1 ) ); _HasMultTerms = ( 1 == bits.GetBits( 1 ) ); _numBits = (byte)bits.GetBits( 4 ); if ( _HasMultTerms ) { _RedMultTerm = bits.GetBitsSigned( _numBits ); _GreenMultTerm = bits.GetBitsSigned( _numBits ); _BlueMultTerm = bits.GetBitsSigned( _numBits ); _AlphaMultTerm = bits.GetBitsSigned( _numBits ); } if ( _HasAddTerms ) { _RedAddTerm = bits.GetBitsSigned( _numBits ); _GreenAddTerm = bits.GetBitsSigned( _numBits ); _BlueAddTerm = bits.GetBitsSigned( _numBits ); _AlphaAddTerm = bits.GetBitsSigned( _numBits ); } if ( ( !_HasAddTerms ) && ( !_HasMultTerms ) ) { // // When none of the two flags are set, get the remaining bits // so that the entire method here works byte aligned // bits.GetBitsSigned( 2 ); } }
/// <summary> /// /// </summary> /// <param name="output"></param> public void Write( Stream output ) { BitStream bits = new BitStream( output ); int maxBits = this.BitCount; if ( 0 == maxBits ) { // // special case: must be byte-aligned by hand // bits.WriteBits( 2, 0 ); // has no Terms whatsoever bits.WriteBits( 4, 1 ); // 1 Bit per nothing bits.WriteBits( 2, 0 ); // nothing } else { bits.WriteBits( 1, ( _HasAddTerms ? 1 : 0 ) ); bits.WriteBits( 1, ( _HasMultTerms ? 1 : 0 ) ); bits.WriteBits( 4, maxBits ); if ( _HasMultTerms ) { bits.WriteBits( maxBits, _RedMultTerm ); bits.WriteBits( maxBits, _GreenMultTerm ); bits.WriteBits( maxBits, _BlueMultTerm ); bits.WriteBits( maxBits, _AlphaMultTerm ); } if ( _HasAddTerms ) { bits.WriteBits( maxBits, _RedAddTerm ); bits.WriteBits( maxBits, _GreenAddTerm ); bits.WriteBits( maxBits, _BlueAddTerm ); bits.WriteBits( maxBits, _AlphaAddTerm ); } } bits.WriteFlush(); }
/// <summary> /// /// </summary> /// <param name="output"></param> /// <param name="bits"></param> public override void Write(Stream output, BitStream bits ) { bits.WriteBits(1, 1); // type flag = 1 bits.WriteBits(1, 1); // straight flag = 1 bits.WriteBits(4, (UInt32)this._numbits); bits.WriteBits(1, (true == this._generalLineFlag ? 1 : 0)); if (!this._generalLineFlag) { bits.WriteBits(1, (true == this._vertLineFlag ? 1 : 0)); if (!this._vertLineFlag) { bits.WriteBits((Int32)this._numbits + 2, this._deltaX); } else { bits.WriteBits((Int32)this._numbits + 2, this._deltaY); } } else { bits.WriteBits((Int32)this._numbits + 2, this._deltaX); bits.WriteBits((Int32)this._numbits + 2, this._deltaY); } }
/// <summary> /// Writes this object back to a stream. /// </summary> /// <param name="output">The stream to write to.</param> public override void Write(Stream output) { BitStream bits = new BitStream(output); bits.WriteBits(1, 0); //reserved bits.WriteBits(5, this._Red); bits.WriteBits(5, this._Green); bits.WriteBits(5, this._Blue); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="length"></param> /// <param name="caller"></param> public virtual void Parse(Stream input, Int64 length, TagTypes caller) { BitStream bits = new BitStream(input); this._numFillBits = (UInt16)bits.GetBits(4); this._numLineBits = (UInt16)bits.GetBits(4); if (length >= 1) { this._shapeRecordBuffer = new Byte[length - 1]; input.Read(this._shapeRecordBuffer, 0, (Int32)length - 1); this._shapeRecordStream = new MemoryStream(); this._shapeRecordStream.Write(this._shapeRecordBuffer, 0, this._shapeRecordBuffer.Length); // To protect the input stream this._shapeRecordStream.Seek(0, SeekOrigin.Begin); this.TryParseShapeRecords(this._shapeRecordStream, caller); } else { Log.Warn(this, "Attempt to parse shapes out of a too small field by: " + caller + ". Length was: " + length); } }
/// <summary> /// Writes this object back to a stream /// </summary> /// <param name="output">The stream to write to.</param> public void Write(Stream output) { if (this._zoneData.Count != (Int32)this._numZoneData) { SwfFormatException e = new SwfFormatException("The count of List<ZoneData> and the byte value of zone data differs. "); Log.Error(this, e.Message); throw e; } output.WriteByte(this._numZoneData); for (int i = 0; i < this._zoneData.Count; i++) { this._zoneData[i].Write(output); } BitStream bits = new BitStream(output); bits.WriteBits(6, 0); //reserved bits.WriteBits(1, Convert.ToInt32(this._zoneMaskY)); bits.WriteBits(1, Convert.ToInt32(this._zoneMaskX)); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public virtual void TryParseShapeRecords(MemoryStream input, TagTypes caller) { BitStream bits = new BitStream(input); this._shapeRecords = new List<ShapeRecord>(); StyleChangeRecord tempSCR = new StyleChangeRecord(this._SwfVersion); StraightEdgeRecord tempSER = new StraightEdgeRecord(this._SwfVersion); CurvedEdgeRecord tempCER = new CurvedEdgeRecord(this._SwfVersion); byte fiveBits = 0; bool endShapeRecordSeen = false; int numberOfStyleChanges = 0; UInt16 localNumFillBits = this._numFillBits; UInt16 localNumLineBits = this._numLineBits; do { bool typeFlag = (0 != bits.GetBits(1)) ? true : false; if (typeFlag) { bool straightFlag = Convert.ToBoolean(bits.GetBits(1)); if (straightFlag) { tempSER = new StraightEdgeRecord(this._SwfVersion); tempSER.Parse(input, bits); this._shapeRecords.Add(tempSER); } else { tempCER = new CurvedEdgeRecord(this._SwfVersion); tempCER.Parse(input, bits); this._shapeRecords.Add(tempCER); } } else { fiveBits = (byte)bits.GetBits(5); if (0 == fiveBits) { endShapeRecordSeen = true; } else { tempSCR = new StyleChangeRecord(this._SwfVersion); tempSCR.Parse(input, bits, fiveBits, caller, ref localNumFillBits, ref localNumLineBits, 0 == numberOfStyleChanges ? true : false); numberOfStyleChanges += 1; this._shapeRecords.Add(tempSCR); } } } while (!endShapeRecordSeen); bits.Reset(); }