public static DefineBitsLossless build(LosslessImage image)
		{
			DefineBitsLossless defineBitsLossless = new DefineBitsLossless(flash.swf.TagValues_Fields.stagDefineBitsLossless2);
			defineBitsLossless.format = 5;
			
			defineBitsLossless.width = image.Width;
			defineBitsLossless.height = image.Height;
			int[] pixels = (int[]) image.Pixels;
			
			defineBitsLossless.data = new sbyte[pixels.Length * 4];
			
			for (int i = 0; i < pixels.Length; i++)
			{
				int offset = i * 4;
				int alpha = (pixels[i] >> 24) & 0xFF;
				defineBitsLossless.data[offset] = (sbyte) alpha;
				
				// [preilly] Ignore the other components if alpha is transparent.  This seems
				// to be a bug in the player.  Additionally, premultiply the alpha and the
				// colors, because the player expects this.
				if (defineBitsLossless.data[offset] != 0)
				{
					int red = (pixels[i] >> 16) & 0xFF;
					defineBitsLossless.data[offset + 1] = (sbyte) ((red * alpha) / 255);
					int green = (pixels[i] >> 8) & 0xFF;
					defineBitsLossless.data[offset + 2] = (sbyte) ((green * alpha) / 255);
					int blue = pixels[i] & 0xFF;
					defineBitsLossless.data[offset + 3] = (sbyte) ((blue * alpha) / 255);
				}
			}
			
			return defineBitsLossless;
		}
        public static DefineBitsLossless build(LosslessImage image)
        {
            DefineBitsLossless defineBitsLossless = new DefineBitsLossless(flash.swf.TagValues_Fields.stagDefineBitsLossless2);

            defineBitsLossless.format = 5;

            defineBitsLossless.width  = image.Width;
            defineBitsLossless.height = image.Height;
            int[] pixels = (int[])image.Pixels;

            defineBitsLossless.data = new sbyte[pixels.Length * 4];

            for (int i = 0; i < pixels.Length; i++)
            {
                int offset = i * 4;
                int alpha  = (pixels[i] >> 24) & 0xFF;
                defineBitsLossless.data[offset] = (sbyte)alpha;

                // [preilly] Ignore the other components if alpha is transparent.  This seems
                // to be a bug in the player.  Additionally, premultiply the alpha and the
                // colors, because the player expects this.
                if (defineBitsLossless.data[offset] != 0)
                {
                    int red = (pixels[i] >> 16) & 0xFF;
                    defineBitsLossless.data[offset + 1] = (sbyte)((red * alpha) / 255);
                    int green = (pixels[i] >> 8) & 0xFF;
                    defineBitsLossless.data[offset + 2] = (sbyte)((green * alpha) / 255);
                    int blue = pixels[i] & 0xFF;
                    defineBitsLossless.data[offset + 3] = (sbyte)((blue * alpha) / 255);
                }
            }

            return(defineBitsLossless);
        }
        public static DefineBits build(System.String name, LosslessImage image)
        {
            DefineBitsLossless defineBits = build(image);

            defineBits.name = name;
            return(defineBits);
        }
        public static DefineTag buildSprite(System.String name, LosslessImage image)
        {
            TagList            taglist    = new TagList();
            DefineBitsLossless defineBits = build(image);

            taglist.defineBitsLossless2(defineBits);

            DefineShape ds3 = ImageShapeBuilder.buildImage(defineBits, defineBits.width, defineBits.height);

            taglist.defineShape3(ds3);

            PlaceObject po2 = new PlaceObject(ds3, 1);

            po2.Matrix = new Matrix();
            //Ahipo2.setName(name);

            taglist.placeObject2(po2);

            return(defineSprite(name, taglist));
        }
