コード例 #1
0
		public unsafe CairoSurfaceWrapper (Cairo.ImageSurface surface)
		{
			this.surface = surface;
			this.data_ptr = (ColorBgra*)surface.DataPtr;
			height = surface.Height;
			width = surface.Width;
		}
コード例 #2
0
ファイル: GdkExtensions.cs プロジェクト: msiyer/Pinta
        public static Gdk.Pixbuf WithAlpha (this Gdk.Pixbuf image, double opacity)
        {
            using (var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, image.Width, image.Height)) {
                using (var g = new Cairo.Context (surf)) {
                    CairoHelper.SetSourcePixbuf (g, image, 0, 0);
                    g.PaintWithAlpha (opacity);
                }

                return new Gdk.Pixbuf (surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
            }
        }
コード例 #3
0
		public StreamGeometryContextImpl(Cairo.Path path = null)
        {

			_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
			_context = new Cairo.Context (_surf);
			this.Path = path;

			if (this.Path != null) 
			{
				_context.AppendPath(this.Path);
			}
        }
コード例 #4
0
 public override object Create(object img)
 {
     Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
     var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, pb.Width, pb.Height);
     var ic = new Cairo.Context (imgs);
     Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
     ic.Paint ();
     imgs.Flush ();
     ((IDisposable)ic).Dispose ();
     var p = new Cairo.SurfacePattern (imgs);
     p.Extend = Cairo.Extend.Repeat;
     return p;
 }
コード例 #5
0
ファイル: PointPickerGraphic.cs プロジェクト: msiyer/Pinta
		private void UpdateThumbnail ()
		{
			double scalex = (double)Allocation.Width / (double)PintaCore.Workspace.ImageSize.Width;
			double scaley = (double)Allocation.Height / (double)PintaCore.Workspace.ImageSize.Height;
			
			thumbnail = new Cairo.ImageSurface (Cairo.Format.Argb32, Allocation.Width, Allocation.Height);
			
			using (Cairo.Context g = new Cairo.Context (thumbnail)) {
				g.Scale (scalex, scaley);
				foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
					layer.Draw(g);
				}
			}
		}
コード例 #6
0
ファイル: ContextBackendHandler.cs プロジェクト: chkn/xwt
 public object CreateContext(Widget w)
 {
     GtkContext ctx = new GtkContext ();
     var b = (IGtkWidgetBackend)WidgetRegistry.GetBackend (w);
     if (!b.Widget.IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (b.Widget.GdkWindow);
     }
     return ctx;
 }
コード例 #7
0
		private void Measure ()
		{
			var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
			
			using (Cairo.Context cr = new Cairo.Context(surface)) {			
				cr.SelectFontFace (FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
				cr.SetFontSize (FontSize);
			
				var textExtents = cr.TextExtents (Text);

				Width = textExtents.Width;
				Height = Math.Abs (textExtents.YBearing);		
				Extent = textExtents.Height;
			}
		}
コード例 #8
0
ファイル: TestDrawing.cs プロジェクト: bvssvni/csharp-utils
        public void TestDrawLine()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new LineShape (0.0, 0.0, 32.0, 32.0);
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/line.png");
            image.Dispose ();
        }
コード例 #9
0
ファイル: CanvasRenderer.cs プロジェクト: msiyer/Pinta
		public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
		{
			dst.Flush ();

            // Our rectangle of interest
            var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();

            using (var g = new Cairo.Context (dst)) {
                // Create the transparent checkerboard background
                g.Translate (-offset.X, -offset.Y);
                g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));

                for (var i = 0; i < layers.Count; i++) {
                    var layer = layers[i];

                    // If we're in LivePreview, substitute current layer with the preview layer
                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                        layer = CreateLivePreviewLayer (layer);

                    // If the layer is offset, handle it here
                    if (!layer.Transform.IsIdentity ())
                        layer = CreateOffsetLayer (layer);

                    // No need to resize the surface if we're at 100% zoom
                    if (scale_factor.Ratio == 1)
                        layer.Draw (g, layer.Surface, layer.Opacity, false);
                    else {
                        using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
                            g.Save ();
                            // Have to undo the translate set above
                            g.Translate (offset.X, offset.Y);
                            CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
                            layer.Draw (g, scaled, layer.Opacity, false);
                            g.Restore ();
                        }
                    }
                }
            }

            // If we are at least 200% and grid is requested, draw it
            if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
                RenderPixelGrid (dst, offset);
			
			dst.MarkDirty ();
		}
コード例 #10
0
ファイル: ContextBackendHandler.cs プロジェクト: joncham/xwt
        public object CreateContext(Widget w)
        {
            GtkContext ctx = new GtkContext();
            var        b   = (IGtkWidgetBackend)WidgetRegistry.GetBackend(w);

            if (!b.Widget.IsRealized)
            {
                Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1);
                Cairo.Context c  = new Cairo.Context(sf);
                ctx.Context     = c;
                ctx.TempSurface = sf;
            }
            else
            {
                ctx.Context = Gdk.CairoHelper.Create(b.Widget.GdkWindow);
            }
            return(ctx);
        }
コード例 #11
0
        public void XyToIndexShouldWorkCorrectly()
        {
            ITextContext context =
                new TypographyTextContext("0123456", FontFile, 36, TextAlignment.Leading);

            // prepare debug contexts
            {
                surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000);
                g       = new Cairo.Context(surface);
                g.SetSourceRGBA(1, 1, 1, 1);
                g.Paint();
                g.SetSourceRGBA(0, 0, 0, 1);
                g.LineWidth = 1;
            }

            // build path
            CairoPathBuilder cairoPathBuilder;

            cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1);
            //FIXME fix this when CairoRenderer is ready
            //context.Build(Point.Zero, cairoPathBuilder);

            bool isInside  = false;
            uint charIndex = context.XyToIndex(-1, 0, out isInside);

            Assert.False(isInside);
            Assert.Equal(0u, charIndex);

            charIndex = context.XyToIndex(13, 0, out isInside);
            Assert.True(isInside);
            Assert.Equal(0u, charIndex);

            charIndex = context.XyToIndex(37, 0, out isInside);
            Assert.True(isInside);
            Assert.Equal(1u, charIndex);

            charIndex = context.XyToIndex(64, 0, out isInside);
            Assert.True(isInside);
            Assert.Equal(2u, charIndex);

            charIndex = context.XyToIndex(89, 0, out isInside);
            Assert.True(isInside);
            Assert.Equal(3u, charIndex);
        }
