Ejemplo n.º 1
0
 public void SetRendererPreDraw(ImageBuffer background, RendererBase rendererToDrawWith, Player playerToCenterOn)
 {
     rendererToDrawWith.PushTransform();
     Vector2D windowCenter = new Vector2D(screenWindow.Left + (screenWindow.Right - screenWindow.Left) / 2, screenWindow.Bottom + (screenWindow.Top - screenWindow.Bottom) / 2);
     Vector2D playerPos = playerToCenterOn.Position;
     Vector2D playfieldOffset = windowCenter - playerPos;
     if (playfieldOffset.x > screenWindow.Left)
     {
         playfieldOffset.x = screenWindow.Left;
     }
     if (playfieldOffset.x < -background.Width() + screenWindow.Right)
     {
         playfieldOffset.x = -background.Width() + screenWindow.Right;
     }
     if (playfieldOffset.y > screenWindow.Bottom)
     {
         playfieldOffset.y = screenWindow.Bottom;
     }
     if (playfieldOffset.y < -background.Height() + screenWindow.Top)
     {
         playfieldOffset.y = -background.Height() + screenWindow.Top;
     }
     Affine translation = Affine.NewTranslation(playfieldOffset);
     rendererToDrawWith.SetTransform(rendererToDrawWith.GetTransform() * translation);
     rendererToDrawWith.SetClippingRect(screenWindow);
 }
Ejemplo n.º 2
0
        internal ImageRenderer(ImageBuffer owner)
            : base()
        {
            m_Owner = owner;

            rasterizer_scanline_aa rasterizer = new rasterizer_scanline_aa();
            ImageClippingProxy imageClippingProxy = new ImageClippingProxy(owner);

            Initialize(imageClippingProxy, rasterizer);
            ScanlineCache = new scanline_packed_8();
        }
Ejemplo n.º 3
0
 public override void Process(ImageBuffer buffer)
 {
     var children = this.Children.OfType<SvgMergeNode>().ToList();
     var inputImage = buffer[children.First().Input];
     var result = new Bitmap(inputImage.Width, inputImage.Height);
     using (var g = Graphics.FromImage(result))
     {
         foreach (var child in children)
         {
             g.DrawImage(buffer[child.Input], new Rectangle(0, 0, inputImage.Width, inputImage.Height),
                         0, 0, inputImage.Width, inputImage.Height, GraphicsUnit.Pixel);
         }
         g.Flush();
     }
     result.Save(@"C:\test.png");
     buffer[this.Result] = result;
 }
Ejemplo n.º 4
0
        public PlayfieldView(rect_d bounds)
        {
            Bounds = bounds;

            backgroundImageSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "Map1Background");
            backgroundImage = backgroundImageSequence.GetImageByIndex(0);

            ImageSequence menuButtonSequence = (ImageSequence)DataAssetCache.Instance.GetAsset(typeof(ImageSequence), "MenuButtonFromGame");
            ButtonWidget menuButton = new ButtonWidget(400, 12, new ThreeImageButtonView(menuButtonSequence.GetImageByIndex(0), menuButtonSequence.GetImageByIndex(1), menuButtonSequence.GetImageByIndex(2)));
            AddChild(menuButton);
            menuButton.ButtonClick += new ButtonWidget.ButtonEventHandler(EscapeMenu);

            playerViews[0] = new PlayerView(new rect_d(400, 300, 800, 600));
            playerViews[1] = new PlayerView(new rect_d(400, 0, 800, 300));
            playerViews[2] = new PlayerView(new rect_d(0, 300, 400, 600));
            playerViews[3] = new PlayerView(new rect_d(0, 0, 400, 300));
        }
        public override void Init(int width, int height, GuiHalSurface.CreateFlags flags, GuiHalSurface.PixelFormat pixelFormat)
        {
            //if (windowsFormsWindow.m_sys_format == PlatformSupportAbstract.ImageFormats.pix_format_undefined)
            {
                //  return false;
            }

            m_window_flags = flags;

            initialWidth = width;
            initialHeight = height;

            int bitDepth = GetBitDepthForPixelFormat(m_format);
            switch (bitDepth)
            {
                case 24:
                    backBuffer = new ImageBuffer(initialWidth, initialHeight, 24, new BlenderBGR());
                    break;

                case 32:
                    backBuffer = new ImageBuffer(initialWidth, initialHeight, 32, new BlenderBGRA());
                    break;

                case 128:
                    throw new NotImplementedException();
                    //backBuffer = null;
                    //m_BackBufferFloat = new ImageBufferFloat(initialWidth, initialHeight, 128, new BlenderBGRAFloat());
                    //break;

                default:
                    throw new NotImplementedException("Don't support this bit depth yet.");
            }

            System.Drawing.Size clientSize = new System.Drawing.Size();
            clientSize.Width = (int)width;
            clientSize.Height = (int)height;
            windowsFormsWindow.ClientSize = clientSize;

            if ((m_window_flags & CreateFlags.Resizable) == 0)
            {
                windowsFormsWindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
                windowsFormsWindow.MaximizeBox = false;
            }

            clientSize.Width = width;
            clientSize.Height = height;
            windowsFormsWindow.ClientSize = clientSize;

            Bounds = new rect_d(0, 0, width, height);

            OnInitialize();
            windowsFormsWindow.m_WindowContentNeedsRedraw = true;
        }