Exemple #5
0
        /// <summary> Utility method to create an appropriate <code>FillStyle</code> from a <code>Paint</code>.</summary>
        /// <param name="paint">an AWT <code>Paint</code> instance
        /// </param>
        /// <param name="bounds">- required for gradient ratio calculation
        /// </param>
        /// <returns> a new <code>FillStyle</code> representing the given paint
        /// </returns>
        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
        public static FillStyle build(System.Drawing.Brush paint, ref System.Drawing.RectangleF bounds, System.Drawing.Drawing2D.Matrix transform)
        {
            FillStyle fs = null;

            if (paint != null)
            {
                double width  = (double)bounds.Width;
                double height = (double)bounds.Height;

                if (paint is System.Drawing.Color)
                {
                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    fs = new FillStyle(SwfUtils.colorToInt(ref new System.Drawing.Color[] { (System.Drawing.Color)paint }[0]));
                }
                else if (paint is System.Drawing.Drawing2D.LinearGradientBrush)
                {
                    System.Drawing.Drawing2D.LinearGradientBrush gp = (System.Drawing.Drawing2D.LinearGradientBrush)paint;
                    //UPGRADE_ISSUE: Method 'java.awt.geom.AffineTransform.transform' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtgeomAffineTransformtransform_javaawtgeomPoint2D_javaawtgeomPoint2D'"
                    System.Drawing.PointF tempAux  = System.Drawing.PointF.Empty;
                    System.Drawing.PointF tempAux2 = System.Drawing.PointF.Empty;
                    System.Drawing.PointF tempAux3 = transform.transform(new System.Drawing.PointF(gp.Rectangle.X, gp.Rectangle.Y), tempAux);
                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    System.Drawing.PointF           tempAux4 = transform.transform(new System.Drawing.PointF(gp.Rectangle.Height, gp.Rectangle.Width), tempAux2);
                    System.Drawing.Drawing2D.Matrix gt       = objectBoundingBoxTransform(ref tempAux3, ref tempAux4, width, height, width, height);
                    fs        = new FillStyle();
                    fs.matrix = MatrixBuilder.build(gt);

                    fs.type = FillStyle.FILL_LINEAR_GRADIENT;

                    fs.gradient         = new Gradient();
                    fs.gradient.records = new GradRecord[2];
                    System.Drawing.Color tempAux5 = (gp.LinearColors)[0];
                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    fs.gradient.records[0] = new GradRecord(0, SwfUtils.colorToInt(ref tempAux5));                     //from left
                    System.Drawing.Color tempAux6 = (gp.LinearColors)[1];
                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    fs.gradient.records[1] = new GradRecord(255, SwfUtils.colorToInt(ref tempAux6));                     //to right
                }
                else if (paint is LinearGradientPaint)
                {
                    LinearGradientPaint   lgp   = (LinearGradientPaint)paint;
                    System.Drawing.PointF start = lgp.getStartPoint();
                    System.Drawing.PointF end   = lgp.getEndPoint();

                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref start, ref end, width, height, width, height);

                    fs        = new FillStyle();
                    fs.matrix = MatrixBuilder.build(gt);

                    System.Drawing.Color[] colors = lgp.getColors();
                    float[] ratios = lgp.getFractions();

                    if (colors.Length == 0 || colors.Length != ratios.Length)
                    //Invalid fill so we skip
                    {
                        return(null);
                    }
                    else if (colors.Length == 1)
                    //Solid fill
                    {
                        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                        return(new FillStyle(SwfUtils.colorToInt(ref colors[0])));
                    }
                    else
                    {
                        fs.type = FillStyle.FILL_LINEAR_GRADIENT;

                        //Maximum of 8 gradient control points records
                        int len = ratios.Length;
                        if (len > 8)
                        {
                            len = 8;
                        }
                        fs.gradient         = new Gradient();
                        fs.gradient.records = new GradRecord[len];

                        for (int i = 0; i < len; i++)
                        {
                            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                            //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                            fs.gradient.records[i] = new GradRecord((int)System.Math.Round((double)(255 * ratios[i])), SwfUtils.colorToInt(ref colors[i]));
                        }
                    }
                }
                else if (paint is RadialGradientPaint)
                {
                    RadialGradientPaint rgp = (RadialGradientPaint)paint;

                    //Note: Flash doesn't support the focal point of a radial gradient
                    //Point2D cp = rgp.getCenterPoint();
                    //Point2D fp = rgp.getFocusPoint();
                    double diameter = rgp.getRadius() * 2.0;
                    double outerX   = diameter * rgp.getTransform().getScaleX();
                    double outerY   = diameter * rgp.getTransform().getScaleY();

                    System.Drawing.PointF tempAux7 = System.Drawing.PointF.Empty;
                    System.Drawing.PointF tempAux8 = System.Drawing.PointF.Empty;
                    //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                    System.Drawing.Drawing2D.Matrix gt = objectBoundingBoxTransform(ref tempAux7, ref tempAux8, width, height, outerX, outerY);
                    fs        = new FillStyle();
                    fs.matrix = MatrixBuilder.build(gt);

                    fs.type = FillStyle.FILL_RADIAL_GRADIENT;

                    System.Drawing.Color[] colors = rgp.getColors();
                    float[] ratios = rgp.getFractions();

                    fs.gradient         = new Gradient();
                    fs.gradient.records = new GradRecord[ratios.Length <= 8?ratios.Length:8];
                    for (int i = 0; i < ratios.Length && i < 8; i++)
                    {
                        //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                        //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                        fs.gradient.records[i] = new GradRecord((int)System.Math.Round((double)(255 * ratios[i])), SwfUtils.colorToInt(ref colors[i]));
                    }
                }
                else if (paint is System.Drawing.TextureBrush)
                {
                    System.Drawing.TextureBrush tp    = (System.Drawing.TextureBrush)paint;
                    System.Drawing.Image        image = (System.Drawing.Image)tp.Image;

                    DefineBitsLossless tag = DefineBitsLosslessBuilder.build(new LosslessImage(image));

                    //Apply Twips Scale of 20 x 20
                    System.Drawing.Drawing2D.Matrix at = new System.Drawing.Drawing2D.Matrix();
                    at.Scale((System.Single)flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL, (System.Single)flash.swf.SwfConstants_Fields.TWIPS_PER_PIXEL);
                    Matrix matrix = MatrixBuilder.build(at);

                    fs = new FillStyle(FillStyle.FILL_BITS, matrix, tag);
                }
            }

            return(fs);
        }