Exemplo n.º 1
0
        /// <summary>
        /// we do not store input linearGradient
        /// </summary>
        /// <param name="linearGradient"></param>
        static void Build(Drawing.PolygonGradientBrush linearGradient,
                          PixelFarm.CpuBlit.VertexProcessing.TessTool tess,
                          out float[] v2f,
                          out float[] colors)
        {
            //reverse user input order
            List <Drawing.PolygonGradientBrush.ColorVertex2d> vertices = linearGradient.Vertices;

            s_v2fList.Clear();
            s_colorList.Clear();

            int j = vertices.Count;

            for (int m = 0; m < j; ++m)
            {
                Drawing.PolygonGradientBrush.ColorVertex2d v = vertices[m];
                s_v2fList.Add(v.X);
                s_v2fList.Add(v.Y);
            }


            ushort[] indexList = PixelFarm.CpuBlit.VertexProcessing.TessToolExtensions.TessAsTriIndexArray(
                tess, s_v2fList.ToArray(), null,
                out float[] tessCoords,
                out int vertexCount
                );

            int n1 = 0;
            int n2 = 0;

            float[] colors2    = new float[indexList.Length * 4];
            float[] tessCoord2 = new float[indexList.Length * 2];

            for (int i = 0; i < indexList.Length; ++i)
            {
                ushort index = indexList[i];
                Drawing.PolygonGradientBrush.ColorVertex2d v = vertices[index];
                Color color = v.C;


                //a,b,g,r

                colors2[n1]     = (color.B / 255f); //r
                colors2[n1 + 1] = (color.G / 255f); //g
                colors2[n1 + 2] = (color.R / 255f); //b
                colors2[n1 + 3] = (color.A / 255f); //a

                tessCoord2[n2]     = v.X;
                tessCoord2[n2 + 1] = v.Y;

                n1 += 4;
                n2 += 2;
            }
            v2f    = tessCoord2;
            colors = colors2;
        }
Exemplo n.º 2
0
        public static PolygonGradientBrush Resolve(Drawing.PolygonGradientBrush polygonGr, PixelFarm.CpuBlit.VertexProcessing.TessTool tess)
        {
            if (!(polygonGr.InnerBrush is PolygonGradientBrush glGradient))
            {
                //create a new one
                Build(polygonGr, tess, out float[] v2f, out float[] colors);
                glGradient = new PolygonGradientBrush(v2f, colors);

                polygonGr.InnerBrush = glGradient;
            }
            return(glGradient);
        }