Ejemplo n.º 6
0
        public override void OnDraw(RendererBase renderer)
        {
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.value());
            IBlender NormalBlender = new BlenderBGRA();
            IBlender GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer(NewRenderer().DestImage, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer(NewRenderer().DestImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new RGBA_Doubles(0,0,0));

            rasterizer_scanline_aa ras = new rasterizer_scanline_aa();
            scanline_packed_8 sl = new scanline_packed_8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            Renderer.RenderSolid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10);
            r.normalize_radius();

            // Drawing as an outline
                conv_stroke p = new conv_stroke(r);
                p.width(1.0);
                ras.add_path(p);

                //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
            Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(255, 1, 1));








            /*            
                    int i;

                    // radial line test
                    //-------------------------
                    dashed_line<rasterizer_type, 
                                renderer_scanline_type, 
                                scanline_type> dash(ras, ren_sl, sl);

                    double cx = width() / 2.0;
                    double cy = height() / 2.0;

                    ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
                    for(i = 180; i > 0; i--) 
                    {
                        double n = 2.0 * agg::pi * i / 180.0;
                        dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
                                  cx, cy, 
                                  1.0, (i < 90) ? i : 0.0);
                    }


                    typedef agg::gradient_x gradient_func_type;
                    typedef agg::span_interpolator_linear<> interpolator_type;
                    typedef agg::span_allocator<color_type> span_allocator_type;
                    typedef agg::pod_auto_array<color_type, 256> color_array_type;
                    typedef agg::span_gradient<color_type, 
                                               interpolator_type, 
                                               gradient_func_type, 
                                               color_array_type> span_gradient_type;

                    typedef agg::renderer_scanline_aa<renderer_base_type, 
                                                      span_allocator_type,
                                                      span_gradient_type> renderer_gradient_type;

                    gradient_func_type  gradient_func;                   // The gradient function
                    agg::trans_affine   gradient_mtx;                    // Affine transformer
                    interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
                    span_allocator_type span_allocator;                  // Span Allocator
                    color_array_type    gradient_colors;                 // The gradient colors
                    span_gradient_type  span_gradient(span_interpolator, 
                                                      gradient_func, 
                                                      gradient_colors, 
                                                      0, 100);

                    renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);

                    dashed_line<rasterizer_type, 
                                renderer_gradient_type, 
                                scanline_type> dash_gradient(ras, ren_gradient, sl);

                    double x1, y1, x2, y2;

                    for(i = 1; i <= 20; i++)
                    {
                        ren_sl.color(agg::rgba(1,1,1));

                        // integral point sizes 1..20
                        //----------------
                        agg::ellipse ell;
            
                        ell.init(20 + i * (i + 1) + 0.5, 
                                 20.5, 
                                 i / 2.0, 
                                 i / 2.0, 
                                 8 + i);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);
            

                        // fractional point sizes 0..2
                        //----------------
                        ell.init(18 + i * 4 + 0.5, 33 + 0.5, 
                                 i/20.0, i/20.0, 
                                 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // fractional point positioning
                        //---------------
                        ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5, 
                                 27 + (i - 1) / 10.0 + 0.5, 
                                 0.5, 0.5, 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // integral line widths 1..20
                        //----------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));

                        x1 = 20 + i* (i + 1);
                        y1 = 40.5;
                        x2 = 20 + i * (i + 1) + (i - 1) * 4;
                        y2 = 100.5;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, i, 0);


                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(0,0,1));

                        // fractional line lengths H (red/blue)
                        //----------------
                        x1 = 17.5 + i * 4;
                        y1 = 107;
                        x2 = 17.5 + i * 4 + i/6.66666667;
                        y2 = 107;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line lengths V (red/blue)
                        //---------------
                        x1 = 18 + i * 4;
                        y1 = 112.5;
                        x2 = 18 + i * 4;
                        y2 = 112.5 + i / 6.66666667;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);

                        // fractional line positioning (red)
                        //---------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(1,1,1));
                        x1 = 21.5;
                        y1 = 120 + (i - 1) * 3.1;
                        x2 = 52.5;
                        y2 = 120 + (i - 1) * 3.1;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line width 2..0 (green)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,1,0), 
                                         agg::rgba(1,1,1));
                        x1 = 52.5;
                        y1 = 118 + i * 3;
                        x2 = 83.5;
                        y2 = 118 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);

                        // stippled fractional width 2..0 (blue)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,0,1), 
                                         agg::rgba(1,1,1));
                        x1 = 83.5;
                        y1 = 119 + i * 3;
                        x2 = 114.5;
                        y2 = 119 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);


                        ren_sl.color(agg::rgba(1,1,1));
                        if(i <= 10)
                        {
                            // integral line width, horz aligned (mipmap test)
                            //-------------------
                            dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
                                      135.5, 119.5 + (i + 2) * (i / 2.0),
                                      i, 0.0);
                        }

                        // fractional line width 0..2, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);

                        // fractional line positioning, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186, 
                                  18.5 + i * 4 + (i - 1) / 10.0, 186,
                                  1.0, 0);
                    }


                    // Triangles
                    //---------------
                    for (int i = 1; i <= 13; i++) 
                    {
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
                        calc_linear_gradient_transform(width()  - 150, 
                                                       height() - 20 - i * (i + 1.5),
                                                       width()  - 20,  
                                                       height() - 20 - i * (i + 1),
                                                       gradient_mtx);
                        ras.reset();
                        ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
                        agg::render_scanlines(ras, sl, ren_gradient);
                    }
             */










            base.OnDraw(renderer);
        }
Ejemplo n.º 7
0
 public PartImage(ImageBuffer imageOfPart)
 {
     this.image = imageOfPart;
 }
