Beispiel #1
0
        void DrawBrushPath(Graphics g)
        {
            if (_latestBrushPathCache != null)
            {
                PixelFarm.Drawing.Color brushColor = _myBrushPath.FillColor;
                using (var br = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(brushColor.alpha, brushColor.red, brushColor.green, brushColor.blue)))
                {
                    g.FillPath(br, _latestBrushPathCache);
                }
                return;
            }

            if (_myBrushPath.Vxs != null)
            {
                //create new path
                _latestBrushPathCache = PixelFarm.Drawing.WinGdi.VxsHelper.CreateGraphicsPath(_myBrushPath.Vxs);
                PixelFarm.Drawing.Color brushColor = _myBrushPath.FillColor;
                using (var br = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(brushColor.alpha, brushColor.red, brushColor.green, brushColor.blue)))
                {
                    g.FillPath(br, _latestBrushPathCache);
                }
            }
            else
            {
                var contPoints = _myBrushPath.contPoints;
                int pcount     = contPoints.Count;
                for (int i = 1; i < pcount; ++i)
                {
                    var p0 = contPoints[i - 1];
                    var p1 = contPoints[i];
                    g.DrawLine(Pens.Red, (float)p0.x, (float)p0.y, (float)p1.x, (float)p1.y);
                }
            }
        }
        public void ChangeFontColor(Color newcolor)
        {
            //change prop
            //then need to evaluate 
            if (elem == null)
            {
                return;
            }
            BoxSpec boxSpec = elem.Spec;
            if (boxSpec.ActualColor == newcolor)
            {
                return;
            }

            HtmlElement.InvokeNotifyChangeOnIdleState(
                elem,
                ElementChangeKind.Spec);
            //-------------------------------------
            var existingRuleSet = elem.ElementRuleSet;
            if (existingRuleSet == null)
            {
                //create new one                     
                elem.ElementRuleSet = existingRuleSet = new CssRuleSet();
                elem.IsStyleEvaluated = true;
            }
            existingRuleSet.AddCssCodeProperty(
                new CssPropertyDeclaration(
                    WellknownCssPropertyName.Color,
                    new CssCodeColor(
                        CssColorConv.ConvertToCssColor(newcolor))));
            HtmlElement.InvokeNotifyChangeOnIdleState(elem, ElementChangeKind.Spec);
        }
        public void FillRoundRect(PixelFarm.Drawing.Color color, float x, float y, float w, float h, float rx, float ry)
        {
            roundRect.SetRect(x, y, x + w, y + h);
            roundRect.SetRadius(rx, ry);
            //create round rect vxs
            var vxs = roundRect.MakeVxs();

            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.FillWithColor(sclineRas, sclinePack8, color);
            }
            break;

            default:
            {
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
            }
            break;
            }
        }
        EaseBox CreateGripper(PixelFarm.Drawing.Color bgcolor, bool isVertical)
        {
            int controllerBoxWH = 10;
            var gripperBox      = new SimpleBox(controllerBoxWH, controllerBoxWH);

            gripperBox.BackColor = bgcolor;
            //---------------------------------------------------------------------

            gripperBox.MouseDrag += (s, e) =>
            {
                Point pos = gripperBox.Position;
                if (isVertical)
                {
                    gripperBox.SetLocation(pos.X, pos.Y + e.YDiff);
                }
                else
                {
                    gripperBox.SetLocation(pos.X + e.XDiff, pos.Y);
                }

                this.ninespaceGrippers.UpdateNinespaces();
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                e.CancelBubbling   = true;
            };
            gripperBox.MouseUp += (s, e) =>
            {
                e.MouseCursorStyle = MouseCursorStyle.Default;
                e.CancelBubbling   = true;
            };

            return(gripperBox);
        }
 static SimpleBox CreateSpaceBox(SpaceName name, Color bgcolor)
 {
     int controllerBoxWH = 10;
     SimpleBox spaceBox = new SimpleBox(controllerBoxWH, controllerBoxWH);
     spaceBox.BackColor = bgcolor;
     spaceBox.Tag = name;
     return spaceBox;
 }
        public void FillPolygon(PixelFarm.Drawing.Color color, float[] vertex2dCoords, int npoints)
        {
            //-------------
            //Tesselate
            //2d coods lis
            //n point
            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                //closed polygon

                //closed polygon
                int j = npoints / 2;
                //first point
                if (j < 2)
                {
                    return;
                }
                ps.MoveTo(vertex2dCoords[0], vertex2dCoords[1]);
                int nn = 2;
                for (int i = 1; i < j; ++i)
                {
                    ps.LineTo(vertex2dCoords[nn++],
                              vertex2dCoords[nn++]);
                }
                //close
                ps.CloseFigure();
                VertexStore vxs = ps.Vxs;
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.FillWithColor(sclineRas, sclinePack8, color);
            }
            break;

            default:
            {
                List <Vertex> vertextList = TessPolygon(vertex2dCoords);
                int           j           = vertextList.Count;
                //-----------------------------
                //fill polygon  with solid color
                unsafe
                {
                    float *vtx = stackalloc float[j * 2];
                    int    n   = 0;
                    for (int i = 0; i < j; ++i)
                    {
                        var v = vertextList[i];
                        vtx[n]     = (float)v.m_X;
                        vtx[n + 1] = (float)v.m_Y;
                        n         += 2;
                    }
                    UnsafeDrawV2fList(DrawMode.Triangles, vtx, j, color);
                }
            }
            break;
            }
        }
Beispiel #7
0
            static CustomWidgets.EaseBox CreateSpaceBox(SpaceName name, PixelFarm.Drawing.Color bgcolor)
            {
                int controllerBoxWH = 10;
                var tinyBox         = new CustomWidgets.SimpleBox(controllerBoxWH, controllerBoxWH);

                tinyBox.BackColor = bgcolor;
                tinyBox.Tag       = name;
                return(tinyBox);
            }
 void Blend(ActualImage destImg, byte[] greyBuff, int greyBufferWidth, int greyBufferHeight)
 {
     PixelFarm.Drawing.Color color = PixelFarm.Drawing.Color.Black;
     for (int y = 0; y < greyBufferHeight; ++y)
     {
         BlendScanline(destImg, greyBuff, color, 0, y, greyBufferWidth);
     }
     //SwapRB(destImg);
 }
Beispiel #9
0
 public void FillRect(PixelFarm.Drawing.Color color, float x, float y, float w, float h)
 {
     //fill with solid color
     unsafe
     {
         //set color
         float *rectCoords = stackalloc float[12];
         CreateRectCoords(rectCoords, x, y, w, h);
         UnsafeDrawV2fList(DrawMode.Triangles, rectCoords, 6, color);
     }
 }
