コード例 #1
0
        Affine BuildImageBoundsPath(
           int srcW, int srcH,
           VertexStore drawImageRectPath,
           double destX, double destY)
        {
            AffinePlan plan = new AffinePlan();
            if (destX != 0 || destY != 0)
            {
                plan = AffinePlan.Translate(destX, destY);
            }

            drawImageRectPath.Clear();
            drawImageRectPath.AddMoveTo(0, 0);
            drawImageRectPath.AddLineTo(srcW, 0);
            drawImageRectPath.AddLineTo(srcW, srcH);
            drawImageRectPath.AddLineTo(0, srcH);
            drawImageRectPath.AddCloseFigure();
            return Affine.NewMatix(plan);
        }
コード例 #2
0
        Affine BuildImageBoundsPath(
            int srcW, int srcH,
            VertexStore drawImageRectPath,
            double destX, double destY,
            double hotspotOffsetX, double hotSpotOffsetY,
            double scaleX, double scaleY,
            double angleRad)
        {
            AffinePlan[] plan = new AffinePlan[4];
            int i = 0;
            if (hotspotOffsetX != 0.0f || hotSpotOffsetY != 0.0f)
            {
                plan[i] = AffinePlan.Translate(-hotspotOffsetX, -hotSpotOffsetY);
                i++;
            }

            if (scaleX != 1 || scaleY != 1)
            {
                plan[i] = AffinePlan.Scale(scaleX, scaleY);
                i++;
            }

            if (angleRad != 0)
            {
                plan[i] = AffinePlan.Rotate(angleRad);
                i++;
            }

            if (destX != 0 || destY != 0)
            {
                plan[i] = AffinePlan.Translate(destX, destY);
                i++;
            }

            drawImageRectPath.Clear();
            drawImageRectPath.AddMoveTo(0, 0);
            drawImageRectPath.AddLineTo(srcW, 0);
            drawImageRectPath.AddLineTo(srcW, srcH);
            drawImageRectPath.AddLineTo(0, srcH);
            drawImageRectPath.AddCloseFigure();
            return Affine.NewMatix(plan);
        }
コード例 #3
0
 public Affine CreateTranslation(double x, double y)
 {
     return(new Affine(this, AffinePlan.Translate(x, y)));
 }
コード例 #4
0
 public static Affine NewMatix(AffinePlan creationPlan)
 {
     return(new Affine(IdentityMatrix, creationPlan));
 }
コード例 #5
0
        private Affine(AffinePlan[] creationPlans)
        {
            //-----------------------
            //start with identity matrix

            sx  = 1;
            shy = 0;
            shx = 0;
            sy  = 1;
            tx  = 0;
            ty  = 0;
            //-----------------------
            int j = creationPlans.Length;

            for (int i = 0; i < j; ++i)
            {
                AffinePlan plan = creationPlans[i];
                switch (plan.cmd)
                {
                case AffineMatrixCommand.None:
                    break;

                case AffineMatrixCommand.Rotate:
                {
                    double angleRad = plan.x;
                    double ca       = Math.Cos(angleRad);
                    double sa       = Math.Sin(angleRad);
                    double t0       = sx * ca - shy * sa;
                    double t2       = shx * ca - sy * sa;
                    double t4       = tx * ca - ty * sa;
                    shy = sx * sa + shy * ca;
                    sy  = shx * sa + sy * ca;
                    ty  = tx * sa + ty * ca;
                    sx  = t0;
                    shx = t2;
                    tx  = t4;
                }
                break;

                case AffineMatrixCommand.Scale:
                {
                    double mm0 = plan.x;
                    double mm3 = plan.y;
                    sx  *= mm0;
                    shx *= mm0;
                    tx  *= mm0;
                    shy *= mm3;
                    sy  *= mm3;
                    ty  *= mm3;
                }
                break;

                case AffineMatrixCommand.Translate:
                {
                    tx += plan.x;
                    ty += plan.y;
                }
                break;

                case AffineMatrixCommand.Skew:
                {
                    double m_sx  = 1;
                    double m_sy  = 1;
                    double m_shx = Math.Tan(plan.x);
                    double m_shy = Math.Tan(plan.y);
                    double t0    = sx * m_sx + shy * m_shx;
                    double t2    = shx * m_sx + sy * m_shx;
                    double t4    = tx * m_sx + ty * m_shx + 0;     //0=m.tx
                    shy = sx * m_shy + shy * m_sy;
                    sy  = shx * m_shy + sy * m_sy;
                    ty  = tx * m_shy + ty * m_sy + 0;       //0= m.ty;
                    sx  = t0;
                    shx = t2;
                    tx  = t4;
                }
                break;

                case AffineMatrixCommand.Invert:
                {
                    double d  = CalculateDeterminantReciprocal();
                    double t0 = sy * d;
                    sy  = sx * d;
                    shy = -shy * d;
                    shx = -shx * d;
                    double t4 = -tx * t0 - ty * shx;
                    ty = -tx * shy - ty * sy;
                    sx = t0;
                    tx = t4;
                }
                break;

                default:
                {
                    throw new NotSupportedException();
                }
                }
            }
        }