コード例 #12
0
        public void ShouldGetCorrectOutline()
        {
            ITextContext textContext = new TypographyTextContext(
                "0123456", FontFile, 36,
                FontStretch.Normal, FontStyle.Normal, FontWeight.Normal,
                1000, 100,
                TextAlignment.Leading);

            // prepare debug contexts
            {
                surface = new Cairo.ImageSurface(Cairo.Format.Argb32, 2000, 2000);
                g       = new Cairo.Context(surface);
                g.SetSourceRGBA(1, 1, 1, 1);
                g.Paint();
                g.SetSourceRGBA(0, 0, 0, 1);
                g.LineWidth = 1;
            }

            // build path
            CairoPathBuilder cairoPathBuilder;
            {
                cairoPathBuilder = new CairoPathBuilder(g, 0, 0, 1);
                textContext.Build(Point.Zero, cairoPathBuilder);
            }

            // show debug results
            // image
            {
                surface.WriteToPng(PathImagePath);
                g.Dispose();

                Assert.False(PathImagePath.Contains(" "));
                // open the image in Windows Photo Viewer
                Process.Start(@"C:\WINDOWS\System32\rundll32.exe", @"""C:\Program Files\Windows Photo Viewer\PhotoViewer.dll"", ImageView_Fullscreen " + PathImagePath);
            }
            //text
            {
                var text = cairoPathBuilder.Result;
                File.WriteAllText(PathTextPath, text);
                Process.Start(@"notepad", PathTextPath);
            }

            // Now, check if the output text and image shows a right outline of the text.
        }
コード例 #13
0
ファイル: CanvasRenderer.cs プロジェクト: p07r0457/Pinta
        public void Render(Cairo.ImageSurface src, Cairo.ImageSurface dst, Gdk.Point offset, bool checker)
        {
            dst.Flush();

            if (scale_factor.Ratio == 1)
            {
                RenderOneToOne(src, dst, offset, checker);
            }
            else if (scale_factor.Ratio < 1)
            {
                RenderZoomIn(src, dst, offset, checker);
            }
            else
            {
                RenderZoomOut(src, dst, offset, destination_size, checker);
            }

            dst.MarkDirty();
        }
コード例 #14
0
        Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
        {
            var swidth  = Math.Max((int)(width * scaleFactor), 1);
            var sheight = Math.Max((int)(height * scaleFactor), 1);

            using (var sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, swidth, sheight))
                using (var ctx = new Cairo.Context(sf)) {
                    ImageDescription idesc = new ImageDescription()
                    {
                        Alpha = 1,
                        Size  = new Size(width, height)
                    };
                    ctx.Scale(scaleFactor, scaleFactor);
                    Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                    var f = new ImageFrame(ImageBuilderBackend.CreatePixbuf(sf), Math.Max((int)width, 1), Math.Max((int)height, 1), true);
                    AddFrame(f);
                    return(f.Pixbuf);
                }
        }
コード例 #15
0
ファイル: CanvasRenderer.cs プロジェクト: casey0102/Pinta
        public void Render(List <Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
        {
            dst.Flush();

            if (scale_factor.Ratio == 1)
            {
                RenderOneToOne(layers, dst, offset);
            }
            else if (scale_factor.Ratio < 1)
            {
                RenderZoomIn(layers, dst, offset);
            }
            else
            {
                RenderZoomOut(layers, dst, offset, destination_size);
            }

            dst.MarkDirty();
        }
コード例 #16
0
ファイル: LayersListWidget.cs プロジェクト: ywscr/Pinta
        public void Reset()
        {
            store.Clear();

            if (active_layer_surface != null)
            {
                (active_layer_surface as IDisposable).Dispose();
                active_layer_surface = null;
            }

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return;
            }

            var doc = PintaCore.Workspace.ActiveDocument;

            foreach (var layer in (doc.UserLayers as IEnumerable <Layer>).Reverse())
            {
                var surf = layer.Surface;

                // Draw the selection layer on top of the active layer.
                if (layer == doc.CurrentUserLayer && doc.ShowSelectionLayer)
                {
                    active_layer_surface = new Cairo.ImageSurface(Cairo.Format.Argb32, thumbnail_width,
                                                                  thumbnail_height);
                    canvas_renderer.Initialize(doc.ImageSize,
                                               new Gdk.Size(thumbnail_width, thumbnail_height));

                    var layers = new List <Layer> {
                        layer, doc.SelectionLayer
                    };
                    canvas_renderer.Render(layers, active_layer_surface, Gdk.Point.Zero);

                    surf = active_layer_surface;
                }

                store.AppendValues(surf, layer.Name, !layer.Hidden, layer);
            }

            SelectLayerInTreeView(PintaCore.Layers.Count - PintaCore.Layers.CurrentLayerIndex - 1);
        }
コード例 #17
0
        public CairoContextBackend CreateContext()
        {
            CairoContextBackend ctx = new CairoContextBackend(Util.GetScaleFactor(this));

            if (!IsRealized)
            {
                Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1);
                ctx.Context     = new Cairo.Context(sf);
                ctx.TempSurface = sf;
            }
            else
            {
                ctx.Context = Gdk.CairoHelper.Create(GdkWindow);
            }
            if (!VisibleWindow)
            {
                ctx.Context.Translate(Allocation.X, Allocation.Y);
            }
            return(ctx);
        }
コード例 #18
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                ReverseAll();
            }
            if (image != null)
            {
                Flush(false);
                image = null;
            }
            if (surface != null)
            {
                // Analysis disable once RedundantCast - backward compatibility
                ((IDisposable)surface).Dispose();
                surface = null;
            }

            base.Dispose(disposing);
        }
コード例 #19
0
        private void StartEditing()
        {
            is_editing = true;

            if (selection == null)
            {
                selection = PintaCore.Workspace.ActiveDocument.Selection.Clone();
            }

            //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop).
            ignoreCloneFinalizations = true;

            //Store the previous state of the current UserLayer's and TextLayer's ImageSurfaces.
            user_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface.Clone();
            text_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface.Clone();
            undo_engine       = CurrentTextEngine.Clone();

            //Stop ignoring any Surface.Clone calls from this point on.
            ignoreCloneFinalizations = false;
        }
コード例 #20
0
        internal void Start(BaseEffect effect,
                            Cairo.ImageSurface source,
                            Cairo.ImageSurface dest,
                            Gdk.Rectangle renderBounds)
        {
            Debug.WriteLine("AsyncEffectRenderer.Start ()");

            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }

            // It is important the effect's properties don't change during rendering.
            // So a copy is made for the render.
            this.effect = effect.Clone();

            this.source_surface = source;
            this.dest_surface   = dest;
            this.render_bounds  = renderBounds;

            // If a render is already in progress, then cancel it,
            // and start a new render.
            if (IsRendering)
            {
                cancel_render_flag  = true;
                restart_render_flag = true;
                return;
            }

            StartRender();
        }
コード例 #21
0
        private static void MakeReflection(Cairo.Context context, Cairo.ImageSurface source, int w, int h)
        {
            context.ResetClip();
            context.SetSourceSurface(source, 2, 2);
            context.Paint();

            double alpha = -0.3;
            double step  = 1.0 / (double)source.Height;

            context.Translate(0, h);
            context.Scale(1, -1);
            context.SetSourceSurface(source, 2, 2);
            for (int i = 0; i < source.Height; i++)
            {
                context.Rectangle(0, i + 2, w, 1);
                context.Clip();
                alpha += step;
                context.PaintWithAlpha(Math.Max(Math.Min(alpha, 0.7), 0.0));
                context.ResetClip();
            }
        }
コード例 #22
0
ファイル: TestDrawing.cs プロジェクト: bvssvni/csharp-utils
        public void TestDrawRectangle()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new RectangleShape ();
            shape.Rectangle = new Rectangle () {
                X = 10.0,
                Y = 10.0,
                Width = 12.0,
                Height = 12.0
            };
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/rectangle.png");
            image.Dispose ();
        }
コード例 #23
0
ファイル: PixelSet.cs プロジェクト: bpatterson-gh/ArtSCII
 /// <summary>
 /// PixelSet Constructor
 /// </summary>
 /// <param name="bmp">ImageSurface to copy</param>
 public PixelSet(ImageSurface img)
 {
     Width  = (uint)img.Width;
     Height = (uint)img.Height;
     byte[] data = img.Data;
     pixels = new byte[3, Width][];
     for (uint x = 0; x < Width; x++)
     {
         pixels[0, x] = new byte[Height];
         pixels[1, x] = new byte[Height];
         pixels[2, x] = new byte[Height];
         for (uint y = 0; y < Height; y++)
         {
             uint  i     = (x + (Width * y)) * 4;
             float alpha = data[i + 3] / 255.0f;
             pixels[0, x][y] = (byte)(data[i] * alpha);
             pixels[1, x][y] = (byte)(data[i + 1] * alpha);
             pixels[2, x][y] = (byte)(data[i + 2] * alpha);
         }
     }
 }
コード例 #24
0
ファイル: GraphicsHandler.cs プロジェクト: pcdummy/Eto
        public void CreateFromImage(Bitmap image)
        {
            this.image = image;
            var handler = (BitmapHandler)image.Handler;

            if (handler.Alpha)
            {
                surface = new Cairo.ImageSurface(Cairo.Format.Argb32, image.Size.Width, image.Size.Height);
            }
            else
            {
                surface = new Cairo.ImageSurface(Cairo.Format.Rgb24, image.Size.Width, image.Size.Height);
            }
            Control = new Cairo.Context(surface);
            Control.Save();
            Control.Rectangle(0, 0, image.Size.Width, image.Size.Height);
            Gdk.CairoHelper.SetSourcePixbuf(Control, handler.Control, 0, 0);
            Control.Operator = Cairo.Operator.Source;
            Control.Fill();
            Control.Restore();
        }
コード例 #25
0
        private unsafe void CopyScaledZoomIn(Cairo.ImageSurface src, Cairo.ImageSurface dst, Rectangle roi)
        {
            // Tell Cairo we need the latest raw data
            dst.Flush();

            EnsureLookupTablesCreated();

            // Cache pointers to surface raw data
            var src_ptr = (ColorBgra *)src.DataPtr;
            var dst_ptr = (ColorBgra *)dst.DataPtr;

            // Cache surface sizes
            var src_width  = src.Width;
            var dst_width  = dst.Width;
            var dst_height = dst.Height;

            for (var dst_row = 0; dst_row < dst_height; ++dst_row)
            {
                // For each dest row, look up the src row to copy from
                var nnY  = dst_row + roi.Y;
                var srcY = d2sLookupY[nnY];

                // Get pointers to src and dest rows
                var dst_row_ptr = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dst_row);
                var src_row_ptr = src.GetRowAddressUnchecked(src_ptr, src_width, srcY);

                for (var dstCol = 0; dstCol < dst_width; ++dstCol)
                {
                    // Look up the src column to copy from
                    var nnX  = dstCol + roi.X;
                    var srcX = d2sLookupX[nnX];

                    // Copy source to destination
                    *dst_row_ptr++ = *(src_row_ptr + srcX);
                }
            }

            // Tell Cairo we changed the raw data
            dst.MarkDirty();
        }
コード例 #26
0
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor) {
         if (pattern != null)
             pattern.Dispose ();
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor));
         var ic = new Cairo.Context (imgs);
         ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
         Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
         ic.Paint ();
         imgs.Flush ();
         ((IDisposable)ic).Dispose ();
         pattern = new Cairo.SurfacePattern (imgs);
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix ();
         cm.Scale (scaleFactor, scaleFactor);
         pattern.Matrix = cm;
         currentScaleFactor = scaleFactor;
     }
     return pattern;
 }
コード例 #27
0
ファイル: WidgetGL.cs プロジェクト: codyn-net/plot-sharp
        private void Reconfigure()
        {
            if (!d_isrealized)
            {
                return;
            }

            GLDo(false, () => {
                if (!InitGl(Allocation.Width, Allocation.Height))
                {
                    return;
                }

                Cleanup();

                Gl.glMatrixMode(Gl.GL_PROJECTION);
                Gl.glOrtho(0, 1, 0, 1, -1, 1);
                Gl.glViewport(0, 0, Allocation.Width, Allocation.Height);

                // Generate cairo image to render into
                d_surface = new Cairo.ImageSurface(Cairo.Format.ARGB32,
                                                   Allocation.Width,
                                                   Allocation.Height);

                // Generate texture to hold the image data
                Gl.glGenTextures(1, out d_texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_RECTANGLE_ARB, d_texture);
                Gl.glTexImage2D(Gl.GL_TEXTURE_RECTANGLE_ARB,
                                0,
                                Gl.GL_RGBA,
                                Allocation.Width,
                                Allocation.Height,
                                0,
                                Gl.GL_BGRA,
                                Gl.GL_UNSIGNED_BYTE,
                                null);
            });
        }
コード例 #28
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            const int width  = 1200;
            const int height = 800;

            using (var bitmap = new SKBitmap(width, height, SKColorType.Rgb888x, SKAlphaType.Premul))
            {
                IntPtr len;
                using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, SKColorType.Rgb888x, SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes))
                {
                    var canvas = skSurface.Canvas;
                    canvas.Clear(SKColors.White);

                    using (var paint = new SKPaint())
                    {
                        paint.TextSize = 80;

                        canvas.DrawText("Good Luck Dale!  :-)", new SKPoint()
                        {
                            X = 100, Y = 100
                        }, paint);
                    }

                    Cairo.Surface surface = new Cairo.ImageSurface(
                        bitmap.GetPixels(out len),
                        Cairo.Format.Argb32,
                        bitmap.Width, bitmap.Height,
                        bitmap.Width * 4);


                    surface.MarkDirty();
                    cr.SetSourceSurface(surface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
コード例 #29
0
        // Clean up resources when live preview is disabled.
        void CleanUp()
        {
            Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss:ffff") + " LivePreviewManager.CleanUp()");

            live_preview_enabled = false;

            if (effect != null)
            {
                if (effect.EffectData != null)
                {
                    effect.EffectData.PropertyChanged -= EffectData_PropertyChanged;
                }
                effect = null !;
            }

            live_preview_surface?.Dispose();
            live_preview_surface = null !;

            if (renderer != null)
            {
                renderer.Dispose();
                renderer = null !;
            }

            if (history_item != null)
            {
                history_item.Dispose();
                history_item = null !;
            }

            // Hide progress dialog and clean up events.
            var dialog = PintaCore.Chrome.ProgressDialog;

            dialog.Hide();
            dialog.Canceled -= HandleProgressDialogCancel;

            PintaCore.Chrome.MainWindowBusy = false;
        }
コード例 #30
0
ファイル: Document.cs プロジェクト: alvinc-git/pdfmod
        public PageThumbnail GetSurface(Page page, int w, int h, int min_width)
        {
            if (w < min_width || h < min_width)
            {
                return(null);
            }

            using (var ppage = PopplerDoc.GetPage(page.Index)) {
                double pw, ph;
                ppage.GetSize(out pw, out ph);
                double scale = Math.Min(w / pw, h / ph);

                var surface = new Cairo.ImageSurface(Cairo.Format.Argb32, (int)(scale * pw), (int)(scale * ph));
                var cr      = new Cairo.Context(surface);
                cr.Scale(scale, scale);
                ppage.Render(cr);
                page.SurfaceDirty = false;
                return(new PageThumbnail()
                {
                    Surface = surface, Context = cr
                });
            }
        }
コード例 #31
0
ファイル: BinaryPixelOp.cs プロジェクト: p07r0457/Pinta
        public void Apply(Cairo.ImageSurface dst, Cairo.ImageSurface lhs, Cairo.ImageSurface rhs)
        {
            if (dst.GetSize() != lhs.GetSize())
            {
                throw new ArgumentException("dst.Size != lhs.Size");
            }

            if (lhs.GetSize() != rhs.GetSize())
            {
                throw new ArgumentException("lhs.Size != rhs.Size");
            }

            unsafe {
                for (int y = 0; y < dst.Height; ++y)
                {
                    ColorBgra *dstPtr = dst.GetRowAddressUnchecked(y);
                    ColorBgra *lhsPtr = lhs.GetRowAddressUnchecked(y);
                    ColorBgra *rhsPtr = rhs.GetRowAddressUnchecked(y);

                    Apply(dstPtr, lhsPtr, rhsPtr, dst.Width);
                }
            }
        }
コード例 #32
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            const int width  = 100;
            const int height = 100;

            using (var bitmap = new SKBitmap(width, height, SKColorType.N_32, SKAlphaType.Premul))
            {
                IntPtr len;
                using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, SKColorType.N_32, SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes))
                {
                    var canvas = skSurface.Canvas;
                    canvas.Clear(SKColors.White);

                    using (var paint = new SKPaint())
                    {
                        paint.StrokeWidth = 4;
                        paint.Color       = new SKColor(0x2c, 0x3e, 0x50);

                        var rect = new SKRect(10, 10, 50, 50);
                        canvas.DrawRect(rect, paint);
                    }

                    Cairo.Surface surface = new Cairo.ImageSurface(
                        bitmap.GetPixels(out len),
                        Cairo.Format.Argb32,
                        bitmap.Width, bitmap.Height,
                        bitmap.Width * 4);


                    surface.MarkDirty();
                    cr.SetSourceSurface(surface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
コード例 #33
0
ファイル: UnoDrawingArea.cs プロジェクト: ediboko1980/uno
        protected override bool OnDrawn(Cairo.Context cr)
        {
            int width, height;

            Console.WriteLine($"Render {renderCount++}");

            width  = (int)AllocatedWidth;
            height = (int)AllocatedHeight;

            var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            // reset the bitmap if the size has changed
            if (bitmap == null || info.Width != bitmap.Width || info.Height != bitmap.Height)
            {
                bitmap = new SKBitmap(width, height, SKColorType.Rgba8888, SKAlphaType.Premul);
            }

            using (var surface = SKSurface.Create(info, bitmap.GetPixels(out var len)))
            {
                surface.Canvas.Clear(SKColors.White);

                WUX.Window.Current.Compositor.Render(surface, info);

                using (var gtkSurface = new Cairo.ImageSurface(
                           bitmap.GetPixels(out _),
                           Cairo.Format.Argb32,
                           bitmap.Width, bitmap.Height,
                           bitmap.Width * 4))
                {
                    gtkSurface.MarkDirty();
                    cr.SetSourceSurface(gtkSurface, 0, 0);
                    cr.Paint();
                }
            }

            return(true);
        }
コード例 #34
0
ファイル: ResourceManager.cs プロジェクト: mfcallahan/Pinta
        // From MonoDevelop:
        // https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Ide/gtk-gui/generated.cs
        private static Pixbuf CreateMissingImage(int size)
        {
            using (var surf = new Cairo.ImageSurface(Cairo.Format.Argb32, size, size))
                using (var g = new Cairo.Context(surf)) {
                    g.SetSourceColor(new Cairo.Color(1, 1, 1));
                    g.Rectangle(0, 0, size, size);
                    g.Fill();

                    g.SetSourceColor(new Cairo.Color(0, 0, 0));
                    g.Rectangle(0, 0, size - 1, size - 1);
                    g.Fill();

                    g.LineWidth = 3;
                    g.LineCap   = Cairo.LineCap.Round;
                    g.LineJoin  = Cairo.LineJoin.Round;
                    g.SetSourceColor(new Cairo.Color(1, 0, 0));
                    g.MoveTo(size / 4, size / 4);
                    g.LineTo((size - 1) - (size / 4), (size - 1) - (size / 4));
                    g.MoveTo((size - 1) - (size / 4), size / 4);
                    g.LineTo(size / 4, (size - 1) - (size / 4));

                    return(new Pixbuf(surf, 0, 0, surf.Width, surf.Height));
                }
        }
コード例 #35
0
        /// <summary>
        /// Copy image data to the layer's surface.
        /// </summary>
        /// <param name="image_data">Array of image data in RGBA format.</param>
        private static unsafe void CopyToSurface(byte[] image_data, Cairo.ImageSurface surf)
        {
            if (image_data.Length != surf.Data.Length)
            {
                throw new ArgumentException("Mismatched image sizes");
            }

            surf.Flush();

            ColorBgra *dst = (ColorBgra *)surf.DataPtr;
            int        len = image_data.Length / ColorBgra.SizeOf;

            fixed(byte *src_bytes = image_data)
            {
                ColorBgra *src = (ColorBgra *)src_bytes;

                for (int i = 0; i < len; ++i)
                {
                    *dst++ = *src++;
                }
            }

            surf.MarkDirty();
        }
コード例 #36
0
ファイル: CanvasBackend.cs プロジェクト: dellis1972/xwt
 public CairoContextBackend CreateContext()
 {
     CairoContextBackend ctx = new CairoContextBackend ();
     if (!IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (GdkWindow);
     }
     return ctx;
 }
コード例 #37
0
ファイル: DftUtil.cs プロジェクト: MagistrTot/DGLE
        public Gdk.Pixbuf BuildImage(FontService fontService)
        {
            Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
            Cairo.Context ctx = new Cairo.Context (image);

            Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx);
            fontService.AssignLayout (layout);

            // fill background
            ctx.Save ();
            ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
            ctx.Paint ();
            ctx.Restore ();

            int charCode = 0;
            int maxHeight = 0;
            Cairo.Point pos = new Cairo.Point (PADDING, PADDING);
            while ((!fontService.OnlyEnglish && charCode < 224) ||
                   (fontService.OnlyEnglish && charCode < (224 - 66))) {

                layout.SetText (alphabet[charCode].ToString());

                Pango.Rectangle te = GetTextExtents (layout, pos);

                // next line
                if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) {
                    pos.X = PADDING;
                    pos.Y = te.Y + maxHeight + PADDING;
                }
                te = DrawText (ctx, layout, pos);
                boxes[charCode] = te;

                pos.X = te.X + te.Width + fontService.Spacing + PADDING;
                maxHeight = Math.Max (maxHeight, te.Height);

                charCode++;
            }

            int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);
            Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (
                image.Data, true, 8,
                image.Width,
                cropHeight,
                image.Stride);

            // manual dispose
            (image as IDisposable).Dispose ();
            (layout as IDisposable).Dispose ();
            (ctx.Target as IDisposable).Dispose ();
            (ctx as IDisposable).Dispose ();

            return pixbuf;
        }
コード例 #38
0
ファイル: LivePreviewManager.cs プロジェクト: ericksson/Pinta
		// Clean up resources when live preview is disabled.
		void CleanUp ()
		{
			Debug.WriteLine (DateTime.Now.ToString("HH:mm:ss:ffff") + " LivePreviewManager.CleanUp()");
			
			live_preview_enabled = false;
			
			if (effect != null) {
				if (effect.EffectData != null)
					effect.EffectData.PropertyChanged -= EffectData_PropertyChanged;
				effect = null;
			}
							
			live_preview_surface = null;
			
			if (renderer != null) {
				renderer.Dispose ();
				renderer = null;
			}

			if (history_item != null) {
				history_item.Dispose ();
				history_item = null;
			}
			
			// Hide progress dialog and clean up events.
			var dialog = PintaCore.Chrome.ProgressDialog;
			dialog.Hide ();
			dialog.Canceled -= HandleProgressDialogCancel;
			
			PintaCore.Chrome.MainWindowBusy = false;
		}
コード例 #39
0
ファイル: GdkExtensions.cs プロジェクト: msiyer/Pinta
        public static Cairo.Surface ToSurface (this Pixbuf pixbuf)
        {
            var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, pixbuf.Width, pixbuf.Height);

            using (var g = new Cairo.Context (surface)) {
                Gdk.CairoHelper.SetSourcePixbuf (g, pixbuf, 0, 0);
                g.Paint ();
            }

            return surface;
        }
コード例 #40
0
 public override object CreatePath()
 {
     Cairo.Surface sf = new Cairo.ImageSurface (null, Cairo.Format.A1, 0, 0, 0);
     return new CairoContextBackend (1) { // scale doesn't matter here, we are going to use it only for creating a path
         TempSurface = sf,
         Context = new Cairo.Context (sf)
     };
 }
コード例 #41
0
ファイル: PintaCanvas.cs プロジェクト: rini18/Pinta
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent (e);

            if (!PintaCore.Workspace.HasOpenDocuments)
                return true;

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);
            canvas_bounds.Intersect (e.Area);

            if (canvas_bounds.IsEmpty)
                return true;

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height) {
                if (canvas != null)
                    (canvas as IDisposable).Dispose ();

                canvas = new Cairo.ImageSurface (Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize (PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create (GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color (.5, .5, .5), 1);
                g.DrawRectangle (new Cairo.Rectangle (x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color (.8, .8, .8), 1);
                g.DrawRectangle (new Cairo.Rectangle (x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color (.9, .9, .9), 1);

                // Set up our clip rectangle
                g.Rectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip ();

                g.Translate (x, y);

                // Render all the layers to a surface
                var layers = PintaCore.Layers.GetLayersToPaint ();
                if (layers.Count == 0) {
                    canvas.Clear ();
                }
                cr.Render (layers, canvas, canvas_bounds.Location);

                // Paint the surface to our canvas
                g.SetSourceSurface (canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
                g.Paint ();

                // Selection outline
                if (PintaCore.Layers.ShowSelection) {
                    g.Save ();
                    g.Translate (0.5, 0.5);
                    g.Scale (scale, scale);

                    g.AppendPath (PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains ("Select") && !PintaCore.Tools.CurrentTool.Name.Contains ("Selected")) {
                        g.Color = new Cairo.Color (0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve ();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color (1, 1, 1);
                    g.StrokePreserve ();

                    // Draw a black dashed line over the white line
                    g.SetDash (new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color (0, 0, 0);

                    g.Stroke ();
                    g.Restore ();
                }
            }

            return true;
        }
コード例 #42
0
		internal AsyncEffectRenderer (Settings settings)
		{
			if (settings.ThreadCount < 1)
				settings.ThreadCount = 1;
			
			if (settings.TileWidth < 1)
				throw new ArgumentException ("EffectRenderSettings.TileWidth");
			
			if (settings.TileHeight < 1)
				throw new ArgumentException ("EffectRenderSettings.TileHeight");			
			
			if (settings.UpdateMillis <= 0)
				settings.UpdateMillis = 100;
			
			effect = null;
			source_surface = null;
			dest_surface = null;
			this.settings = settings;
			
			is_rendering = false;
			render_id = 0;
			updated_lock = new object ();
			is_updated = false;
			render_exceptions = new List<Exception> ();	
			
			timer_tick_id = 0;
		}		
コード例 #43
0
		internal void Start (BaseEffect effect,
		                     Cairo.ImageSurface source,
		                     Cairo.ImageSurface dest,
		                     Gdk.Rectangle renderBounds)
		{
			Debug.WriteLine ("AsyncEffectRenderer.Start ()");
			
			if (effect == null)
				throw new ArgumentNullException ("effect");
			
			if (source == null)
				throw new ArgumentNullException ("source");
			
			if (dest == null)
				throw new ArgumentNullException ("dest");
			
			if (renderBounds.IsEmpty)
				throw new ArgumentException ("renderBounds.IsEmpty");
			
			// It is important the effect's properties don't change during rendering.
			// So a copy is made for the render.
			this.effect = effect.Clone();
			
			this.source_surface = source;
			this.dest_surface = dest;
			this.render_bounds = renderBounds;
			
			// If a render is already in progress, then cancel it,
			// and start a new render.
			if (IsRendering) {
				cancel_render_flag = true;
				restart_render_flag = true;
				return;
			}
			
			StartRender ();
		}
コード例 #44
0
		Cairo.Context Playback ()
		{
			using (var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 10, 10))
			{
				var context = new Cairo.Context(surface);
				Apply(context);
				return context;
			}
		}
コード例 #45
0
ファイル: PointPickerGraphic.cs プロジェクト: msiyer/Pinta
		protected override void OnSizeRequested (ref Gtk.Requisition requisition)
		{
			// Always be X pixels tall, but maintain aspect ratio
			Size imagesize = PintaCore.Workspace.ImageSize;
			
			requisition.Height = 65;
			requisition.Width = (imagesize.Width * requisition.Height) / imagesize.Height;
			thumbnail = null;
		}
コード例 #46
0
ファイル: ImageHandler.cs プロジェクト: StEvUgnIn/xwt
		Gdk.Pixbuf RenderFrame (ApplicationContext actx, double scaleFactor, double width, double height)
		{
			var swidth = Math.Max ((int)(width * scaleFactor), 1);
			var sheight = Math.Max ((int)(height * scaleFactor), 1);

			using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, swidth, sheight))
			using (var ctx = new Cairo.Context (sf)) {
				ImageDescription idesc = new ImageDescription () {
					Alpha = 1,
					Size = new Size (width, height)
				};
				ctx.Scale (scaleFactor, scaleFactor);
				Draw (actx, ctx, scaleFactor, 0, 0, idesc);
				var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), Math.Max((int)width,1), Math.Max((int)height,1), true);
				AddFrame (f);
				return f.Pixbuf;
			}
		}
コード例 #47
0
ファイル: ImageHandler.cs プロジェクト: neiz/xwt
 Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
 {
     using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(width * scaleFactor), (int)(height * scaleFactor)))
     using (var ctx = new Cairo.Context (sf)) {
         ImageDescription idesc = new ImageDescription () {
             Alpha = 1,
             Size = new Size (width * scaleFactor, height * scaleFactor)
         };
         Draw (actx, ctx, 1, 0, 0, idesc);
         var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), (int)width, (int)height);
         AddFrame (f);
         return f.Pixbuf;
     }
 }
コード例 #48
0
 static GtkTextLayoutBackendHandler()
 {
     using (Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1)) {
         SharedContext = new Cairo.Context(sf);
     }
 }
コード例 #49
0
		public void Start (BaseEffect effect)
		{			
			if (live_preview_enabled)
				throw new InvalidOperationException ("LivePreviewManager.Start() called while live preview is already enabled.");
			
			// Create live preview surface.
			// Start rendering.
			// Listen for changes to effectConfiguration object, and restart render if needed.
			
			live_preview_enabled = true;
			apply_live_preview_flag = false;
			cancel_live_preview_flag = false;
			
			layer = PintaCore.Layers.CurrentLayer;
			this.effect = effect;
			
			// Handle selection path.
			PintaCore.Tools.Commit ();
			selection_path = (PintaCore.Layers.ShowSelection) ? PintaCore.Layers.SelectionPath : null;
			render_bounds = selection_path.GetBounds ();
			render_bounds = PintaCore.Workspace.ClampToImageSize (render_bounds);			
									
			//TODO Use the current tool layer instead.
			live_preview_surface = new Cairo.ImageSurface (Cairo.Format.Argb32,
			                                  PintaCore.Workspace.ImageSize.Width,
			                                  PintaCore.Workspace.ImageSize.Height);
			
			// Paint the pre-effect layer surface into into the working surface.
			using (var ctx = new Cairo.Context (live_preview_surface)) {
				ctx.SetSourceSurface (layer.Surface, (int) layer.Offset.X, (int) layer.Offset.Y);
				ctx.Paint ();
			}
			
			if (effect.EffectData != null)
				effect.EffectData.PropertyChanged += EffectData_PropertyChanged;
			
			if (Started != null) {
				Started (this, new LivePreviewStartedEventArgs());
			}
			
			var settings = new AsyncEffectRenderer.Settings () {
				ThreadCount = PintaCore.System.RenderThreads,
				TileWidth = render_bounds.Width,
				TileHeight = 1,
				ThreadPriority = ThreadPriority.BelowNormal
			};
			
			Debug.WriteLine (DateTime.Now.ToString("HH:mm:ss:ffff") + "Start Live preview.");
			
			renderer = new Renderer (this, settings);
			renderer.Start (effect, layer.Surface, live_preview_surface, render_bounds);
			
			if (effect.IsConfigurable) {		
				if (!effect.LaunchConfiguration ()) {
					PintaCore.Chrome.MainWindowBusy = true;
					Cancel ();
				} else {
					PintaCore.Chrome.MainWindowBusy = true;
					Apply ();
				}
			} else {
				PintaCore.Chrome.MainWindowBusy = true;
				Apply ();
			}
		}
コード例 #50
0
ファイル: LayersListWidget.cs プロジェクト: ericksson/Pinta
        public void Reset()
        {
            store.Clear ();

            if (active_layer_surface != null) {
                active_layer_surface.Dispose ();
                active_layer_surface = null;
            }

            if (!PintaCore.Workspace.HasOpenDocuments)
                return;

            var doc = PintaCore.Workspace.ActiveDocument;

            foreach (var layer in (doc.UserLayers as IEnumerable<Layer>).Reverse ()) {
                var surf = layer.Surface;

                // Draw the selection layer on top of the active layer.
                if (layer == doc.CurrentUserLayer && doc.ShowSelectionLayer) {
                    active_layer_surface = new Cairo.ImageSurface (Cairo.Format.Argb32, thumbnail_width,
                                                                   thumbnail_height);
                    canvas_renderer.Initialize (doc.ImageSize,
                                                new Gdk.Size (thumbnail_width, thumbnail_height));

                    var layers = new List<Layer> { layer, doc.SelectionLayer };
                    canvas_renderer.Render (layers, active_layer_surface, Gdk.Point.Zero);

                    surf = active_layer_surface;
                }

                store.AppendValues (surf, layer.Name, !layer.Hidden, layer);
            }

            SelectLayerInTreeView (PintaCore.Layers.Count - PintaCore.Layers.CurrentLayerIndex - 1);
        }
コード例 #51
0
ファイル: PintaCanvas.cs プロジェクト: jonnyro/Pinta
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent (e);

            if (!PintaCore.Workspace.HasOpenDocuments)
                return true;

            double scale = PintaCore.Workspace.Scale;

            int x = (int)PintaCore.Workspace.Offset.X;
            int y = (int)PintaCore.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            Rectangle canvas_bounds = new Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);
            canvas_bounds.Intersect (e.Area);

            if (canvas_bounds.IsEmpty)
                return true;

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height) {
                if (canvas != null)
                    (canvas as IDisposable).Dispose ();

                canvas = new Cairo.ImageSurface (Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize (PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);

            using (Cairo.Context g = CairoHelper.Create (GdkWindow)) {
                // Draw our 1 px black border
                g.DrawRectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color (0, 0, 0), 1);

                // Set up our clip rectangle
                g.Rectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
                g.Clip ();

                g.Translate (x, y);

                bool checker = true;

                // Resize each layer and paint it to the screen
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
                    cr.Render (layer.Surface, canvas, canvas_bounds.Location, checker);
                    g.SetSourceSurface (canvas, canvas_bounds.X + (int)(layer.Offset.X * scale), canvas_bounds.Y + (int)(layer.Offset.Y * scale));
                    g.PaintWithAlpha (layer.Opacity);

                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled) {
                        cr.Render (PintaCore.LivePreview.LivePreviewSurface, canvas, canvas_bounds.Location, checker);

                        g.Save ();
                        g.Scale (scale, scale);
                        g.AppendPath (PintaCore.Layers.SelectionPath);
                        g.Clip ();

                        g.Scale (1 / scale, 1 / scale);
                        g.SetSourceSurface (canvas, canvas_bounds.X, canvas_bounds.Y);
                        g.PaintWithAlpha (layer.Opacity);

                        g.Restore ();
                    }

                    checker = false;
                }

                // If we are at least 200% and grid is requested, draw it
                if (PintaCore.Actions.View.PixelGrid.Active && cr.ScaleFactor.Ratio <= 0.5d) {
                    gr.Render (canvas, canvas_bounds.Location);
                    g.SetSourceSurface (canvas, canvas_bounds.X, canvas_bounds.Y);
                    g.Paint ();
                }

                // Selection outline
                if (PintaCore.Layers.ShowSelection) {
                    g.Save ();
                    g.Translate (0.5, 0.5);
                    g.Scale (scale, scale);

                    g.AppendPath (PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains ("Select") && !PintaCore.Tools.CurrentTool.Name.Contains ("Selected")) {
                        g.Color = new Cairo.Color (0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve ();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color (1, 1, 1);
                    g.StrokePreserve ();

                    // Draw a black dashed line over the white line
                    g.SetDash (new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color (0, 0, 0);

                    g.Stroke ();
                    g.Restore ();
                }
            }

            return true;
        }
コード例 #52
0
ファイル: TextTool.cs プロジェクト: xxgreg/Pinta
        private void DrawText(Cairo.ImageSurface dst, string textFont, string text, Point pt, Size measuredSize, bool antiAliasing, Cairo.Color color)
        {
            Rectangle dstRect = new Rectangle (pt, measuredSize);
            //Rectangle dstRectClipped = Rectangle.Intersect(dstRect, ScratchSurface.Bounds);
                        /*
            if (dstRectClipped.Width == 0 || dstRectClipped.Height == 0)
            {
                return;
            }
             */
            using (Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.Argb32, 8, 8)) {
                using (Cairo.Context context = new Cairo.Context (surface)) {
                    context.FillRectangle (new Cairo.Rectangle (0, 0, surface.Width, surface.Height), color);
                }

                DrawText (dst, textFont, text, pt, measuredSize, antiAliasing, surface);
            }
        }
コード例 #53
0
ファイル: BinaryPixelOp.cs プロジェクト: p07r0457/Pinta
 public override void Apply(Cairo.ImageSurface dst, Point dstOffset, Cairo.ImageSurface src, Point srcOffset, int roiLength)
 {
     Apply(dst.GetPointAddress(dstOffset), src.GetPointAddress(srcOffset), roiLength);
 }
コード例 #54
0
 static GtkTextLayoutBackendHandler()
 {
     using (Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1)) {
         SharedContext = new Cairo.Context (sf);
     }
 }
コード例 #55
0
ファイル: CanvasBackend.cs プロジェクト: nirenyang/xwt
 public CairoContextBackend CreateContext()
 {
     CairoContextBackend ctx = new CairoContextBackend (Util.GetScaleFactor (this));
     if (!IsRealized) {
         Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
         Cairo.Context c = new Cairo.Context (sf);
         ctx.Context = c;
         ctx.TempSurface = sf;
     } else {
         ctx.Context = Gdk.CairoHelper.Create (GdkWindow);
     }
     if (!VisibleWindow) {
         ctx.Context.Translate (Allocation.X, Allocation.Y);
         // Set ContextBackend Origin
         ctx.Origin.X = Allocation.X;
         ctx.Origin.Y = Allocation.Y;
     }
     return ctx;
 }
コード例 #56
0
 public StreamGeometryContextImpl(StreamGeometryImpl imp)
 {
     _impl    = imp;
     _surf    = new Cairo.ImageSurface(Cairo.Format.Argb32, 0, 0);
     _context = new Cairo.Context(_surf);
 }
コード例 #57
0
ファイル: LivePreviewManager.cs プロジェクト: ericksson/Pinta
		public void Start (BaseEffect effect)
		{			
			if (live_preview_enabled)
				throw new InvalidOperationException ("LivePreviewManager.Start() called while live preview is already enabled.");
			
			// Create live preview surface.
			// Start rendering.
			// Listen for changes to effectConfiguration object, and restart render if needed.

			live_preview_enabled = true;
			apply_live_preview_flag = false;
			cancel_live_preview_flag = false;
			
			layer = PintaCore.Layers.CurrentLayer;
			this.effect = effect;

			//TODO Use the current tool layer instead.
			live_preview_surface = new Cairo.ImageSurface (Cairo.Format.Argb32,
			                                  PintaCore.Workspace.ImageSize.Width,
			                                  PintaCore.Workspace.ImageSize.Height);

			// Handle selection path.
			PintaCore.Tools.Commit ();
			selection_path = (PintaCore.Layers.ShowSelection) ? PintaCore.Workspace.ActiveDocument.Selection.SelectionPath : null;
			render_bounds = (selection_path != null) ? selection_path.GetBounds () : live_preview_surface.GetBounds ();
			render_bounds = PintaCore.Workspace.ClampToImageSize (render_bounds);	

			history_item = new SimpleHistoryItem (effect.Icon, effect.Name);
			history_item.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayerIndex);	
			
			// Paint the pre-effect layer surface into into the working surface.
			using (var ctx = new Cairo.Context (live_preview_surface)) {
				layer.Draw(ctx, layer.Surface, 1);
			}
			
			if (effect.EffectData != null)
				effect.EffectData.PropertyChanged += EffectData_PropertyChanged;
			
			if (Started != null) {
				Started (this, new LivePreviewStartedEventArgs());
			}
			
			var settings = new AsyncEffectRenderer.Settings () {
				ThreadCount = PintaCore.System.RenderThreads,
				TileWidth = render_bounds.Width,
				TileHeight = 1,
				ThreadPriority = ThreadPriority.BelowNormal
			};
			
			Debug.WriteLine (DateTime.Now.ToString("HH:mm:ss:ffff") + "Start Live preview.");
			
			renderer = new Renderer (this, settings);
			renderer.Start (effect, layer.Surface, live_preview_surface, render_bounds);
			
			if (effect.IsConfigurable) {		
				if (!effect.LaunchConfiguration ()) {
					PintaCore.Chrome.MainWindowBusy = true;
					Cancel ();
				} else {
					PintaCore.Chrome.MainWindowBusy = true;
					Apply ();
				}
			} else {
				PintaCore.Chrome.MainWindowBusy = true;
				Apply ();
			}
		}
コード例 #58
0
        public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination)
        {
            // copy to a surface
            using (var surface = new Cairo.ImageSurface(Cairo.Format.Rgb24, (int)source.Width, (int)source.Height))
            {
                unsafe
                {
                    var destrow = (byte *)surface.DataPtr;
                    fixed(byte *srcdata = Control)
                    {
                        byte *srcrow = srcdata + ((int)source.Top * rowStride) + (int)source.Left;

                        for (int y = (int)source.Top; y < (int)source.Bottom; y++)
                        {
                            var src  = srcrow;
                            var dest = (uint *)destrow;
                            for (int x = (int)source.Left; x < (int)source.Right; x++)
                            {
                                *
                                dest = colors[*src];
                                src++;
                                dest++;
                            }

                            srcrow  += rowStride;
                            destrow += surface.Stride;
                        }
                    }
                }

                var context = graphics.Control;
                context.Save();
                destination.X += (float)graphics.InverseOffset;
                destination.Y += (float)graphics.InverseOffset;
                context.Rectangle(destination.ToCairo());
                double scalex = 1;
                double scaley = 1;
                if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f)
                {
                    scalex = (double)destination.Width / (double)source.Width;
                    scaley = (double)destination.Height / (double)source.Height;
                    context.Scale(scalex, scaley);
                }
                context.SetSourceSurface(surface, (int)destination.Left, (int)destination.Top);
                context.Fill();
                context.Restore();
            }


            /*
             * if (graphics == null || graphics.Control == null || graphics.GC == null)
             *      throw new Exception("WHAA?");
             * using (var drawable = new Gdk.Pixmap(graphics.Control, source.Right+1, source.Bottom+1))
             * using (var gc = new Gdk.GC(drawable))
             * {
             *      if (drawable.Colormap == null)
             *              drawable.Colormap = graphics.Control.Colormap;
             *      drawable.DrawIndexedImage(gc, 0, 0, source.Right+1, source.Bottom+1, Gdk.RgbDither.None, Control, this.rowStride, GetPmap());
             *      if (source.Width != destination.Width || source.Height != destination.Height)
             *      {
             *              // scale da shit
             *              Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, source.Width, source.Height);
             *              pb.GetFromDrawable(drawable, drawable.Colormap, source.X, source.Y, 0, 0, source.Width, source.Height);
             *
             *              Gdk.Pixbuf pbDest = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height);
             *              pb.Scale(pbDest, 0, 0, destination.Width, destination.Height, 0, 0, (double)destination.Width / (double)source.Width,
             *                      (double)destination.Height / (double)source.Height, Gdk.InterpType.Bilinear);
             *              pb.Dispose();
             *
             *
             *              graphics.Control.DrawPixbuf(graphics.GC, pbDest, 0, 0, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0);
             *              pbDest.Dispose();
             *      }
             *      else
             *      {
             *              // no scaling necessary!
             *              graphics.Control.DrawDrawable(graphics.GC, drawable, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height);
             *      }
             *
             * }*/
        }
コード例 #59
0
ファイル: ImageHandler.cs プロジェクト: wwwK/dotdevelop-xwt
        internal static Gdk.Pixbuf CreateBitmap(string stockId, double width, double height, double scaleFactor)
        {
            Gdk.Pixbuf result = null;

            Gtk.IconSet iconset = Gtk.IconFactory.LookupDefault(stockId);
            if (iconset != null)
            {
                // Find the size that better fits the requested size
                Gtk.IconSize gsize = Util.GetBestSizeFit(width);
                result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize, null, null, scaleFactor);
                if (result == null || result.Width < width * scaleFactor)
                {
                    var gsize2x = Util.GetBestSizeFit(width * scaleFactor, iconset.Sizes);
                    if (gsize2x != Gtk.IconSize.Invalid && gsize2x != gsize)
                    {
                        // Don't dispose the previous result since the icon is owned by the IconSet
                        result = iconset.RenderIcon(Gtk.Widget.DefaultStyle, Gtk.TextDirection.Ltr, Gtk.StateType.Normal, gsize2x, null, null);
                    }
                }
            }

            if (result == null && Gtk.IconTheme.Default.HasIcon(stockId))
            {
                result = Gtk.IconTheme.Default.LoadIcon(stockId, (int)width, (Gtk.IconLookupFlags) 0);
            }

            if (result == null)
            {
                // render a custom gtk-missing-image icon
                // if Gtk.Stock.MissingImage is not found
                int w = (int)width;
                int h = (int)height;
                                #if XWT_GTK3
                Cairo.ImageSurface s  = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
                Cairo.Context      cr = new Cairo.Context(s);
                cr.SetSourceRGB(255, 255, 255);
                cr.Rectangle(0, 0, w, h);
                cr.Fill();
                cr.SetSourceRGB(0, 0, 0);
                cr.LineWidth = 1;
                cr.Rectangle(0.5, 0.5, w - 1, h - 1);
                cr.Stroke();
                cr.SetSourceRGB(255, 0, 0);
                cr.LineWidth = 3;
                cr.LineCap   = Cairo.LineCap.Round;
                cr.LineJoin  = Cairo.LineJoin.Round;
                cr.MoveTo(w / 4, h / 4);
                cr.LineTo((w - 1) - w / 4, (h - 1) - h / 4);
                cr.MoveTo(w / 4, (h - 1) - h / 4);
                cr.LineTo((w - 1) - w / 4, h / 4);
                cr.Stroke();
                result = Gtk3Extensions.GetFromSurface(s, 0, 0, w, h);
                                #else
                using (Gdk.Pixmap pmap = new Gdk.Pixmap(Gdk.Screen.Default.RootWindow, w, h))
                    using (Gdk.GC gc = new Gdk.GC(pmap)) {
                        gc.RgbFgColor = new Gdk.Color(255, 255, 255);
                        pmap.DrawRectangle(gc, true, 0, 0, w, h);
                        gc.RgbFgColor = new Gdk.Color(0, 0, 0);
                        pmap.DrawRectangle(gc, false, 0, 0, (w - 1), (h - 1));
                        gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
                        gc.RgbFgColor = new Gdk.Color(255, 0, 0);
                        pmap.DrawLine(gc, (w / 4), (h / 4), ((w - 1) - (w / 4)), ((h - 1) - (h / 4)));
                        pmap.DrawLine(gc, ((w - 1) - (w / 4)), (h / 4), (w / 4), ((h - 1) - (h / 4)));
                        result = Gdk.Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, w, h);
                    }
                                #endif
            }
            return(result);
        }
コード例 #60
0
ファイル: TextTool.cs プロジェクト: Kharevich/Pinta
        private void StartEditing()
        {
            is_editing = true;

            //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop).
            ignoreCloneFinalizations = true;

            //Store the previous state of the current UserLayer's and TextLayer's ImageSurfaces.
            user_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface.Clone();
            text_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface.Clone();
            undo_engine = CurrentTextEngine.Clone();

            //Stop ignoring any Surface.Clone calls from this point on.
            ignoreCloneFinalizations = false;
        }