Beispiel #10
0
 public static void UnsafeDirectSetData(SpriteShape lion,
     int numPaths,
     PathWriter pathStore,
     Color[] colors,
     int[] pathIndice)
 {
     lion.path = pathStore;
     lion.colors = colors;
     lion.pathIndexList = pathIndice;
     lion.numPaths = numPaths;
     lion.UpdateBoundingRect();
 }
        void BlendScanline(ActualImage destImg, byte[] expandGreyBuffer,
                           PixelFarm.Drawing.Color color, int x, int y, int width)

        {
            byte[] rgb = new byte[3] {
                color.R,
                color.G,
                color.B
            };
            //-------------------------
            //destination

            TempMemPtr memPtr = ActualImage.GetBufferPtr(destImg);
            //start pixel
            int destImgIndex = (x * 4) + (destImg.Stride * y);
            //start img src
            int  srcImgIndex = x + (width * y);
            int  colorIndex  = 0;
            int  round       = 0;
            byte color_a     = color.alpha;

            unsafe
            {
                byte *destImgBuffer = (byte *)memPtr.Ptr;
                while (width > 3)
                {
                    int a0 = expandGreyBuffer[srcImgIndex] * color_a;
                    int a1 = expandGreyBuffer[srcImgIndex + 1] * color_a;
                    int a2 = expandGreyBuffer[srcImgIndex + 2] * color_a;

                    byte ec0 = destImgBuffer[destImgIndex];     //existing color
                    byte ec1 = destImgBuffer[destImgIndex + 1]; //existing color
                    byte ec2 = destImgBuffer[destImgIndex + 2]; //existing color
                                                                //------------------------------------------------------
                                                                //please note that we swap a2 and a0 on the fly****
                                                                //------------------------------------------------------
                    byte n0 = (byte)((((rgb[colorIndex] - ec0) * a2) + (ec0 << 16)) >> 16);
                    byte n1 = (byte)((((rgb[colorIndex + 1] - ec1) * a1) + (ec1 << 16)) >> 16);
                    byte n2 = (byte)((((rgb[colorIndex + 2] - ec2) * a0) + (ec2 << 16)) >> 16);

                    destImgBuffer[destImgIndex]     = n0;
                    destImgBuffer[destImgIndex + 1] = n1;
                    destImgBuffer[destImgIndex + 2] = n2;

                    destImgIndex += 4;
                    round         = 0;
                    colorIndex    = 0;
                    srcImgIndex  += 3;
                    width        -= 3;
                }
                memPtr.Release();
            }
        }
Beispiel #12
0
        public void Clear(PixelFarm.Drawing.Color c)
        {
            //set value for clear color buffer

            GL.ClearColor(
                (float)c.R / 255f,
                (float)c.G / 255f,
                (float)c.B / 255f,
                (float)c.A / 255f);
            GL.ClearStencil(0);
            //actual clear here
            GL.Clear(ClearBufferMask.ColorBufferBit |
                     ClearBufferMask.DepthBufferBit |
                     ClearBufferMask.StencilBufferBit);
        }
Beispiel #13
0
 public static TextSpanStyle CreateNewStyle(Color color)
 {
     if (color != Color.Empty)
     {
         TextSpanStyle simpleBeh = new TextSpanStyle();
         // simpleBeh.SharedBgColorBrush = new ArtSolidBrush(color);
         return simpleBeh;
     }
     else
     {
         TextSpanStyle simpleBeh = new TextSpanStyle();
         //simpleBeh.SharedBgColorBrush = new ArtSolidBrush(color);
         return simpleBeh;
     }
 }
 public static void WriteColorsToStream(BinaryWriter writer, Color[] colors)
 {
     int len = colors.Length;
     //1.
     writer.Write(len);
     for (int i = 0; i < len; ++i)
     {
         Color color = colors[i];
         writer.Write(color.red);
         writer.Write(color.green);
         writer.Write(color.blue);
         writer.Write(color.alpha);
     }
     writer.Write((int)0);
     writer.Flush();
 }
 public void SetPixelHighRes(ImageReaderWriterBase sourceImage,
     Color[] destBuffer,
     int destBufferOffset,
     int x,
     int y)
 {
     int r, g, b, a;
     r = g = b = a = LineAA.SUBPIXEL_SCALE * LineAA.SUBPIXEL_SCALE / 2;
     int weight;
     int x_lr = x >> LineAA.SUBPIXEL_SHIFT;
     int y_lr = y >> LineAA.SUBPIXEL_SHIFT;
     x &= LineAA.SUBPIXEL_MARK;
     y &= LineAA.SUBPIXEL_MARK;
     int sourceOffset;
     byte[] ptr = sourceImage.GetBuffer();
     sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr);
     weight = (LineAA.SUBPIXEL_SCALE - x) *
              (LineAA.SUBPIXEL_SCALE - y);
     r += weight * ptr[sourceOffset + CO.R];
     g += weight * ptr[sourceOffset + CO.G];
     b += weight * ptr[sourceOffset + CO.B];
     a += weight * ptr[sourceOffset + CO.A];
     sourceOffset += sourceImage.BytesBetweenPixelsInclusive;
     weight = x * (LineAA.SUBPIXEL_SCALE - y);
     r += weight * ptr[sourceOffset + CO.R];
     g += weight * ptr[sourceOffset + CO.G];
     b += weight * ptr[sourceOffset + CO.B];
     a += weight * ptr[sourceOffset + CO.A];
     sourceOffset = sourceImage.GetBufferOffsetXY(x_lr, y_lr + 1);
     weight = (LineAA.SUBPIXEL_SCALE - x) * y;
     r += weight * ptr[sourceOffset + CO.R];
     g += weight * ptr[sourceOffset + CO.G];
     b += weight * ptr[sourceOffset + CO.B];
     a += weight * ptr[sourceOffset + CO.A];
     sourceOffset += sourceImage.BytesBetweenPixelsInclusive;
     weight = x * y;
     r += weight * ptr[sourceOffset + CO.R];
     g += weight * ptr[sourceOffset + CO.G];
     b += weight * ptr[sourceOffset + CO.B];
     a += weight * ptr[sourceOffset + CO.A];
     destBuffer[destBufferOffset].red = (byte)(r >> LineAA.SUBPIXEL_SHIFT * 2);
     destBuffer[destBufferOffset].green = (byte)(g >> LineAA.SUBPIXEL_SHIFT * 2);
     destBuffer[destBufferOffset].blue = (byte)(b >> LineAA.SUBPIXEL_SHIFT * 2);
     destBuffer[destBufferOffset].alpha = (byte)(a >> LineAA.SUBPIXEL_SHIFT * 2);
 }
        public void ChangeBackgroundColor(Color backgroundColor)
        {
            if (elem == null)
            {
                return;
            }
            BoxSpec boxSpec = elem.Spec;
            if (boxSpec.BackgroundColor == backgroundColor)
            {
                return;
            }


            var existingRuleSet = elem.ElementRuleSet;
            if (existingRuleSet == null)
            {
                //create new one                     
                elem.ElementRuleSet = existingRuleSet = new CssRuleSet();
                elem.IsStyleEvaluated = false;
            }

            //-------------------------------------
            existingRuleSet.RemoveCssProperty(WellknownCssPropertyName.BackgroundColor);
            existingRuleSet.AddCssCodeProperty(
               new CssPropertyDeclaration(
                   WellknownCssPropertyName.BackgroundColor,
                   new CssCodeColor(CssColorConv.ConvertToCssColor(backgroundColor))));
            elem.SkipPrincipalBoxEvalulation = false;
            CssBox cssbox = HtmlElement.InternalGetPrincipalBox(elem);
            if (cssbox != null)
            {
#if DEBUG
                cssbox.dbugMark1++;
#endif

                CssBox.InvalidateComputeValue(cssbox);
            }

            HtmlElement.InvokeNotifyChangeOnIdleState(
               elem,
               ElementChangeKind.Spec);
            InvalidateCssBox(cssbox);
        }
