private void  encodeClipEventFlags(int flags, SwfEncoder w)
 {
     if (w.swfVersion >= 6)
     {
         w.write32(flags);
     }
     else
     {
         w.writeUI16(flags);
     }
 }
		private void  encodeBevelFilter(SwfEncoder w, BevelFilter f)
		{
			encodeRGBA(f.shadowColor, w);
			encodeRGBA(f.highlightColor, w);
			w.write32(f.blurX);
			w.write32(f.blurY);
			w.write32(f.angle);
			w.write32(f.distance);
			w.writeUI16(f.strength);
			w.writeUI8(f.flags);
		}
		private void  encodeGlowFilter(SwfEncoder w, GlowFilter f)
		{
			encodeRGBA(f.color, w);
			w.write32(f.blurX);
			w.write32(f.blurY);
			w.writeUI16(f.strength);
			w.writeUI8(f.flags);
		}
		private void  encodeDropShadowFilter(SwfEncoder w, DropShadowFilter f)
		{
			encodeRGBA(f.color, w);
			w.write32(f.blurX);
			w.write32(f.blurY);
			w.write32(f.angle);
			w.write32(f.distance);
			w.writeUI16(f.strength);
			w.writeUI8(f.flags);
		}
		private void  encodeDefineText(DefineText tag, SwfEncoder w, int type)
		{
			int id = dict.add(tag);
			w.writeUI16(id);
			encodeRect(tag.bounds, w);
			encodeMatrix(tag.matrix, w);
			int length = tag.records.Count;
			
			// compute necessary bit width
			int glyphBits = 0;
			int advanceBits = 0;
			for (int i = 0; i < length; i++)
			{
				TextRecord tr = (TextRecord) tag.records[i];
				
				for (int j = 0; j < tr.entries.Length; j++)
				{
					GlyphEntry entry = tr.entries[j];
					
					while (entry.Index > (1 << glyphBits))
						glyphBits++;
					while (System.Math.Abs(entry.advance) > (1 << advanceBits))
						advanceBits++;
				}
			}
			
			// increment to get from bit index to bit count.
			++glyphBits;
			++advanceBits;
			
			w.writeUI8(glyphBits);
			w.writeUI8(++advanceBits); // add one extra bit because advances are signed
			
			for (int i = 0; i < length; i++)
			{
				TextRecord record = (TextRecord) tag.records[i];
				encodeTextRecord(record, w, type, glyphBits, advanceBits);
			}
			
			w.writeUI8(0);
		}
        //    public void inlineBinaryOp(InlineBinaryOp op)
        //    {
        //        writer.writeU8(op.code);
        //        writer.writeU8(op.dst);
        //        encodeOperand(op.lhs, op.rhs);
        //    }

        //    private void encodeOperand(Object lhs, Object rhs)
        //    {
        //        int lhsType = operandType(lhs);
        //        int rhsType = operandType(rhs);
        //        writer.writeU8(lhsType >> 4 | rhsType);
        //        encodeOperand(lhsType, lhs);
        //        encodeOperand(rhsType, rhs);
        //    }
        //
        //    private void encodeOperand(Object operand)
        //    {
        //        int type = operandType(operand);
        //        writer.writeU8(type);
        //        encodeOperand(type, operand);
        //    }
        //
        //    public void inlineBranchWhenFalse(InlineBranchWhenFalse op)
        //    {
        //        writer.writeU8(op.code);
        //        int pos = writer.getPos();
        //        writer.writeU8(op.cond);
        //        encodeOperand(op.lhs, op.rhs);
        //        Integer offset = (Integer) labels.get(op.target);
        //        if (offset != null)
        //        {
        //            // label came earlier
        //            writer.writeU16(offset.intValue() - pos - 2);
        //        }
        //        else
        //        {
        //            // label comes later. don't know the offset yet.
        //			updates.add(new UpdateEntry(pos+2, pos, op));
        //            writer.writeU16(0);
        //        }
        //    }

        //    public void inlineGetMember(InlineGetMember op)
        //    {
        //        writer.writeU8(op.code);
        //        writer.writeU8(op.dst);
        //        writer.writeU8(op.src);
        //        encodeOperand(op.member);
        //    }
        //
        //    public void inlineSetMember(InlineSetMember op)
        //    {
        //        writer.writeU8(op.code);
        //        writer.writeU8(op.dst);
        //        encodeOperand(op.member, op.src);
        //    }

        //    public void inlineSetRegister(InlineSetRegister op)
        //    {
        //        writer.writeU8(op.code);
        //        writer.writeU8(op.dst);
        //        encodeOperand(op.value);
        //    }
        //
        //    public void inlineUnaryRegOp(InlineUnaryRegOp op)
        //    {
        //        writer.writeU8(op.code);
        //        writer.writeU8(op.register);
        //    }

        //    private void encodeOperand(int opType, Object operand)
        //    {
        //        switch (opType)
        //        {
        //        case ActionConstants.kInlineTrue:
        //        case ActionConstants.kInlineFalse:
        //        case ActionConstants.kInlineNull:
        //        case ActionConstants.kInlineUndefined:
        //            // do nothing, type implies value
        //            break;
        //        case ActionConstants.kInlineConstantByte:
        //        case ActionConstants.kInlineChar:
        //        case ActionConstants.kInlineRegister:
        //            int i = ((Number)operand).intValue();
        //            writer.writeU8(i);
        //            break;
        //        case ActionConstants.kInlineConstantWord:
        //        case ActionConstants.kInlineShort:
        //            i = ((Number)operand).intValue();
        //            writer.writeU16(i);
        //            break;
        //        case ActionConstants.kInlineLong:
        //            i = ((Number)operand).intValue();
        //            writer.write32(i);
        //            break;
        //        case ActionConstants.kInlineDouble:
        //            long num = Double.doubleToLongBits(((Number)operand).doubleValue());
        //            writer.write32((int)(num>>32));
        //            writer.write32((int)num);
        //            break;
        //        }
        //    }

        //    private int operandType(Object operand)
        //    {
        //        if (operand == Boolean.TRUE)
        //            return ActionConstants.kInlineTrue;
        //        else if (operand == Boolean.FALSE)
        //            return ActionConstants.kInlineFalse;
        //        else if (operand == ActionFactory.UNDEFINED)
        //            return ActionConstants.kInlineUndefined;
        //        else if (operand == ActionFactory.STACKTOP)
        //            return ActionConstants.kInlineStack;
        //        else if (operand == null)
        //            return ActionConstants.kInlineNull;
        //        else if (operand instanceof Short)
        //            return ((Short)operand).intValue() < 256 ? ActionConstants.kInlineConstantByte : ActionConstants.kInlineConstantWord;
        //        else if (operand instanceof Double)
        //            return ActionConstants.kInlineDouble;
        //        else if (operand instanceof Integer)
        //            return (((Integer)operand).intValue() & ~0xFF) == 0 ? ActionConstants.kInlineChar :
        //                   (((Integer)operand).intValue() & ~0xFFFF) == 0 ? ActionConstants.kInlineShort :
        //                    ActionConstants.kInlineLong;
        //        else if (operand instanceof Byte)
        //            return ActionConstants.kInlineRegister;
        //        else
        //            throw new IllegalArgumentException("unknown operand type " + operand.getClass().getName());
        //    }

        public override void  call(Action action)
        {
            writer.writeUI8(action.code);
            // this action's opcode 0x9E has hi bit set, but it never has data.  considered a permanent minor bug.
            writer.writeUI16(0);
        }
		private void  encodeButtonCondAction(ButtonCondAction condAction, SwfEncoder w, bool last)
		{
			int pos = w.Pos;
			w.writeUI16(0);
			
			w.writeUBits(condAction.keyPress, 7);
			w.writeBit(condAction.overDownToIdle);
			
			w.writeBit(condAction.idleToOverDown);
			w.writeBit(condAction.outDownToIdle);
			w.writeBit(condAction.outDownToOverDown);
			w.writeBit(condAction.overDownToOutDown);
			w.writeBit(condAction.overDownToOverUp);
			w.writeBit(condAction.overUpToOverDown);
			w.writeBit(condAction.overUpToIdle);
			w.writeBit(condAction.idleToOverUp);
			
			new ActionEncoder(w, debug).encode(condAction.actionList);
			w.writeUI8(0); // end action byte
			
			if (!last)
			{
				w.writeUI16at(pos, w.Pos - pos);
			}
		}
		public override void  header(Header header)
		{
			// get some header properties we need to know
			int swfVersion = header.version;
			this.header_Renamed_Field = header;
			this.writer = createEncoder(swfVersion);
			this.tagw = createEncoder(swfVersion);
			width = header.size.Width;
			height = header.size.Height;
			frames = 0;
			
			// write the header
			writer.writeUI8(header.compressed?'C':'F');
			writer.writeUI8('W');
			writer.writeUI8('S');
			writer.writeUI8(header.version);
			writer.write32((int) header.length);
			if (header.compressed)
			{
				writer.markComp();
			}
			encodeRect(header.size, writer);
			writer.writeUI8(header.rate >> 8);
			writer.writeUI8(header.rate & 255);
			framecountPos = writer.Pos;
			writer.writeUI16(header.framecount);
		}
		private void  encodeMorphFillstyles(MorphFillStyle[] fillStyles, SwfEncoder w, int code)
		{
			int count = fillStyles.Length;
			if (count >= 0xFF)
			{
				w.writeUI8(0xFF);
				w.writeUI16(count);
			}
			else
			{
				w.writeUI8(count);
			}
			
			for (int i = 0; i < count; i++)
			{
				encodeMorphFillstyle(fillStyles[i], w, code);
			}
		}
		private void  encodeKerningRecord(KerningRecord kerningRecord, SwfEncoder w, bool wideCodes)
		{
			if (wideCodes)
			{
				w.writeUI16(kerningRecord.code1);
				w.writeUI16(kerningRecord.code2);
			}
			else
			{
				w.writeUI8(kerningRecord.code1);
				w.writeUI8(kerningRecord.code2);
			}
			w.writeUI16(kerningRecord.adjustment);
		}
		private void  encodeFillStyle(FillStyle style, SwfEncoder w, int shape)
		{
			w.writeUI8(style.type);
			switch (style.type)
			{
				
				case FillStyle.FILL_SOLID:  // 0x00
					if ((shape == flash.swf.TagValues_Fields.stagDefineShape3) || (shape == flash.swf.TagValues_Fields.stagDefineShape6))
						encodeRGBA(style.color, w);
					else
						encodeRGB(style.color, w);
					break;
				
				case FillStyle.FILL_GRADIENT: 
				// 0x10 linear gradient fill
				case FillStyle.FILL_RADIAL_GRADIENT: 
				// 0x12 radial gradient fill
				case FillStyle.FILL_FOCAL_RADIAL_GRADIENT:  // 0x13 focal radial gradient fill
					encodeMatrix(style.matrix, w);
					encodeGradient(style.gradient, w, shape);
					break;
				
				case FillStyle.FILL_BITS: 
				// 0x40 tiled bitmap fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_CLIP): 
				// 0x41 clipped bitmap fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_NOSMOOTH): 
				// 0x42 tiled non-smoothed fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_CLIP | FillStyle.FILL_BITS_NOSMOOTH):  // 0x43 clipped non-smoothed fill
					w.writeUI16(dict.getId(style.bitmap));
					encodeMatrix(style.matrix, w);
					break;
				}
		}
		private void  encodeFillstyles(System.Collections.ArrayList fillstyles, SwfEncoder w, int shape)
		{
			int count = fillstyles.Count;
			if (count >= 0xFF)
			{
				w.writeUI8(0xFF);
				w.writeUI16(count);
			}
			else
			{
				w.writeUI8(count);
			}
			
			System.Collections.IEnumerator it = fillstyles.GetEnumerator();
			//UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
			while (it.MoveNext())
			{
				//UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
				FillStyle style = (FillStyle) it.Current;
				encodeFillStyle(style, w, shape);
			}
		}
		private void  encodeLineStyle(LineStyle lineStyle, SwfEncoder w, int shape)
		{
			w.writeUI16(lineStyle.width);
			
			if (shape == flash.swf.TagValues_Fields.stagDefineShape6)
			{
				w.writeUI16(lineStyle.flags);
				if (lineStyle.hasMiterJoint())
					w.writeUI16(lineStyle.miterLimit);
			}
			
			if (shape == flash.swf.TagValues_Fields.stagDefineShape6 && lineStyle.hasFillStyle())
			{
				encodeFillStyle(lineStyle.fillStyle, w, shape);
			}
			else if ((shape == flash.swf.TagValues_Fields.stagDefineShape3) || (shape == flash.swf.TagValues_Fields.stagDefineShape6))
			{
				encodeRGBA(lineStyle.color, w);
			}
			else
			{
				encodeRGB(lineStyle.color, w);
			}
		}
		private void  encodeLinestyles(System.Collections.ArrayList linestyles, SwfEncoder w, int shape)
		{
			int count = linestyles.Count;
			if (count > 0xFF)
			{
				w.writeUI8(0xFF);
				w.writeUI16(count);
			}
			else
			{
				w.writeUI8(count);
			}
			
			for (int i = 0; i < count; i++)
			{
				encodeLineStyle((LineStyle) linestyles[i], w, shape);
			}
		}
		private void  encodeGradientBevelFilter(SwfEncoder w, GradientBevelFilter f)
		{
			w.writeUI8(f.numcolors);
			for (int i = 0; i < f.numcolors; ++i)
				encodeRGBA(f.gradientColors[i], w);
			for (int i = 0; i < f.numcolors; ++i)
				w.writeUI8(f.gradientRatio[i]);
			
			//        w.write32( f.shadowColor );
			//        w.write32( f.highlightColor );
			w.write32(f.blurX);
			w.write32(f.blurY);
			w.write32(f.angle);
			w.write32(f.distance);
			w.writeUI16(f.strength);
			w.writeUI8(f.flags);
		}
		private void  encodeMorphFillstyle(MorphFillStyle style, SwfEncoder w, int code)
		{
			w.writeUI8(style.type);
			switch (style.type)
			{
				
				case FillStyle.FILL_SOLID:  // 0x00
					encodeRGBA(style.startColor, w);
					encodeRGBA(style.endColor, w);
					break;
				
				case FillStyle.FILL_GRADIENT: 
				// 0x10 linear gradient fill
				case FillStyle.FILL_RADIAL_GRADIENT: 
				// 0x12 radial gradient fill
				case FillStyle.FILL_FOCAL_RADIAL_GRADIENT:  // 0x13 focal radial gradient fill
					encodeMatrix(style.startGradientMatrix, w);
					encodeMatrix(style.endGradientMatrix, w);
					encodeMorphGradient(style.gradRecords, w);
					if (style.type == FillStyle.FILL_FOCAL_RADIAL_GRADIENT && code == flash.swf.TagValues_Fields.stagDefineMorphShape2)
					{
						w.writeSI16(style.ratio1);
						w.writeSI16(style.ratio2);
					}
					break;
				
				case FillStyle.FILL_BITS: 
				// 0x40 tiled bitmap fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_CLIP): 
				// 0x41 clipped bitmap fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_NOSMOOTH): 
				// 0x42 tiled non-smoothed fill
				case (FillStyle.FILL_BITS | FillStyle.FILL_BITS_CLIP | FillStyle.FILL_BITS_NOSMOOTH):  // 0x43 clipped non-smoothed fill
					w.writeUI16(dict.getId(style.bitmap));
					encodeMatrix(style.startBitmapMatrix, w);
					encodeMatrix(style.endBitmapMatrix, w);
					break;
				
				default: 
					assert(false);
					//throw new IOException("unrecognized fill style type: " + style.type);
					break;
				
			}
		}
		private void  encodeTextRecord(TextRecord record, SwfEncoder w, int type, int glyphBits, int advanceBits)
		{
			w.writeUI8(record.flags);
			
			if (record.hasFont())
			{
				w.writeUI16(dict.getId(record.font));
			}
			
			if (record.hasColor())
			{
				if (type == flash.swf.TagValues_Fields.stagDefineText2)
					encodeRGBA(record.color, w);
				else
					encodeRGB(record.color, w);
			}
			
			if (record.hasX())
			{
				w.writeSI16(record.xOffset);
			}
			
			if (record.hasY())
			{
				w.writeSI16(record.yOffset);
			}
			
			if (record.hasHeight())
			{
				w.writeUI16(record.height);
			}
			
			w.writeUI8(record.entries.Length);
			
			for (int i = 0; i < record.entries.Length; i++)
			{
				w.writeUBits(record.entries[i].Index, glyphBits);
				w.writeSBits(record.entries[i].advance, advanceBits);
			}
			w.flushBits();
		}
		private void  encodeMorphLinestyles(MorphLineStyle[] lineStyles, SwfEncoder w, int code)
		{
			if (lineStyles.Length >= 0xFF)
			{
				w.writeUI8(0xFF);
				w.writeUI16(lineStyles.Length);
			}
			else
			{
				w.writeUI8(lineStyles.Length);
			}
			
			for (int i = 0; i < lineStyles.Length; i++)
			{
				MorphLineStyle style = lineStyles[i];
				w.writeUI16(style.startWidth);
				w.writeUI16(style.endWidth);
				if (code == flash.swf.TagValues_Fields.stagDefineMorphShape2)
				{
					w.writeUBits(style.startCapsStyle, 2);
					w.writeUBits(style.jointStyle, 2);
					w.writeBit(style.hasFill);
					w.writeBit(style.noHScale);
					w.writeBit(style.noVScale);
					w.writeBit(style.pixelHinting);
					w.writeUBits(0, 5); // reserved
					w.writeBit(style.noClose);
					w.writeUBits(style.endCapsStyle, 2);
					if (style.jointStyle == 2)
					{
						w.writeUI16(style.miterLimit);
					}
				}
				if (!style.hasFill)
				{
					encodeRGBA(style.startColor, w);
					encodeRGBA(style.endColor, w);
				}
				if (style.hasFill)
				{
					encodeMorphFillstyle(style.fillType, w, code);
				}
			}
		}
		private void  encodeButtonRecord(ButtonRecord record, SwfEncoder w, int defineButton)
		{
			if (defineButton == flash.swf.TagValues_Fields.stagDefineButton2)
			{
				w.writeUBits(0, 2);
				w.writeBit(record.blendMode != - 1);
				w.writeBit(record.filters != null);
			}
			else
			{
				w.writeUBits(0, 4);
			}
			w.writeBit(record.hitTest);
			w.writeBit(record.down);
			w.writeBit(record.over);
			w.writeBit(record.up);
			
			w.writeUI16(dict.getId(record.characterRef));
			w.writeUI16(record.placeDepth);
			encodeMatrix(record.placeMatrix, w);
			
			if (defineButton == flash.swf.TagValues_Fields.stagDefineButton2)
			{
				encodeCxforma(record.colorTransform, w);
				if (record.filters != null)
				{
					this.encodeFilterList(record.filters, w);
				}
				if (record.blendMode != - 1)
				{
					w.writeUI8(record.blendMode);
				}
			}
		}
		public override void  defineSprite(DefineSprite tag)
		{
			int id = dict.add(tag);
			tagw.writeUI16(id);
			tagw.writeUI16(tag.framecount);
			
			if (Debug)
			{
				debug.adjust = writer.Pos + 6;
			}
			
			// save frame count
			int oldFrames = frames;
			frames = 0;
			
			// save the movie writer, and push a new writer
			SwfEncoder oldWriter = writer;
			writer = tagw;
			tagw = createEncoder(SwfVersion);
			
			// write sprite tags
			System.Collections.IList tags = tag.tagList.tags;
			int size = tags.Count;
			for (int i = 0; i < size; i++)
			{
				Tag t = (Tag) tags[i];
				if (!(t is DefineTag))
					t.visit(this);
			}
			
			// terminate with end marker
			writer.writeUI16(0);
			
			// update frame count
			writer.writeUI16at(2, frames);
			
			// restore writers
			tagw = writer;
			writer = oldWriter;
			frames = oldFrames;
			
			if (Debug)
			{
				debug.adjust = 0;
			}
			
			encodeTag(tag);
		}
		private void  encodeSoundInfo(SoundInfo info, SwfEncoder w)
		{
			w.writeUBits(0, 2); // reserved
			w.writeBit(info.syncStop);
			w.writeBit(info.syncNoMultiple);
			w.writeBit(info.records != null);
			w.writeBit(info.loopCount != SoundInfo.UNINITIALIZED);
			w.writeBit(info.outPoint != SoundInfo.UNINITIALIZED);
			w.writeBit(info.inPoint != SoundInfo.UNINITIALIZED);
			
			if (info.inPoint != SoundInfo.UNINITIALIZED)
			{
				w.write32((int) info.inPoint);
			}
			if (info.outPoint != SoundInfo.UNINITIALIZED)
			{
				w.write32((int) info.outPoint);
			}
			if (info.loopCount != SoundInfo.UNINITIALIZED)
			{
				w.writeUI16(info.loopCount);
			}
			if (info.records != null)
			{
				w.writeUI8(info.records.Length);
				for (int k = 0; k < info.records.Length; k++)
				{
					w.write64(info.records[k]);
				}
			}
		}
Beispiel #22
0
		private void  encodeClipEventFlags(int flags, SwfEncoder w)
		{
			if (w.swfVersion >= 6)
				w.write32(flags);
			else
				w.writeUI16(flags);
		}