コード例 #6
0
        private Affine(Affine copyFrom, AffinePlan creationPlan)
        {
            //-----------------------
            sx  = copyFrom.sx;
            shy = copyFrom.shy;
            shx = copyFrom.shx;
            sy  = copyFrom.sy;
            tx  = copyFrom.tx;
            ty  = copyFrom.ty;
            //-----------------------
            switch (creationPlan.cmd)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case AffineMatrixCommand.None:
                break;

            case AffineMatrixCommand.Rotate:
            {
                double angleRad = creationPlan.x;
                double ca       = Math.Cos(angleRad);
                double sa       = Math.Sin(angleRad);
                double t0       = sx * ca - shy * sa;
                double t2       = shx * ca - sy * sa;
                double t4       = tx * ca - ty * sa;
                shy = sx * sa + shy * ca;
                sy  = shx * sa + sy * ca;
                ty  = tx * sa + ty * ca;
                sx  = t0;
                shx = t2;
                tx  = t4;
            }
            break;

            case AffineMatrixCommand.Scale:
            {
                double mm0 = creationPlan.x;
                double mm3 = creationPlan.y;
                sx  *= mm0;
                shx *= mm0;
                tx  *= mm0;
                shy *= mm3;
                sy  *= mm3;
                ty  *= mm3;
            }
            break;

            case AffineMatrixCommand.Skew:
            {
                double m_sx  = 1;
                double m_sy  = 1;
                double m_shx = Math.Tan(creationPlan.x);
                double m_shy = Math.Tan(creationPlan.y);
                double t0    = sx * m_sx + shy * m_shx;
                double t2    = shx * m_sx + sy * m_shx;
                double t4    = tx * m_sx + ty * m_shx + 0;     //0=m.tx
                shy = sx * m_shy + shy * m_sy;
                sy  = shx * m_shy + sy * m_sy;
                ty  = tx * m_shy + ty * m_sy + 0;       //0= m.ty;
                sx  = t0;
                shx = t2;
                tx  = t4;
                //return new Affine(1.0, Math.Tan(y), Math.Tan(x), 1.0, 0.0, 0.0);
            }
            break;

            case AffineMatrixCommand.Translate:
            {
                tx += creationPlan.x;
                ty += creationPlan.y;
            }
            break;

            case AffineMatrixCommand.Invert:
            {
                double d  = CalculateDeterminantReciprocal();
                double t0 = sy * d;
                sy  = sx * d;
                shy = -shy * d;
                shx = -shx * d;
                double t4 = -tx * t0 - ty * shx;
                ty = -tx * shy - ty * sy;
                sx = t0;
                tx = t4;
            }
            break;
            }
        }
コード例 #7
0
 static Affine BuildImageBoundsPath(int srcW, int srcH,
    VertexStore drawImageRectPath, AffinePlan[] affPlans)
 {
     drawImageRectPath.Clear();
     drawImageRectPath.AddMoveTo(0, 0);
     drawImageRectPath.AddLineTo(srcW, 0);
     drawImageRectPath.AddLineTo(srcW, srcH);
     drawImageRectPath.AddLineTo(0, srcH);
     drawImageRectPath.AddCloseFigure();
     return Affine.NewMatix(affPlans);
 }
コード例 #8
0
        public void Render(IImageReaderWriter source, AffinePlan[] affinePlans)
        {
            VertexStore v1 = GetFreeVxs();
            Affine destRectTransform = BuildImageBoundsPath(source.Width, source.Height, v1, affinePlans);
            // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
            Affine sourceRectTransform = destRectTransform.CreateInvert();
            var imgSpanGen = new ImgSpanGenRGBA_BilinearClip(
                source,
                Drawing.Color.Black,
                new SpanInterpolatorLinear(sourceRectTransform));

            var v2 = destRectTransform.TransformToVxs(v1, GetFreeVxs());
            Render(v2, imgSpanGen);
            //
            ReleaseVxs(ref v1);
            ReleaseVxs(ref v2);
        }
コード例 #9
0
ファイル: 1_Affine.cs プロジェクト: prepare/HTML-Renderer
 public static Affine NewMatix(AffinePlan creationPlan)
 {
     return new Affine(IdentityMatrix, creationPlan);
 }