Beispiel #17
0
        public void FillVxsSnap(PixelFarm.Drawing.Color color, VertexStoreSnap snap)
        {
            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                sclineRas.Reset();
                sclineRas.AddPath(snap);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
            } break;

            default:
            {
                sclineRas.Reset();
                sclineRas.AddPath(snap);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
            } break;
            }
        }
Beispiel #18
0
        //--------------------------------------------------------------------
        public void GenerateColors(Color[] outputColors, int startIndex, int x, int y, int len)
        {
            m_interpolator.Begin(x + 0.5, y + 0.5, len);
            do
            {
                m_interpolator.GetCoord(out x, out y);
                float d = m_grValueCalculator.Calculate(x >> DOWN_SCALE_SHIFT,
                                                      y >> DOWN_SCALE_SHIFT,
                                                      m_d2);
                d = ((d - m_d1) * stepRatio);
                if (d < 0) d = 0;
                if (d >= m_colorsProvider.GradientSteps)
                {
                    d = m_colorsProvider.GradientSteps - 1;
                }

                outputColors[startIndex++] = m_colorsProvider.GetColor((int)d);
                m_interpolator.Next();
            }
            while (--len != 0);
        }
Beispiel #19
0
 public override void ReEvaluateComputeValue(ref ReEvaluateArgs args)
 {
     var myspec = this.imageSpec;
     this.fillColor = myspec.ActualColor;
     this.strokeColor = myspec.StrokeColor;
     this.ActualX = ConvertToPx(myspec.X, ref args);
     this.ActualY = ConvertToPx(myspec.Y, ref args);
     this.ActualWidth = ConvertToPx(myspec.Width, ref args);
     this.ActualHeight = ConvertToPx(myspec.Height, ref args);
     this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args);
     this._path = CreateRectGraphicPath( 
             this.ActualX,
             this.ActualY,
             this.ActualWidth,
             this.ActualHeight);
     if (this._imgRun.ImageBinder == null)
     {
         this._imgRun.ImageBinder = new SvgImageBinder(myspec.ImageSrc);
     }
     ValidatePath();
 }
Beispiel #20
0
        //-------------------------------------------------------------------------------


        public void FillVxs(PixelFarm.Drawing.Color color, VertexStore vxs)
        {
            //solid brush
            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
            } break;

            default:
            {
                //tess the vxs first
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
                //throw new NotSupportedException();
            } break;
            }
        }
 protected virtual void CustomRenderSingleScanLine(
     IImageReaderWriter dest,
     Scanline scline,
     Color color)
 {
     //implement
 }
Beispiel #22
0
 public void FillPolygon(PixelFarm.Drawing.Color color, float[] vertex2dCoords)
 {
     FillPolygon(color, vertex2dCoords, vertex2dCoords.Length);
 }
Beispiel #23
0
        public void FillEllipse(PixelFarm.Drawing.Color color, float x, float y, float rx, float ry)
        {
            ellipse.Reset(x, y, rx, ry);
            var vxs = ellipse.MakeVxs();

            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                sclineRasToGL.DrawWithColor(sclineRas, sclinePack8, color);
            } break;

            default:
            {           //other mode
                int n = vxs.Count;
                //make triangular fan***
                unsafe
                {
                    float *coords = stackalloc float[(n * 2) + 4];

                    int    i = 0;
                    int    nn = 0;
                    int    npoints = 0;
                    double vx, vy;
                    //center
                    coords[nn++] = (float)x;
                    coords[nn++] = (float)y;
                    npoints++;
                    var cmd = vxs.GetVertex(i, out vx, out vy);

                    while (i < n)
                    {
                        switch (cmd)
                        {
                        case VertexCmd.MoveTo:
                        {
                            coords[nn++] = (float)vx;
                            coords[nn++] = (float)vy;
                            npoints++;
                        } break;

                        case VertexCmd.LineTo:
                        {
                            coords[nn++] = (float)vx;
                            coords[nn++] = (float)vy;
                            npoints++;
                        } break;

                        case VertexCmd.Stop:
                        {
                        } break;

                        default:
                        {
                        } break;
                        }
                        i++;
                        cmd = vxs.GetVertex(i, out vx, out vy);
                    }
                    //close circle
                    coords[nn++] = coords[2];
                    coords[nn++] = coords[3];
                    npoints++;


                    UnsafeDrawV2fList(DrawMode.TriangleFan, coords, npoints, color);
                }
            } break;
            }
        }
Beispiel #24
0
 public override void BlendSolidVSpan(int x, int y, int len, Color c, byte[] covers, int coversIndex)
 {
     linkedImage.BlendSolidHSpan(y, x, len, c, covers, coversIndex);
 }
Beispiel #25
0
 public override void BlendColorVSpan(int x, int y, int len, Color[] colors, int colorsIndex, byte[] covers, int coversIndex, bool firstCoverForAll)
 {
     linkedImage.BlendColorHSpan(y, x, len, colors, colorsIndex, covers, coversIndex, firstCoverForAll);
 }
Beispiel #26
0
 public abstract void Line(double x1, double y1, double x2, double y2, Color color);
Beispiel #27
0
 public override void BlendHL(int x1, int y, int x2, Color c, byte cover)
 {
     linkedImage.BlendVL(y, x1, x2, c, cover);
 }
Beispiel #28
0
 public LinearGradientColorsProvider(Color c1, Color c2)
     : this(c1, c2, 256)
 {
 }
Beispiel #29
0
 public LinearGradientColorsProvider(Color c1, Color c2, int gradientSteps)
 {
     m_c1 = c1;
     m_c2 = c2;
     this.gradientSteps = gradientSteps;
 }