Ejemplo n.º 8
0
        public Task SaveSheets()
        {
            return(ApplicationController.Instance.Tasks.Execute(
                       "Export Part Sheet".Localize(),
                       null,
                       async(reporter, cancelationToken) =>
            {
                var progressStatus = new ProgressStatus();

                var processCount = 0.0;
                currentlySaving = true;
                // first create images for all the parts
                foreach (var item in itemSource)
                {
                    progressStatus.Status = item.Name;
                    reporter.Report(progressStatus);

                    var xxx = itemSource.Count();
                    var yyy = itemSource.FirstOrDefault()?.Name;

                    var object3D = await item.CreateContent();

                    var loadedMeshGroups = object3D.VisibleMeshes().ToList();
                    if (loadedMeshGroups?.Count > 0)
                    {
                        AxisAlignedBoundingBox aabb = loadedMeshGroups[0].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[0].WorldMatrix());

                        for (int i = 1; i < loadedMeshGroups.Count; i++)
                        {
                            aabb = AxisAlignedBoundingBox.Union(aabb, loadedMeshGroups[i].Mesh.GetAxisAlignedBoundingBox(loadedMeshGroups[i].WorldMatrix()));
                        }

                        RectangleDouble bounds2D = new RectangleDouble(aabb.MinXYZ.X, aabb.MinXYZ.Y, aabb.MaxXYZ.X, aabb.MaxXYZ.Y);
                        double widthInMM = bounds2D.Width + PartMarginMM * 2;
                        double textSpaceMM = 5;
                        double heightMM = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                        TypeFacePrinter typeFacePrinter = new TypeFacePrinter(item.Name, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                        double sizeOfNameX = typeFacePrinter.GetSize().X + PartMarginPixels * 2;
                        Vector2 sizeOfRender = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                        ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.X)), (int)(sizeOfRender.Y));
                        typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                        Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                        RectangleDouble rectBounds = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                        double strokeWidth = .5 * PixelPerMM;
                        rectBounds.Inflate(-strokeWidth / 2);
                        RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                        partGraphics2D.Render(rect, Color.LightGray);
                        Stroke rectOutline = new Stroke(rect, strokeWidth);
                        partGraphics2D.Render(rectOutline, Color.DarkGray);

                        foreach (var meshGroup in loadedMeshGroups)
                        {
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, meshGroup.Mesh, meshGroup.WorldMatrix(), new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, Color.Black);
                        }
                        partGraphics2D.Render(typeFacePrinter, Color.Black);

                        partImagesToPrint.Add(new PartImage(imageOfPart));
                    }

                    progressStatus.Progress0To1 = Math.Min(processCount / itemSource.Count, .95);
                    reporter.Report(progressStatus);
                    processCount++;
                }

                progressStatus.Status = "Saving".Localize();
                reporter.Report(progressStatus);

                partImagesToPrint.Sort(BiggestToLittlestImages);

                PdfDocument document = new PdfDocument();
                document.Info.Title = "MatterHackers Parts Sheet";
                document.Info.Author = "MatterHackers Inc.";
                document.Info.Subject = "This is a list of the parts that are in a queue from MatterControl.";
                document.Info.Keywords = "MatterControl, STL, 3D Printing";

                int nextPartToPrintIndex = 0;
                int plateNumber = 1;
                bool done = false;

                while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
                {
                    PdfPage pdfPage = document.AddPage();
                    CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
                }

                try
                {
                    // save the final document
                    document.Save(pathAndFileToSaveTo);

                    // Now try and open the document. This will launch whatever PDF viewer is on the system and ask it
                    // to show the file (at least on Windows).
                    Process.Start(pathAndFileToSaveTo);
                }
                catch (Exception)
                {
                }

                currentlySaving = false;

                progressStatus.Progress0To1 = 1;
                reporter.Report(progressStatus);
            }));
        }
        public TextImageWidget(string label, RGBA_Bytes fillColor, RGBA_Bytes borderColor, RGBA_Bytes textColor, double borderWidth, BorderDouble margin, ImageBuffer image = null, int fontSize = 12, FlowDirection flowDirection = FlowDirection.LeftToRight, double height = 40, double width = 0, bool centerText = false)
            : base()
        {
            this.image       = image;
            this.fillColor   = fillColor;
            this.borderColor = borderColor;
            this.borderWidth = borderWidth;
            this.Margin      = new BorderDouble(0);
            this.Padding     = new BorderDouble(0);

            TextWidget  textWidget = new TextWidget(label, pointSize: fontSize);
            ImageWidget imageWidget;

            FlowLayoutWidget container = new FlowLayoutWidget(flowDirection);

            if (centerText)
            {
                // make sure the contents are centered
                GuiWidget leftSpace = new GuiWidget(0, 1);
                leftSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                container.AddChild(leftSpace);
            }

            if (image != null && image.Width > 0)
            {
                imageWidget         = new ImageWidget(image);
                imageWidget.VAnchor = VAnchor.ParentCenter;
                container.AddChild(imageWidget);
            }

            if (label != "")
            {
                textWidget.VAnchor   = VAnchor.ParentCenter;
                textWidget.TextColor = textColor;
                textWidget.Padding   = new BorderDouble(3, 0);
                container.AddChild(textWidget);
            }

            if (centerText)
            {
                GuiWidget rightSpace = new GuiWidget(0, 1);
                rightSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                container.AddChild(rightSpace);

                container.HAnchor = Agg.UI.HAnchor.ParentLeftRight | Agg.UI.HAnchor.FitToChildren;
            }
            container.VAnchor = Agg.UI.VAnchor.ParentCenter;

            container.MinimumSize = new Vector2(width, height);
            container.Margin      = margin;
            this.AddChild(container);
            HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
            VAnchor = VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
        }
        private ButtonViewStates getButtonView(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false)
        {
            if (hoverImageName == null)
            {
                hoverImageName = normalImageName;
            }

            if (pressedImageName == null)
            {
                pressedImageName = hoverImageName;
            }

            if (disabledImageName == null)
            {
                disabledImageName = normalImageName;
            }

            ImageBuffer normalImage   = new ImageBuffer();
            ImageBuffer pressedImage  = new ImageBuffer();
            ImageBuffer hoverImage    = new ImageBuffer();
            ImageBuffer disabledImage = new ImageBuffer();

            if (normalImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(normalImage);
                }
            }

            if (hoverImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(pressedImage);
                }
            }

            if (pressedImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(hoverImageName), hoverImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(hoverImage);
                }
            }

            if (disabledImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(disabledImageName), disabledImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(disabledImage);
                }
            }

            if (invertImageLocation)
            {
                flowDirection = FlowDirection.RightToLeft;
            }
            else
            {
                flowDirection = FlowDirection.LeftToRight;
            }

            //Create the multi-state button view
            ButtonViewStates buttonViewWidget = new ButtonViewStates(
                new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText),
                new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, Margin, hoverImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText),
                new TextImageWidget(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText),
                new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, disabledImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText)
                );

            return(buttonViewWidget);
        }