コード例 #10
0
ファイル: 1_Affine.cs プロジェクト: prepare/HTML-Renderer
        private Affine(AffinePlan[] creationPlans)
        {
            //-----------------------
            //start with identity matrix

            sx = 1;
            shy = 0;
            shx = 0;
            sy = 1;
            tx = 0;
            ty = 0;
            //-----------------------
            int j = creationPlans.Length;
            for (int i = 0; i < j; ++i)
            {
                AffinePlan plan = creationPlans[i];
                switch (plan.cmd)
                {
                    case AffineMatrixCommand.None:
                        break;
                    case AffineMatrixCommand.Rotate:
                        {
                            double angleRad = plan.x;
                            double ca = Math.Cos(angleRad);
                            double sa = Math.Sin(angleRad);
                            double t0 = sx * ca - shy * sa;
                            double t2 = shx * ca - sy * sa;
                            double t4 = tx * ca - ty * sa;
                            shy = sx * sa + shy * ca;
                            sy = shx * sa + sy * ca;
                            ty = tx * sa + ty * ca;
                            sx = t0;
                            shx = t2;
                            tx = t4;
                        }
                        break;
                    case AffineMatrixCommand.Scale:
                        {
                            double mm0 = plan.x;
                            double mm3 = plan.y;
                            sx *= mm0;
                            shx *= mm0;
                            tx *= mm0;
                            shy *= mm3;
                            sy *= mm3;
                            ty *= mm3;
                        }
                        break;
                    case AffineMatrixCommand.Translate:
                        {
                            tx += plan.x;
                            ty += plan.y;
                        }
                        break;
                    case AffineMatrixCommand.Skew:
                        {
                            double m_sx = 1;
                            double m_sy = 1;
                            double m_shx = Math.Tan(plan.x);
                            double m_shy = Math.Tan(plan.y);
                            double t0 = sx * m_sx + shy * m_shx;
                            double t2 = shx * m_sx + sy * m_shx;
                            double t4 = tx * m_sx + ty * m_shx + 0;//0=m.tx
                            shy = sx * m_shy + shy * m_sy;
                            sy = shx * m_shy + sy * m_sy;
                            ty = tx * m_shy + ty * m_sy + 0;//0= m.ty;
                            sx = t0;
                            shx = t2;
                            tx = t4;
                        }
                        break;
                    case AffineMatrixCommand.Invert:
                        {
                            double d = CalculateDeterminantReciprocal();
                            double t0 = sy * d;
                            sy = sx * d;
                            shy = -shy * d;
                            shx = -shx * d;
                            double t4 = -tx * t0 - ty * shx;
                            ty = -tx * shy - ty * sy;
                            sx = t0;
                            tx = t4;
                        }
                        break;
                    default:
                        {
                            throw new NotSupportedException();
                        }
                }
            }
        }
コード例 #11
0
ファイル: 1_Affine.cs プロジェクト: prepare/HTML-Renderer
        private Affine(Affine copyFrom, AffinePlan creationPlan)
        {
            //-----------------------
            sx = copyFrom.sx;
            shy = copyFrom.shy;
            shx = copyFrom.shx;
            sy = copyFrom.sy;
            tx = copyFrom.tx;
            ty = copyFrom.ty;
            //-----------------------
            switch (creationPlan.cmd)
            {
                default:
                    {
                        throw new NotSupportedException();
                    }
                case AffineMatrixCommand.None:
                    break;
                case AffineMatrixCommand.Rotate:
                    {
                        double angleRad = creationPlan.x;
                        double ca = Math.Cos(angleRad);
                        double sa = Math.Sin(angleRad);
                        double t0 = sx * ca - shy * sa;
                        double t2 = shx * ca - sy * sa;
                        double t4 = tx * ca - ty * sa;
                        shy = sx * sa + shy * ca;
                        sy = shx * sa + sy * ca;
                        ty = tx * sa + ty * ca;
                        sx = t0;
                        shx = t2;
                        tx = t4;
                    }
                    break;
                case AffineMatrixCommand.Scale:
                    {
                        double mm0 = creationPlan.x;
                        double mm3 = creationPlan.y;
                        sx *= mm0;
                        shx *= mm0;
                        tx *= mm0;
                        shy *= mm3;
                        sy *= mm3;
                        ty *= mm3;
                    }
                    break;
                case AffineMatrixCommand.Skew:
                    {
                        double m_sx = 1;
                        double m_sy = 1;
                        double m_shx = Math.Tan(creationPlan.x);
                        double m_shy = Math.Tan(creationPlan.y);
                        double t0 = sx * m_sx + shy * m_shx;
                        double t2 = shx * m_sx + sy * m_shx;
                        double t4 = tx * m_sx + ty * m_shx + 0;//0=m.tx
                        shy = sx * m_shy + shy * m_sy;
                        sy = shx * m_shy + sy * m_sy;
                        ty = tx * m_shy + ty * m_sy + 0;//0= m.ty;
                        sx = t0;
                        shx = t2;
                        tx = t4;
                        //return new Affine(1.0, Math.Tan(y), Math.Tan(x), 1.0, 0.0, 0.0);

                    }
                    break;
                case AffineMatrixCommand.Translate:
                    {
                        tx += creationPlan.x;
                        ty += creationPlan.y;
                    }
                    break;
                case AffineMatrixCommand.Invert:
                    {
                        double d = CalculateDeterminantReciprocal();
                        double t0 = sy * d;
                        sy = sx * d;
                        shy = -shy * d;
                        shx = -shx * d;
                        double t4 = -tx * t0 - ty * shx;
                        ty = -tx * shy - ty * sy;
                        sx = t0;
                        tx = t4;
                    }
                    break;
            }
        }