Beispiel #30
0
        public void DrawGlyphImages3(PixelFarm.Drawing.Color color,
                                     GLBitmap bmp, PixelFarm.Drawing.RectangleF[] destAndSrcPairs)
        {
            //GL.Disable(EnableCap.Blend);
            //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            ////GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.Zero);
            unsafe
            {
                var prevColor = this.strokeColor;
                this.StrokeColor = PixelFarm.Drawing.Color.White;
                GL.Enable(EnableCap.Texture2D);
                {
                    GL.BindTexture(TextureTarget.Texture2D, GetTextureId(bmp));
                    // GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Combine);
                    GL.EnableClientState(ArrayCap.TextureCoordArray); //***
                    //texture source coord 1= 100% of original width
                    float *arr      = stackalloc float[8];
                    float  fullsrcW = bmp.Width;
                    float  fullsrcH = bmp.Height;
                    int    len      = destAndSrcPairs.Length;
                    if (len > 1)
                    {
                        if ((len % 2 != 0))
                        {
                            len -= 1;
                        }
                        if (this.canvasOrientation == Drawing.CanvasOrientation.LeftTop)
                        {
                            for (int i = 0; i < len;)
                            {
                                //each

                                var destRect = destAndSrcPairs[i];
                                var srcRect  = destAndSrcPairs[i + 1];
                                i += 2;
                                if (!bmp.IsInvert)
                                {
                                    ////arr[0] = 0; arr[1] = 0;
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[2] = 1; arr[3] = 0;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[4] = 1; arr[5] = 1;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Top / fullsrcH;
                                    //arr[6] = 0; arr[7] = 1;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Top / fullsrcH;
                                }
                                else
                                {
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = srcRect.Top / fullsrcH;
                                    //arr[2] = 1; arr[3] = 1;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = srcRect.Top / fullsrcH;
                                    //arr[4] = 1; arr[5] = 0;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Bottom / fullsrcH;
                                    //arr[6] = 0; arr[7] = 0;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Bottom / fullsrcH;
                                }
                                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, (IntPtr)arr);
                                //------------------------------------------
                                //fill rect with texture
                                FillRectWithTexture(destRect.X, destRect.Y, destRect.Width, destRect.Height);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < len;)
                            {
                                //each

                                var destRect = destAndSrcPairs[i];
                                var srcRect  = destAndSrcPairs[i + 1];
                                i += 2;
                                if (bmp.IsInvert)
                                {
                                    ////arr[0] = 0; arr[1] = 0;
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[2] = 1; arr[3] = 0;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[4] = 1; arr[5] = 1;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Top / fullsrcH;
                                    //arr[6] = 0; arr[7] = 1;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Top / fullsrcH;
                                }
                                else
                                {
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = srcRect.Top / fullsrcH;
                                    //arr[2] = 1; arr[3] = 1;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = srcRect.Top / fullsrcH;
                                    //arr[4] = 1; arr[5] = 0;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Bottom / fullsrcH;
                                    //arr[6] = 0; arr[7] = 0;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Bottom / fullsrcH;
                                }
                                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, (IntPtr)arr);
                                //------------------------------------------
                                //fill rect with texture
                                FillRectWithTexture(destRect.X, destRect.Y, destRect.Width, destRect.Height);
                            }
                        }
                    }
                    GL.DisableClientState(ArrayCap.TextureCoordArray);
                }
                GL.Disable(EnableCap.Texture2D);
                this.StrokeColor = prevColor;
            }
            ////enable color again
            //////at this point alpha component is fill in to destination
            //////-------------------------------------------------------------------------------------
            //////2. then fill again!,
            //////we use alpha information from dest,
            //////so we set blend func to ... GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha)
            //GL.ColorMask(true, true, true, true);
            //GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
            //{
            //    int len = destAndSrcPairs.Length;
            //    if (len > 1)
            //    {
            //        for (int i = 0; i < len; )
            //        {
            //            //each
            //            var destRect = destAndSrcPairs[i];
            //            var srcRect = destAndSrcPairs[i + 1];
            //            i += 2;
            //            FillRect(color, destRect.X, destRect.Y, destRect.Width, destRect.Height);
            //        }
            //    }
            //}
            ////3.
            ////set blend mode back
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            ////fill with color
        }
Beispiel #31
0
        public void DrawGlyphImages(PixelFarm.Drawing.Color color,
                                    GLBitmap bmp, PixelFarm.Drawing.RectangleF[] destAndSrcPairs)
        {
            //TODO: white opaque bg should render in single pass

            //----------------------------
            //in this version: this technique *** use gray scale gradient , not subpixel rendering
            //TODO: add subpixel rendering support**
            //see also: FillPolygon ***


            //double pass technique:

            //--------
            GL.ColorMask(false, false, false, true);
            //use alpha channel from source***
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.Zero);
            unsafe
            {
                var prevColor = this.strokeColor;
                this.StrokeColor = PixelFarm.Drawing.Color.White;
                GL.Enable(EnableCap.Texture2D);
                {
                    GL.BindTexture(TextureTarget.Texture2D, GetTextureId(bmp));
                    GL.EnableClientState(ArrayCap.TextureCoordArray); //***
                    //texture source coord 1= 100% of original width
                    float *arr      = stackalloc float[8];
                    float  fullsrcW = bmp.Width;
                    float  fullsrcH = bmp.Height;
                    int    len      = destAndSrcPairs.Length;
                    if (len > 1)
                    {
                        if ((len % 2 != 0))
                        {
                            len -= 1;
                        }
                        if (this.canvasOrientation == Drawing.CanvasOrientation.LeftTop)
                        {
                            for (int i = 0; i < len;)
                            {
                                //each

                                var destRect = destAndSrcPairs[i];
                                var srcRect  = destAndSrcPairs[i + 1];
                                i += 2;
                                if (!bmp.IsInvert)
                                {
                                    ////arr[0] = 0; arr[1] = 0;
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[2] = 1; arr[3] = 0;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[4] = 1; arr[5] = 1;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Top / fullsrcH;
                                    //arr[6] = 0; arr[7] = 1;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Top / fullsrcH;
                                }
                                else
                                {
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = srcRect.Top / fullsrcH;
                                    //arr[2] = 1; arr[3] = 1;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = srcRect.Top / fullsrcH;
                                    //arr[4] = 1; arr[5] = 0;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Bottom / fullsrcH;
                                    //arr[6] = 0; arr[7] = 0;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Bottom / fullsrcH;
                                }
                                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, (IntPtr)arr);
                                //------------------------------------------
                                //fill rect with texture
                                FillRectWithTexture(destRect.X, destRect.Y, destRect.Width, destRect.Height);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < len;)
                            {
                                //each

                                var destRect = destAndSrcPairs[i];
                                var srcRect  = destAndSrcPairs[i + 1];
                                i += 2;
                                if (bmp.IsInvert)
                                {
                                    ////arr[0] = 0; arr[1] = 0;
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[2] = 1; arr[3] = 0;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = (srcRect.Top + srcRect.Height) / fullsrcH;
                                    //arr[4] = 1; arr[5] = 1;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Top / fullsrcH;
                                    //arr[6] = 0; arr[7] = 1;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Top / fullsrcH;
                                }
                                else
                                {
                                    arr[0] = srcRect.Left / fullsrcW; arr[1] = srcRect.Top / fullsrcH;
                                    //arr[2] = 1; arr[3] = 1;
                                    arr[2] = srcRect.Right / fullsrcW; arr[3] = srcRect.Top / fullsrcH;
                                    //arr[4] = 1; arr[5] = 0;
                                    arr[4] = srcRect.Right / fullsrcW; arr[5] = srcRect.Bottom / fullsrcH;
                                    //arr[6] = 0; arr[7] = 0;
                                    arr[6] = srcRect.Left / fullsrcW; arr[7] = srcRect.Bottom / fullsrcH;
                                }
                                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, (IntPtr)arr);
                                //------------------------------------------
                                //fill rect with texture
                                FillRectWithTexture(destRect.X, destRect.Y, destRect.Width, destRect.Height);
                            }
                        }
                    }
                    GL.DisableClientState(ArrayCap.TextureCoordArray);
                }
                GL.Disable(EnableCap.Texture2D);
                this.StrokeColor = prevColor;
            }
            //enable color again
            ////at this point alpha component is fill in to destination
            ////-------------------------------------------------------------------------------------
            ////2. then fill again!,
            ////we use alpha information from dest,
            ////so we set blend func to ... GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha)
            GL.ColorMask(true, true, true, true);
            GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
            {
                int len = destAndSrcPairs.Length;
                if (len > 1)
                {
                    for (int i = 0; i < len;)
                    {
                        //each
                        var destRect = destAndSrcPairs[i];
                        var srcRect  = destAndSrcPairs[i + 1];
                        i += 2;
                        FillRect(color, destRect.X, destRect.Y, destRect.Width, destRect.Height);
                    }
                }
            }

            //3.
            //set blend mode back
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //fill with color
        }