Ejemplo n.º 11
0
 public static void RemoveTexture(this Mesh mesh, int faceIndex, ImageBuffer texture, int index)
 {
     mesh.FaceTextures.Remove(faceIndex);
 }
Ejemplo n.º 12
0
        public static void DoSubtract(ImageBuffer result, ImageBuffer imageToSubtractFrom, ImageBuffer imageToSubtract)
        {
            if (lookupSubtractAndClamp == null)
            {
                CreateLookup();
            }

            if (imageToSubtractFrom.BitDepth != imageToSubtract.BitDepth || imageToSubtract.BitDepth != result.BitDepth)
            {
                throw new NotImplementedException("All the images have to be the same bit depth.");
            }
            if (imageToSubtractFrom.Width != imageToSubtract.Width || imageToSubtractFrom.Height != imageToSubtract.Height ||
                imageToSubtractFrom.Width != result.Width || imageToSubtractFrom.Height != result.Height)
            {
                throw new Exception("All images must be the same size.");
            }

            switch (imageToSubtractFrom.BitDepth)
            {
            case 32:
            {
                int    height       = imageToSubtractFrom.Height;
                int    width        = imageToSubtractFrom.Width;
                byte[] resultBuffer = result.GetBuffer();
                byte[] imageABuffer = imageToSubtractFrom.GetBuffer();
                byte[] imageBBuffer = imageToSubtract.GetBuffer();
                for (int y = 0; y < height; y++)
                {
                    int offset = imageToSubtractFrom.GetBufferOffsetY(y);

                    for (int x = 0; x < width; x++)
                    {
                        resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];                                         // add 255 to make sure not < 0
                        offset++;
                        resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
                        offset++;
                        resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
                        offset++;
                        resultBuffer[offset] = 255;
                        offset++;
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 13
0
        public void GenerateMarchingSquaresAndLines(Action <double, string> progressReporter, ImageBuffer image, IThresholdFunction thresholdFunction)
        {
            if (image != null)
            {
                // Regenerate outline
                var marchingSquaresData = new MarchingSquaresByte(
                    image,
                    thresholdFunction.ZeroColor,
                    thresholdFunction.Threshold,
                    0);

                progressReporter?.Invoke(0, "Creating Outline");

                marchingSquaresData.CreateLineSegments();
                progressReporter?.Invoke(.1, null);

                int pixelsToIntPointsScale = 1000;
                var lineLoops = marchingSquaresData.CreateLineLoops(pixelsToIntPointsScale);

                progressReporter?.Invoke(.15, null);

                var min = new IntPoint(-10, -10);
                var max = new IntPoint(10 + image.Width * pixelsToIntPointsScale, 10 + image.Height * pixelsToIntPointsScale);

                var boundingPoly = new Polygon();
                boundingPoly.Add(min);
                boundingPoly.Add(new IntPoint(min.X, max.Y));
                boundingPoly.Add(max);
                boundingPoly.Add(new IntPoint(max.X, min.Y));

                // now clip the polygons to get the inside and outside polys
                var clipper = new Clipper();
                clipper.AddPaths(lineLoops, PolyType.ptSubject, true);
                clipper.AddPath(boundingPoly, PolyType.ptClip, true);

                var polygonShape = new Polygons();
                progressReporter?.Invoke(.3, null);

                clipper.Execute(ClipType.ctIntersection, polygonShape);

                progressReporter?.Invoke(.55, null);

                polygonShape = Clipper.CleanPolygons(polygonShape, 100);

                progressReporter?.Invoke(.75, null);

                VertexStorage rawVectorShape = polygonShape.PolygonToPathStorage();

                var aabb   = this.VisibleMeshes().FirstOrDefault().GetAxisAlignedBoundingBox();
                var xScale = aabb.XSize / image.Width;

                var affine = Affine.NewScaling(1.0 / pixelsToIntPointsScale * xScale);
                affine *= Affine.NewTranslation(-aabb.XSize / 2, -aabb.YSize / 2);

                rawVectorShape.transform(affine);
                this.VertexSource = rawVectorShape;

                progressReporter?.Invoke(1, null);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Loads the specified file from the StaticData/Icons path
 /// </summary>
 /// <param name="path">The file path to load</param>
 /// <param name="buffer">The ImageBuffer to populate with data from the given file</param>
 public void LoadIcon(string path, ImageBuffer buffer)
 {
     LoadImage(Path.Combine("Icons", path), buffer);
 }
Ejemplo n.º 15
0
        public void LoadImageData(Stream imageStream, ImageBuffer destImage)
        {
            var bitmap = new Bitmap(imageStream);

            ImageIOWindowsPlugin.ConvertBitmapToImage(destImage, bitmap);
        }
Ejemplo n.º 16
0
        public Entity(double radius, Playfield in_playfield)
		{
            levelMap = in_playfield.LevelMap;
			m_Radius = radius;
			m_Velocity = new Vector2D(60,120);
		}
Ejemplo n.º 17
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer        widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());
            ImageClippingProxy clippingProxy   = new ImageClippingProxy(widgetsSubImage);

            clippingProxy.clear(new ColorF(1, 1, 1));
            m_ras.SetVectorClipBox(0, 0, Width, Height);

            Affine move = Affine.NewTranslation(10, 10);

            Perspective shadow_persp = new Perspective(m_shape_bounds.Left, m_shape_bounds.Bottom,
                                                       m_shape_bounds.Right, m_shape_bounds.Top,
                                                       m_shadow_ctrl.polygon());

            IVertexSource shadow_trans;

            if (m_FlattenCurves.Checked)
            {
                shadow_trans = new VertexSourceApplyTransform(m_shape, shadow_persp);
            }
            else
            {
                shadow_trans = new VertexSourceApplyTransform(m_path, shadow_persp);
                // this will make it very smooth after the transform
                //shadow_trans = new conv_curve(shadow_trans);
            }

            // Render shadow
            m_ras.add_path(shadow_trans);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, new ColorF(0.2, 0.3, 0).ToColor());

            // Calculate the bounding box and extend it by the blur radius
            RectangleDouble bbox = new RectangleDouble();

            bounding_rect.bounding_rect_single(shadow_trans, 0, ref bbox);

            bbox.Left   -= m_radius.Value;
            bbox.Bottom -= m_radius.Value;
            bbox.Right  += m_radius.Value;
            bbox.Top    += m_radius.Value;

            if (m_method.SelectedIndex == 1)
            {
                // The recursive blur method represents the true Gaussian Blur,
                // with theoretically infinite kernel. The restricted window size
                // results in extra influence of edge pixels. It's impossible to
                // solve correctly, but extending the right and top areas to another
                // radius value produces fair result.
                //------------------
                bbox.Right += m_radius.Value;
                bbox.Top   += m_radius.Value;
            }

            stopwatch.Restart();

            if (m_method.SelectedIndex != 2)
            {
                // Create a new pixel renderer and attach it to the main one as a child image.
                // It returns true if the attachment succeeded. It fails if the rectangle
                // (bbox) is fully clipped.
                //------------------
#if SourceDepth24
                ImageBuffer image2 = new ImageBuffer(new BlenderBGR());
#else
                ImageBuffer image2 = new ImageBuffer(new BlenderBGRA());
#endif
                if (image2.Attach(widgetsSubImage, (int)bbox.Left, (int)bbox.Bottom, (int)bbox.Right, (int)bbox.Top))
                {
                    // Blur it
                    if (m_method.SelectedIndex == 0)
                    {
                        // More general method, but 30-40% slower.
                        //------------------
                        //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value));

                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        stack_blur test = new stack_blur();
                        test.Blur(image2, agg_basics.uround(m_radius.Value), agg_basics.uround(m_radius.Value));
                    }
                    else
                    {
                        // True Gaussian Blur, 3-5 times slower than Stack Blur,
                        // but still constant time of radius. Very sensitive
                        // to precision, doubles are must here.
                        //------------------
                        m_recursive_blur.blur(image2, m_radius.Value);
                    }
                }
            }
            else
            {
                /*
                 * // Blur separate channels
                 * //------------------
                 * if(m_channel_r.Checked)
                 * {
                 *      typedef agg::pixfmt_alpha_blend_gray<
                 *              agg::blender_gray8,
                 *              agg::rendering_buffer,
                 *              3, 2> pixfmt_gray8r;
                 *
                 *      pixfmt_gray8r pixf2r(m_rbuf2);
                 *      if(pixf2r.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *      {
                 *              agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value),
                 *                                                                        agg::uround(m_radius.Value));
                 *      }
                 * }
                 *
                 * if(m_channel_g.Checked)
                 * {
                 *      typedef agg::pixfmt_alpha_blend_gray<
                 *              agg::blender_gray8,
                 *              agg::rendering_buffer,
                 *              3, 1> pixfmt_gray8g;
                 *
                 *      pixfmt_gray8g pixf2g(m_rbuf2);
                 *      if(pixf2g.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *      {
                 *              agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value),
                 *                                                                        agg::uround(m_radius.Value));
                 *      }
                 * }
                 *
                 * if(m_channel_b.Checked)
                 * {
                 *      typedef agg::pixfmt_alpha_blend_gray<
                 *              agg::blender_gray8,
                 *              agg::rendering_buffer,
                 *              3, 0> pixfmt_gray8b;
                 *
                 *      pixfmt_gray8b pixf2b(m_rbuf2);
                 *      if(pixf2b.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *      {
                 *              agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value),
                 *                                                                        agg::uround(m_radius.Value));
                 *      }
                 * }
                 */
            }

            double tm = stopwatch.ElapsedMilliseconds;

            // Render the shape itself
            //------------------
            if (m_FlattenCurves.Checked)
            {
                m_ras.add_path(m_shape);
            }
            else
            {
                m_ras.add_path(m_path);
            }

            scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, new ColorF(0.6, 0.9, 0.7, 0.8).ToColor());

            graphics2D.DrawString(string.Format("{0:F2} ms", tm), 140, 30);
            base.OnDraw(graphics2D);
        }
Ejemplo n.º 18
0
 public AddOnRow(string text, ThemeConfig theme, GuiWidget optionalControls, ImageBuffer icon)
     : base(text, theme, null, optionalControls, icon)
 {
     imageWidget.Cursor = Cursors.Hand;
     imageWidget.Margin = 4;
     imageWidget.Click += (s, e) =>
     {
         optionalControls.InvokeClick();
     };
 }
Ejemplo n.º 19
0
 public override void Process(ImageBuffer buffer)
 {
     // TODO: Implement feDisplacementMap filter Process().
 }
Ejemplo n.º 20
0
        private void CreateProductDataWidgets(PrinterSettings printerSettings, ProductSkuData product)
        {
            var row = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(top: theme.DefaultContainerPadding)
            };

            productDataContainer.AddChild(row);

            var image = new ImageBuffer(150, 10);

            row.AddChild(new ImageWidget(image)
            {
                Margin  = new BorderDouble(right: theme.DefaultContainerPadding),
                VAnchor = VAnchor.Top
            });

            WebCache.RetrieveImageAsync(image, product.FeaturedImage.ImageUrl, scaleToImageX: true);

            var descriptionBackground = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Top,
                Padding = theme.DefaultContainerPadding
            };

            var description = new MarkdownWidget(theme)
            {
                MinimumSize = new VectorMath.Vector2(350, 0),
                HAnchor     = HAnchor.Stretch,
                VAnchor     = VAnchor.Fit,
                Markdown    = product.ProductDescription.Trim()
            };

            descriptionBackground.AddChild(description);
            descriptionBackground.BeforeDraw += (s, e) =>
            {
                var rect = new RoundedRect(descriptionBackground.LocalBounds, 3);
                e.Graphics2D.Render(rect, theme.SlightShade);
            };

            row.AddChild(descriptionBackground);

            var padding = theme.DefaultContainerPadding;

            var addonsColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Padding = new BorderDouble(padding, padding, padding, 0),
                HAnchor = HAnchor.Stretch
            };

            var addonsSection = new SectionWidget("Upgrades and Accessories", addonsColumn, theme);

            productDataContainer.AddChild(addonsSection);
            theme.ApplyBoxStyle(addonsSection);
            addonsSection.Margin = addonsSection.Margin.Clone(left: 0);

            foreach (var item in product.ProductListing.AddOns)
            {
                var icon = new ImageBuffer(80, 0);
                WebCache.RetrieveImageAsync(icon, item.FeaturedImage.ImageUrl, scaleToImageX: true);

                var addOnRow = new AddOnRow(item.AddOnTitle, theme, null, icon)
                {
                    HAnchor = HAnchor.Stretch,
                    Cursor  = Cursors.Hand
                };

                foreach (var child in addOnRow.Children)
                {
                    child.Selectable = false;
                }

                addOnRow.Click += (s, e) =>
                {
                    ApplicationController.Instance.LaunchBrowser($"https://www.matterhackers.com/store/l/{item.AddOnListingReference}/sk/{item.AddOnSkuReference}");
                };

                addonsColumn.AddChild(addOnRow);
            }

            if (false)
            {
                var settingsPanel = new GuiWidget()
                {
                    HAnchor         = HAnchor.Stretch,
                    VAnchor         = VAnchor.Stretch,
                    MinimumSize     = new VectorMath.Vector2(20, 20),
                    DebugShowBounds = true
                };

                settingsPanel.Load += (s, e) =>
                {
                    var printer = new PrinterConfig(printerSettings);

                    var settingsContext = new SettingsContext(
                        printer,
                        null,
                        NamedSettingsLayers.All);

                    settingsPanel.AddChild(
                        new ConfigurePrinterWidget(settingsContext, printer, theme)
                    {
                        HAnchor = HAnchor.Stretch,
                        VAnchor = VAnchor.Stretch,
                    });
                };

                this.AddChild(new SectionWidget("Settings", settingsPanel, theme, expanded: false, setContentVAnchor: false)
                {
                    VAnchor = VAnchor.Stretch
                });
            }
        }
Ejemplo n.º 21
0
 public static Graphics FromImage(ImageBuffer image)
 {
     return(new Graphics(image, image.NewGraphics2D()));
 }
    public void ParsePattern(ICrop crop, ISampling sampling, IColorQuantizer quantizer, IColorCache colorCache)
    {
        if (!this.IsParsing)
        {
            IsParsing = true;
            Thread thread = new Thread(() =>
            {
                var bmp = new Bitmap((System.Drawing.Image)Image.Clone());

                int desiredWidth  = 32;
                int desiredHeight = 32;
                if (crop != null)
                {
                    crop.SetImage(bmp);
                    desiredWidth  = crop.GetWidth();
                    desiredHeight = crop.GetHeight();
                }

                if (quantizer is BaseColorCacheQuantizer colorCacheQuantizer)
                {
                    colorCacheQuantizer.ChangeCacheProvider(colorCache);
                }

                var sampledBmp = sampling.Resample(bmp, desiredWidth, desiredHeight);
                bmp.Dispose();
                bmp = sampledBmp;

                Bitmap croppedBmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(croppedBmp))
                {
                    graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    graphics.DrawImage(bmp, (32 - bmp.Width) / 2, (32 - bmp.Height) / 2, bmp.Width, bmp.Height);
                }

                bmp.Dispose();
                bmp = croppedBmp;

                var transparentPixels = new bool[bmp.Width * bmp.Height];
                for (var y = 0; y < bmp.Height; y++)
                {
                    for (var x = 0; x < bmp.Width; x++)
                    {
                        transparentPixels[x + y * bmp.Width] = bmp.GetPixel(x, y).A != 255;
                    }
                }
                var targetImage = ImageBuffer.QuantizeImage(bmp, quantizer, null, 15, 1);

                bmp.Dispose();
                bmp = new Bitmap(targetImage);
                for (var y = 0; y < bmp.Height; y++)
                {
                    for (var x = 0; x < bmp.Width; x++)
                    {
                        if (transparentPixels[x + y * bmp.Width])
                        {
                            bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 0, 0, 0));
                        }
                    }
                }
                Result    = bmp;
                IsReady   = true;
                IsParsing = false;
            });
            thread.Start();
        }
    }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates a bitmap with 32bit A-rgb (BGRA) PixelFormat
 /// </summary>
 /// <param name="width">Width.</param>
 /// <param name="height">Height.</param>
 public Bitmap(int width, int height)
 {
     this.buffer = new ImageBuffer(width, height, 32, new BlenderBGRA());
 }
        private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
        {
            ImageBuffer normalImage          = new ImageBuffer();
            ImageBuffer pressedImage         = new ImageBuffer();
            ImageBuffer normalToPressedImage = new ImageBuffer();
            ImageBuffer pressedToNormalImage = new ImageBuffer();
            string      pressedText          = pressedLabel;

            if (pressedLabel == null)
            {
                pressedText = label;
            }

            if (normalToPressedImageName == null)
            {
                normalToPressedImageName = pressedImageName;
            }

            if (pressedImageName == null)
            {
                pressedImageName = normalToPressedImageName;
            }

            if (pressedToNormalImageName == null)
            {
                pressedToNormalImageName = normalImageName;
            }

            if (normalImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);

                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(normalImage);
                }
            }

            if (pressedImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(pressedImage);
                }
            }

            if (normalToPressedImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(normalToPressedImageName), normalToPressedImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(normalToPressedImage);
                }
            }

            if (pressedToNormalImageName != null)
            {
                ImageIO.LoadImageData(this.GetImageLocation(pressedToNormalImageName), pressedToNormalImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(pressedToNormalImage);
                }
            }



            if (invertImageLocation)
            {
                flowDirection = FlowDirection.RightToLeft;
            }
            else
            {
                flowDirection = FlowDirection.LeftToRight;
            }

            //Create the multi-state button view
            GuiWidget normal                = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget normalHover           = new TextImageWidget(label, hoverFillColor, normalBorderColor, hoverTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchNormalToPressed = new TextImageWidget(label, pressedFillColor, normalBorderColor, pressedTextColor, borderWidth, Margin, normalToPressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressed               = new TextImageWidget(pressedText, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget pressedHover          = new TextImageWidget(label, hoverFillColor, pressedBorderColor, hoverTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget switchPressedToNormal = new TextImageWidget(label, normalFillColor, pressedBorderColor, normalTextColor, borderWidth, Margin, pressedToNormalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
            GuiWidget disabled              = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);

            CheckBoxViewStates checkBoxButtonViewWidget = new CheckBoxViewStates(normal, normalHover, switchNormalToPressed, pressed, pressedHover, switchPressedToNormal, disabled);

            return(checkBoxButtonViewWidget);
        }
Ejemplo n.º 25
0
 public void ResetClip()
 {
     _clipBuffer = null;
     aggGc.SetClippingRect(new RectangleDouble(aggGc.DestImage.GetBounds()));
 }
Ejemplo n.º 26
0
 public override void Process(ImageBuffer buffer)
 {
     // TODO: Implement feMorphology filter Process().
     buffer[Result] = buffer[Input];
 }
 /// <summary>
 /// See <see cref="IColorQuantizer.Prepare"/> for more details.
 /// </summary>
 public void Prepare(ImageBuffer image)
 {
     OnPrepare(image);
 }
Ejemplo n.º 28
0
        private void CreateOnePage(int plateNumber, ref int nextPartToPrintIndex, PdfPage pdfPage)
        {
            ImageBuffer plateInventoryImage           = new ImageBuffer((int)(300 * 8.5), 300 * 11);
            Graphics2D  plateGraphics                 = plateInventoryImage.NewGraphics2D();
            double      currentlyPrintingHeightPixels = PrintTopOfPage(plateInventoryImage, plateGraphics);

            Vector2          offset        = new Vector2(PageMarginPixels.Left, currentlyPrintingHeightPixels);
            double           tallestHeight = 0;
            List <PartImage> partsOnLine   = new List <PartImage>();

            while (nextPartToPrintIndex < partImagesToPrint.Count)
            {
                ImageBuffer image = partImagesToPrint[nextPartToPrintIndex].image;
                tallestHeight = Math.Max(tallestHeight, image.Height);

                if (partsOnLine.Count > 0 && offset.X + image.Width > plateInventoryImage.Width - PageMarginPixels.Right)
                {
                    if (partsOnLine.Count == 1)
                    {
                        plateGraphics.Render(partsOnLine[0].image, plateInventoryImage.Width / 2 - partsOnLine[0].image.Width / 2, offset.Y - tallestHeight);
                    }
                    else
                    {
                        foreach (PartImage partToDraw in partsOnLine)
                        {
                            plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.Y - tallestHeight);
                        }
                    }

                    offset.X      = PageMarginPixels.Left;
                    offset.Y     -= (tallestHeight + PartPaddingPixels * 2);
                    tallestHeight = 0;
                    partsOnLine.Clear();
                    if (offset.Y - image.Height < PageMarginPixels.Bottom)
                    {
                        break;
                    }
                }
                else
                {
                    partImagesToPrint[nextPartToPrintIndex].xOffset = offset.X;
                    partsOnLine.Add(partImagesToPrint[nextPartToPrintIndex]);
                    //plateGraphics.Render(image, offset.x, offset.y - image.Height);
                    offset.X += image.Width + PartPaddingPixels * 2;
                    nextPartToPrintIndex++;
                }
            }

            // print the last line of parts
            foreach (PartImage partToDraw in partsOnLine)
            {
                plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.Y - tallestHeight);
            }

            TypeFacePrinter printer = new TypeFacePrinter(string.Format("{0}", Path.GetFileNameWithoutExtension(pathAndFileToSaveTo)), 32, justification: Justification.Center);

            printer.Origin = new Vector2(plateGraphics.DestImage.Width / 2, 110);
            plateGraphics.Render(printer, Color.Black);

            printer        = new TypeFacePrinter(string.Format("Page {0}", plateNumber), 28, justification: Justification.Center);
            printer.Origin = new Vector2(plateGraphics.DestImage.Width / 2, 60);
            plateGraphics.Render(printer, Color.Black);

            MemoryStream jpegStream = new MemoryStream();

            ImageIO.SaveImageData(jpegStream, ".jpeg", plateInventoryImage);

            XGraphics gfx = XGraphics.FromPdfPage(pdfPage);

            jpegStream.Seek(0, SeekOrigin.Begin);
            XImage jpegImage = XImage.FromStream(jpegStream);

            //double width = jpegImage.PixelWidth * 72 / jpegImage.HorizontalResolution;
            //double height = jpegImage.PixelHeight * 72 / jpegImage. .HorizontalResolution;

            gfx.DrawImage(jpegImage, 0, 0, pdfPage.Width, pdfPage.Height);
        }
 /// <summary>
 /// Called when quantizer is about to be prepared for next round.
 /// </summary>
 protected virtual void OnPrepare(ImageBuffer image)
 {
     uniqueColorIndex = -1;
     paletteFound     = false;
     UniqueColors.Clear();
 }
Ejemplo n.º 30
0
 public void SetImage(ImageBuffer imageBuffer)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 31
0
 public TGA(ImageBuffer image)
 {
     _image = image;
 }
Ejemplo n.º 32
0
 public abstract void Process(ImageBuffer buffer);
Ejemplo n.º 33
0
 public ResponsiveImageWidget(ImageBuffer initialImage)
 {
     this.HAnchor = HAnchor.Stretch;
     this.Image   = initialImage;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Change all colors to White if not alpha 0 or set to Color.Transparent
 /// </summary>
 /// <param name="sourceImage">The source image to act on</param>
 /// <returns>A new modified image</returns>
 public static ImageBuffer AnyAlphaToColor(this ImageBuffer sourceImage, Color color)
 {
     return(AnyAlphaToColor(sourceImage, color, Color.Transparent));
 }
Ejemplo n.º 35
0
        public static void PlaceTextureOnFaces(this Mesh mesh, IEnumerable <int> faces, ImageBuffer textureToUse, Matrix4X4 textureCoordinateMapping)
        {
            var faceTextures = new Dictionary <int, FaceTextureData>();

            var uvs = new Vector2Float[3];

            foreach (var face in faces)
            {
                int uvIndex = 0;
                foreach (int vertexIndex in new int[] { mesh.Faces[face].v0, mesh.Faces[face].v1, mesh.Faces[face].v2 })
                {
                    var edgeStartPosition = mesh.Vertices[vertexIndex];
                    var textureUv         = edgeStartPosition.Transform(textureCoordinateMapping);
                    uvs[uvIndex++] = new Vector2Float(textureUv);
                }

                faceTextures.Add(face, new FaceTextureData(textureToUse, uvs[0], uvs[1], uvs[2]));
            }

            // add in any existing face textures
            if (mesh.FaceTextures != null)
            {
                foreach (var kvp in mesh.FaceTextures)
                {
                    faceTextures.Add(kvp.Key, kvp.Value);
                }
            }

            mesh.FaceTextures = faceTextures;

            mesh.MarkAsChanged();
        }
Ejemplo n.º 36
0
        public static Matrix4X4 GetMaxPlaneProjection(this Mesh mesh, IEnumerable <int> faces, ImageBuffer textureToUse, Matrix4X4?initialTransform = null)
        {
            // If not set than make it identity
            var firstTransform = initialTransform == null ? Matrix4X4.Identity : (Matrix4X4)initialTransform;

            var textureCoordinateMapping = Matrix4X4.CreateRotation(new Quaternion(mesh.Faces[faces.First()].normal.AsVector3(), Vector3.UnitZ));

            var bounds = RectangleDouble.ZeroIntersection;

            foreach (var face in faces)
            {
                foreach (int vertexIndex in new int[] { mesh.Faces[face].v0, mesh.Faces[face].v1, mesh.Faces[face].v2 })
                {
                    var edgeStartPosition = mesh.Vertices[vertexIndex];
                    var textureUv         = edgeStartPosition.Transform(textureCoordinateMapping);
                    bounds.ExpandToInclude(new Vector2(textureUv));
                }
            }

            var centering = Matrix4X4.CreateTranslation(new Vector3(-bounds.Left, -bounds.Bottom, 0));
            var scaling   = Matrix4X4.CreateScale(new Vector3(1 / bounds.Width, 1 / bounds.Height, 1));

            return(textureCoordinateMapping * firstTransform * centering * scaling);
        }
Ejemplo n.º 37
0
 public override void Process(ImageBuffer buffer)
 {
     // TODO: Implement feDisplacementMap filter Process().
     buffer[Result] = buffer[Input];
 }
Ejemplo n.º 38
0
 public static void PlaceTextureOnFace(this Mesh mesh, int face, ImageBuffer textureToUse)
 {
     //// planer project along the normal of this face
     mesh.PlaceTextureOnFace(face, textureToUse, mesh.GetMaxPlaneProjection(face, textureToUse));
 }
Ejemplo n.º 39
0
        static void CreateThumbnailsThread()
        {
            while (true)
            {
                if (listOfWidgetsNeedingThumbnails.Count > 0)
                {
                    PartThumbnailWidget thumbnailWidget = listOfWidgetsNeedingThumbnails[0];
                    if (thumbnailWidget.printItem == null)
                    {
                        thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                    }
                    else // generate the image
                    {
                        Mesh loadedMesh = StlProcessing.Load(thumbnailWidget.printItem.FileLocation);

                        thumbnailWidget.image = new ImageBuffer(thumbnailWidget.buildingThumbnailImage);
                        thumbnailWidget.Invalidate();

                        if (loadedMesh != null)
                        {
                            ImageBuffer tempImage      = new ImageBuffer(thumbnailWidget.image.Width, thumbnailWidget.image.Height, 32, new BlenderBGRA());
                            Graphics2D  partGraphics2D = tempImage.NewGraphics2D();

                            List <MeshEdge> nonManifoldEdges = loadedMesh.GetNonManifoldEdges();
                            if (nonManifoldEdges.Count > 0)
                            {
                                if (File.Exists("RunUnitTests.txt"))
                                {
                                    partGraphics2D.Circle(4, 4, 4, RGBA_Bytes.Red);
                                }
                            }

                            AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox();
                            double          maxSize     = Math.Max(aabb.XSize, aabb.YSize);
                            double          scale       = thumbnailWidget.image.Width / (maxSize * 1.2);
                            RectangleDouble bounds2D    = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                            PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh,
                                                                                 new Vector2((thumbnailWidget.image.Width / scale - bounds2D.Width) / 2 - bounds2D.Left,
                                                                                             (thumbnailWidget.image.Height / scale - bounds2D.Height) / 2 - bounds2D.Bottom),
                                                                                 scale,
                                                                                 thumbnailWidget.FillColor);

                            thumbnailWidget.image = new ImageBuffer(tempImage);
                        }
                        else
                        {
                            thumbnailWidget.image = new ImageBuffer(thumbnailWidget.noThumbnailImage);
                        }
                    }
                    thumbnailWidget.Invalidate();

                    using (TimedLock.Lock(listOfWidgetsNeedingThumbnails, "CreateThumbnailsThread()"))
                    {
                        listOfWidgetsNeedingThumbnails.RemoveAt(0);

                        foreach (PartThumbnailWidget part in listOfWidgetsNeedingThumbnails)
                        {
                            // mark them so we try to add them again if needed
                            part.thumbNailHasBeenRequested = false;
                        }

                        listOfWidgetsNeedingThumbnails.Clear();
                    }
                }
                Thread.Sleep(100);
            }
        }