Beispiel #32
0
 static unsafe void UnsafeDrawV2fList(DrawMode mode, float *polygon2dVertices, int vertexCount, PixelFarm.Drawing.Color c)
 {
     GL.Color4(c.R, c.G, c.B, c.A);
     //1. enable client side memory
     GL.EnableClientState(ArrayCap.VertexArray); //***
     //2. load data from point to vertex array part
     GL.VertexPointer(2, VertexPointerType.Float, 0, (IntPtr)polygon2dVertices);
     //3. draw array
     GL.DrawArrays((BeginMode)mode, 0, vertexCount);
     //4. disable client side memory
     GL.DisableClientState(ArrayCap.VertexArray);
 }
Beispiel #33
0
 public void SetColorValue(PixelFarm.Drawing.Color color)
 {
     _evaluatedAs = CssValueEvaluatedAs.Color;
     _cachedColor = color;
 }
Beispiel #34
0
 /// <summary>
 /// Check if the given color is visible if painted (has alpha and color values)
 /// </summary>
 /// <param name="color">the color to check</param>
 /// <returns>true - visible, false - not visible</returns>
 public static bool IsColorVisible(Color color)
 {
     return color.A > 0;
 }
        void SubPixRender(IImageReaderWriter dest, Scanline scanline, Color color)
        {
            byte[] covers = scanline.GetCovers();
            int num_spans = scanline.SpanCount;
            int y = scanline.Y;
            byte[] buffer = dest.GetBuffer();
            IPixelBlender blender = dest.GetRecieveBlender();
            int last_x = int.MinValue;
            int bufferOffset = 0;
            //------------------------------------------
            Color bgColor = Color.White;
            float cb_R = bgColor.R / 255f;
            float cb_G = bgColor.G / 255f;
            float cb_B = bgColor.B / 255f;
            float cf_R = color.R / 255f;
            float cf_G = color.G / 255f;
            float cf_B = color.B / 255f;
            //------------------------------------------
            int prevCover = -1;
            for (int i = 1; i <= num_spans; ++i)
            {
                //render span by span  
                ScanlineSpan span = scanline.GetSpan(i);
                if (span.x != last_x + 1)
                {
                    bufferOffset = dest.GetBufferOffsetXY(span.x, y);
                }

                last_x = span.x;
                int num_pix = span.len;
                if (num_pix < 0)
                {
                    //special encode***
                    num_pix = -num_pix; //make it positive value
                    last_x += (num_pix - 1);
                    //long span with coverage
                    int coverageValue = covers[span.cover_index];
                    //------------------------------------------- 
                    if (coverageValue >= 255)
                    {
                        //100% cover
                        int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                        Color todrawColor = Color.FromArgb(a, Color.FromArgb(color.R, color.G, color.B));
                        while (num_pix > 0)
                        {
                            blender.BlendPixel(buffer, bufferOffset, todrawColor);
                            bufferOffset += 4; //1 pixel 4 bytes
                            --num_pix;
                        }
                    }
                    else
                    {
                        int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                        Color newc = Color.FromArgb(color.R, color.G, color.B);
                        Color todrawColor = Color.FromArgb(a, newc);
                        while (num_pix > 0)
                        {
                            blender.BlendPixel(buffer, bufferOffset, todrawColor);
                            bufferOffset += 4; //1 pixel 4 bytes
                            --num_pix;
                        }
                    }
                    prevCover = coverageValue;
                }
                else
                {
                    int coverIndex = span.cover_index;
                    last_x += (num_pix - 1);
                    while (num_pix > 0)
                    {
                        int coverageValue = covers[coverIndex++];
                        if (coverageValue >= 255)
                        {
                            //100% cover
                            Color newc = Color.FromArgb(color.R, color.G, color.B);
                            int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                            blender.BlendPixel(buffer, bufferOffset, Color.FromArgb(a, newc));
                            prevCover = coverageValue;
                        }
                        else
                        {
                            //check direction : 

                            bool isUpHill = coverageValue >= prevCover;
                            //if (isUpHill != ((coverageValue % 2) > 0))
                            //{
                            //}
                            //---------------------------- 
                            byte c_r = 0, c_g = 0, c_b = 0;
                            //----------------------------
                            //assume lcd screen is RGB
                            float subpix_percent = ((float)(coverageValue) / 256f);
                            if (coverageValue < cover_1_3)
                            {
                                //assume LCD color arrangement is BGR                            
                                if (isUpHill)
                                {
                                    c_r = bgColor.R;
                                    c_g = bgColor.G;
                                    c_b = (byte)(mix(cb_B, cf_B, subpix_percent) * 255);
                                }
                                else
                                {
                                    c_r = (byte)(mix(cb_R, cf_R, subpix_percent) * 255);
                                    c_g = bgColor.G;
                                    c_b = bgColor.B;
                                }

                                int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)));
                            }
                            else if (coverageValue < cover_2_3)
                            {
                                if (isUpHill)
                                {
                                    c_r = bgColor.R;
                                    c_g = (byte)(mix(cb_G, cf_G, subpix_percent) * 255);
                                    c_b = (byte)(mix(cb_B, cf_B, 1) * 255);
                                }
                                else
                                {
                                    c_r = (byte)(mix(cb_R, cf_R, 1) * 255);
                                    c_g = (byte)(mix(cb_G, cf_G, subpix_percent) * 255);
                                    c_b = bgColor.B;
                                }

                                int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)));
                            }
                            else
                            {
                                //cover > 2/3 but not full 
                                if (isUpHill)
                                {
                                    c_r = (byte)(mix(cb_R, cf_R, subpix_percent) * 255);
                                    c_g = (byte)(mix(cb_G, cf_G, 1) * 255);
                                    c_b = (byte)(mix(cb_B, cf_B, 1) * 255);
                                }
                                else
                                {
                                    c_r = (byte)(mix(cb_R, cf_R, 1) * 255);
                                    c_g = (byte)(mix(cb_G, cf_G, 1) * 255);
                                    c_b = (byte)(mix(cb_B, cf_B, subpix_percent) * 255);
                                }

                                int a = ((coverageValue + 1) * color.Alpha0To255) >> 8;
                                blender.BlendPixel(buffer, bufferOffset, Color.FromArgb(a, Color.FromArgb(c_r, c_g, c_b)));
                            }
                        }
                        bufferOffset += 4; //1 pixel 4 bits 
                        --num_pix;
                        prevCover = coverageValue;
                    }
                }
            }
        }
Beispiel #36
0
 public void SetColors(Color c1, Color c2)
 {
     SetColors(c1, c2, 256);
 }
Beispiel #37
0
 public abstract void Rectangle(double left, double bottom, double right, double top, Color color);
Beispiel #38
0
 public abstract void PaintSeries(VertexStore vxs, Color[] colors, int[] pathIndexs, int numPath);
Beispiel #39
0
 public override void CopyVL(int x, int y,
                            int len,
                            Color c)
 {
     linkedImage.CopyHL(y, x, len, c);
 }
        public static void GetInterpolatedColor(Color[] colors, double x, double y,
                                                out PixelFarm.Drawing.Color outputColor)
        {
            //interpolate by channel
            double v1, v2, v3, v4, v;
            byte   a;
            {
                //row
                v1 = getValue2(colors[0].A, colors[1].A, colors[2].A, colors[3].A, x);
                v2 = getValue2(colors[4].A, colors[5].A, colors[6].A, colors[7].A, x);
                v3 = getValue2(colors[8].A, colors[9].A, colors[10].A, colors[11].A, x);
                v4 = getValue2(colors[12].A, colors[13].A, colors[14].A, colors[15].A, x);
                //columns
                v = getValue2(v1, v2, v3, v4, y);
                //clamp
                if (v > 255)
                {
                    a = 255;
                }
                else if (v < 0)
                {
                    a = 0;
                }
                else
                {
                    a = (byte)v;
                }
            }
            //---------------------------------------------------
            byte r;
            {
                //row
                v1 = getValue2(colors[0].R, colors[1].R, colors[2].R, colors[3].R, x);
                v2 = getValue2(colors[4].R, colors[5].R, colors[6].R, colors[7].R, x);
                v3 = getValue2(colors[8].R, colors[9].R, colors[10].R, colors[11].R, x);
                v4 = getValue2(colors[12].R, colors[13].R, colors[14].R, colors[15].R, x);
                //columns
                v = getValue2(v1, v2, v3, v4, y);
                //clamp
                if (v > 255)
                {
                    r = 255;
                }
                else if (v < 0)
                {
                    r = 0;
                }
                else
                {
                    r = (byte)v;
                }
            }
            //---------------------------------------------------
            byte g;
            {
                //row
                v1 = getValue2(colors[0].G, colors[1].G, colors[2].G, colors[3].G, x);
                v2 = getValue2(colors[4].G, colors[5].G, colors[6].G, colors[7].G, x);
                v3 = getValue2(colors[8].G, colors[9].G, colors[10].G, colors[11].G, x);
                v4 = getValue2(colors[12].G, colors[13].G, colors[14].G, colors[15].G, x);
                //columns
                v = getValue2(v1, v2, v3, v4, y);
                //clamp
                if (v > 255)
                {
                    g = 255;
                }
                else if (v < 0)
                {
                    g = 0;
                }
                else
                {
                    g = (byte)v;
                }
            }
            //---------------------------------------------------
            byte b;

            {
                //b

                v1 = getValue2(colors[0].B, colors[1].B, colors[2].B, colors[3].B, x);
                v2 = getValue2(colors[4].B, colors[5].B, colors[6].B, colors[7].B, x);
                v3 = getValue2(colors[8].B, colors[9].B, colors[10].B, colors[11].B, x);
                v4 = getValue2(colors[12].B, colors[13].B, colors[14].B, colors[15].B, x);
                //columns
                v = getValue2(v1, v2, v3, v4, y);
                //clamp
                if (v > 255)
                {
                    b = 255;
                }
                else if (v < 0)
                {
                    b = 0;
                }
                else
                {
                    b = (byte)v;
                }
            }

            outputColor = new Color(a, r, g, b);
        }
Beispiel #41
0
 public override void BlendVL(int x, int y1, int y2, Color c, byte cover)
 {
     linkedImage.BlendHL(y1, x, y2, c, cover);
 }
        void BlendWithLcdTechnique(ActualImage destImg, ActualImage glyphImg, PixelFarm.Drawing.Color color)
        {
            //var g8Lut = g8_4_2_1;
            //var forwardBuffer = new ScanlineSubPixelRasterizer.TempForwardAccumBuffer();
            //int glyphH = glyphImg.Height;
            //int glyphW = glyphImg.Width;
            //byte[] glyphBuffer = ActualImage.GetBuffer(glyphImg);
            //int srcIndex = 0;
            //int srcStride = glyphImg.Stride;
            //byte[] destImgBuffer = ActualImage.GetBuffer(destImg);
            ////start pixel
            //int destImgIndex = 0;
            //int destX = 0;
            //byte[] rgb = new byte[]{
            //    color.R,
            //    color.G,
            //    color.B
            //};

            //byte color_a = color.alpha;

            //for (int y = 0; y < glyphH; ++y)
            //{
            //    srcIndex = srcStride * y;
            //    destImgIndex = (destImg.Stride * y) + (destX * 4); //4 color component
            //    int i = 0;
            //    int round = 0;
            //    forwardBuffer.Reset();
            //    byte e0 = 0;
            //    int prev_a = 0;

            //    for (int x = 0; x < glyphW; ++x)
            //    {
            //        //1.
            //        //read 1 pixel (4 bytes, 4 color components)
            //        byte r = glyphBuffer[srcIndex];
            //        byte g = glyphBuffer[srcIndex + 1];
            //        byte b = glyphBuffer[srcIndex + 2];
            //        byte a = glyphBuffer[srcIndex + 3];


            //        //2.
            //        //convert to grey scale and convert to 65 level grey scale value
            //        byte greyScaleValue = g8Lut.Convert255ToLevel(a);

            //        for (int n = 0; n < 3; ++n)
            //        {

            //            forwardBuffer.WriteAccumAndReadBack(
            //             g8Lut.TertiaryFromLevel(greyScaleValue),
            //             g8Lut.SecondaryFromLevel(greyScaleValue),
            //             g8Lut.PrimaryFromLevel(greyScaleValue), out e0);

            //            //5. blend this pixel to dest image (expand to 5 (sub)pixel)
            //            BlendPixel(e0 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //        }
            //        //------------------------------------------------------------
            //        prev_a = a;
            //        srcIndex += 4;
            //    }
            //    //---------
            //    //when finish each line
            //    //we must draw extened 4 pixels
            //    //---------

            //    {


            //        byte e1, e2, e3, e4;
            //        forwardBuffer.ReadRemaining4(out e1, out e2, out e3, out e4);
            //        int remainingEnergy = Math.Min(srcStride, 4);
            //        switch (remainingEnergy)
            //        {
            //            default: throw new NotSupportedException();
            //            case 4:
            //                BlendPixel(e1 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e2 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e3 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e4 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                break;
            //            case 3:
            //                BlendPixel(e1 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e2 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e3 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                break;
            //            case 2:
            //                BlendPixel(e1 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                BlendPixel(e2 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                break;
            //            case 1:
            //                BlendPixel(e1 * color_a, rgb, ref i, destImgBuffer, ref destImgIndex, ref round);
            //                break;
            //            case 0:
            //                //nothing
            //                break;
            //        }
            //    }
            //}
        }
Beispiel #43
0
 public override void CopyColorVSpan(int x, int y, int len, Color[] colors, int colorsIndex)
 {
     linkedImage.CopyColorHSpan(y, x, len, colors, colorsIndex);
 }
Beispiel #44
0
 //-------------------------------------------------------
 public abstract void Clear(Color color);                
 public static void ReadColorDataFromStream(BinaryReader reader, out Color[] colors)
 {
     int len = reader.ReadInt32();
     colors = new Color[len];
     for (int i = 0; i < len; ++i)
     {
         byte r = reader.ReadByte();
         byte g = reader.ReadByte();
         byte b = reader.ReadByte();
         byte a = reader.ReadByte();
         colors[i] = new Color(a, r, g, b);
     }
     int end = reader.ReadInt32();
 }
Beispiel #46
0
 public void FillCircle(PixelFarm.Drawing.Color color, float x, float y, float radius)
 {
     FillEllipse(color, x, y, radius, radius);
 }
Beispiel #47
0
 public abstract void FillCircle(double x, double y, double radius, Color color);
Beispiel #48
0
 public abstract void FillRectangle(double left, double bottom, double right, double top, Color fillColor);
Beispiel #49
0
 public void SetColors(Color c1, Color c2, int gradientSteps)
 {
     m_c1 = c1;
     m_c2 = c2;
     this.gradientSteps = gradientSteps;
 }
        public void RenderWithColor(IImageReaderWriter dest,
                ScanlineRasterizer sclineRas,
                Scanline scline,
                Color color)
        {
            if (!sclineRas.RewindScanlines()) { return; } //early exit
            //----------------------------------------------- 
            scline.ResetSpans(sclineRas.MinX, sclineRas.MaxX);
            switch (this.ScanlineRenderMode)
            {
                default:
                    {
                        //prev mode  
                        //this mode 
                        while (sclineRas.SweepScanline(scline))
                        {
                            //render solid single scanline
                            int y = scline.Y;
                            int num_spans = scline.SpanCount;
                            byte[] covers = scline.GetCovers();
                            //render each span in the scanline
                            for (int i = 1; i <= num_spans; ++i)
                            {
                                ScanlineSpan span = scline.GetSpan(i);
                                if (span.len > 0)
                                {
                                    //positive len 
                                    dest.BlendSolidHSpan(span.x, y, span.len, color, covers, span.cover_index);
                                }
                                else
                                {
                                    //fill the line, same coverage area
                                    int x = span.x;
                                    int x2 = (x - span.len - 1);
                                    dest.BlendHL(x, y, x2, color, covers[span.cover_index]);
                                }
                            }
                        }
                    }
                    break;
                case Agg.ScanlineRenderMode.SubPixelRendering:
                    {
#if DEBUG
                        int dbugMinScanlineCount = 0;
#endif

                        while (sclineRas.SweepScanline(scline))
                        {
                            SubPixRender(dest, scline, color);
#if DEBUG
                            dbugMinScanlineCount++;
#endif
                        }
                    }
                    break;
                case Agg.ScanlineRenderMode.Custom:
                    {
                        while (sclineRas.SweepScanline(scline))
                        {
                            CustomRenderSingleScanLine(dest, scline, color);
                        }
                    }
                    break;
            }
        }
Beispiel #51
0
 public void DrawMarker(float x, float y, PixelFarm.Drawing.Color color, float sizeInPx = 8)
 {
     painter.FillRect(x, y, sizeInPx, sizeInPx, color);
 }
Beispiel #52
0
        void CreateChromaTestButtons(AppHost host, int x, int y)
        {
            void ShowColorBoxs(Box colorBoxPanel, PixelFarm.Drawing.Color[] colors)
            {
                //nested method
                colorBoxPanel.ClearChildren();
                for (int i = 0; i < colors.Length; ++i)
                {
                    Box colorBox = new Box(30, 30);

                    PixelFarm.Drawing.Color c = colors[i];
                    colorBox.BackColor = new PixelFarm.Drawing.Color(c.R, c.G, c.B);
                    colorBoxPanel.Add(colorBox);
                }

                UI.LayoutUpdateArgs updateArgs = new UI.LayoutUpdateArgs();

                colorBoxPanel.PerformContentLayout(updateArgs);
            }

            Box colorPanel = new Box(200, 40);

            colorPanel.ContentLayoutKind = BoxContentLayoutKind.HorizontalStack;
            colorPanel.BackColor         = PixelFarm.Drawing.Color.White;
            colorPanel.SetLocation(x, y);
            host.AddChild(colorPanel);

            y += colorPanel.Height;

            //test1...
            var buttonBeh = new UI.UIMouseBehaviour <Label, object>();

            buttonBeh.MouseMove += (s, e) =>
            {
                if (e.CurrentContextElement is Label lbl)
                {
                    lbl.BackColor = PixelFarm.Drawing.Color.Yellow;
                }
            };
            buttonBeh.MouseLeave += (s, e) =>
            {
                if (e.CurrentContextElement is Label lbl)
                {
                    lbl.BackColor = PixelFarm.Drawing.KnownColors.Gray;
                }
            };


            //----------------------------------
            {
                Label lblChromaDarken = new Label();
                lblChromaDarken.BackColor = PixelFarm.Drawing.KnownColors.Gray;
                lblChromaDarken.Text      = "Darken";
                lblChromaDarken.SetLocation(x, y);

                buttonBeh.AttachSharedBehaviorTo(lblChromaDarken);

                UI.GeneralEventListener evListener = new UI.GeneralEventListener();
                evListener.MouseDown += (s, e) =>
                {
                    PixelFarm.Drawing.Color color = PixelFarm.Drawing.KnownColors.DeepPink;
                    using (Tools.More.BorrowChromaTool(out var chroma))
                    {
                        chroma.SetColor(color);
                        PixelFarm.Drawing.Color[] colors = new[] {
                            color,
                            chroma.Darken(),
                            chroma.Darken(2),
                            chroma.Darken(2.6)
                        };
                        //present in the box
                        ShowColorBoxs(colorPanel, colors);
                    }
                };
                lblChromaDarken.AttachExternalEventListener(evListener);
                x += 50;

                host.AddChild(lblChromaDarken);
            }

            //----------------------------------
            {
                Label lblLighten = new Label();
                lblLighten.Text = "Brighten";
                buttonBeh.AttachSharedBehaviorTo(lblLighten);

                lblLighten.SetLocation(x, y);
                {
                    UI.GeneralEventListener evListener = new UI.GeneralEventListener();
                    evListener.MouseDown += (s, e) =>
                    {
                        PixelFarm.Drawing.Color color = PixelFarm.Drawing.KnownColors.DeepPink;
                        using (Tools.More.BorrowChromaTool(out var chroma))
                        {
                            chroma.SetColor(color);
                            PixelFarm.Drawing.Color[] colors = new[] {
                                color,
                                chroma.Brighten(),
                                chroma.Brighten(2),
                                chroma.Brighten(3)
                            };
                            //present in the box
                            ShowColorBoxs(colorPanel, colors);
                        }
                    };
                    lblLighten.AttachExternalEventListener(evListener);
                }
                x += lblLighten.Width + 5;

                host.AddChild(lblLighten);
            }
        }

        void CreateRBGVarBoxes(AppHost host, int x, int y)
        {
            _rgb_varBoxes = new Box[7];
            for (int i = 0; i < 7; ++i)
            {
                Box rgb_varBox = new Box(40, 40);
                rgb_varBox.SetLocation(x + (i * 40), y);
                _rgb_varBoxes[i] = rgb_varBox;
                host.AddChild(rgb_varBox);
            }
        }

        void CreateSwatchBoxes(AppHost host, int x, int y)
        {
            _swatch_Boxes = new Box[6];
            for (int i = 0; i < 6; ++i)
            {
                Box swatchBox = new Box(40, 40);
                swatchBox.SetLocation(x + (i * 40), y);
                _swatch_Boxes[i] = swatchBox;
                host.AddChild(swatchBox);
            }
        }

        void CreateHsvVarBoxes(AppHost host, int x, int y)
        {
            _hsv_varBoxes = new Box[9];
            for (int i = 0; i < 9; ++i)
            {
                Box hsv_varBox = new Box(40, 40);
                hsv_varBox.SetLocation(x + (i * 40), y);
                _hsv_varBoxes[i] = hsv_varBox;
                host.AddChild(hsv_varBox);
            }
        }

        void CreateRBGScrollBarAndSampleColorBox(
            int x, int y,
            out ScrollBar scBar,
            out Box sampleBox,
            Action <ScrollBar, Box> pairAction
            )
        {
            //Action<>
            //horizontal scrollbar
            scBar = new LayoutFarm.CustomWidgets.ScrollBar(300, 15);

            //TODO: add mx with layout engine
            scBar.ScrollBarType = CustomWidgets.ScrollBarType.Horizontal;
            scBar.SetLocation(x, y);
            scBar.MinValue    = 0;
            scBar.MaxValue    = 255 * 10;
            scBar.SmallChange = 1;
            //
            scBar.ScrollValue = 0; //init
                                   //
            sampleBox = new Box(30, 30);
            sampleBox.SetLocation(x + 350, y);
            //
            var n_scBar     = scBar;
            var n_sampleBox = sampleBox;

            scBar.SliderBox.UserScroll += (s, e) => pairAction(n_scBar, n_sampleBox);

            pairAction(n_scBar, n_sampleBox);
        }

        bool _component_ready = false;

        void UpdateAllComponents()
        {
            byte r = (byte)(_r_sc.ScrollValue / 10);
            byte g = (byte)(_g_sc.ScrollValue / 10);
            byte b = (byte)(_b_sc.ScrollValue / 10);

            _pure_rgbBox.BackColor = new PixelFarm.Drawing.Color(r, g, b);

            //the update ColorMatch
            _colorMatch.CurrentAlgorithm = _blenderAlgo;
            _colorMatch.CurrentRGB       = new RGB(r, g, b);
            _colorMatch.CurrentHSV       = _colorMatch.CurrentRGB.ToHSV();
            _colorMatch.CurrentRGB       = _colorMatch.CurrentHSV.ToRGB();//?
            _colorMatch.Update();
            //then present color match results
            //1. rgb variants
            for (int i = 0; i < 7; ++i)
            {
                _rgb_varBoxes[i].BackColor = _colorMatch.VariationsRGB[i].ToPixelFarmColor();
            }
            //2. hsv variants
            for (int i = 0; i < 9; ++i)
            {
                _hsv_varBoxes[i].BackColor = _colorMatch.VariationsHSV[i].ToPixelFarmColor();
            }
            //3. swatch box
            Blend blend = _colorMatch.CurrentBlend;

            for (int i = 0; i < 6; ++i)
            {
                _swatch_Boxes[i].BackColor = blend.Colors[i].ToRGB().ToPixelFarmColor();
            }
        }
    }