示例#1
0
        private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool?.DoHandleCopy(doc, cb) == true)
            {
                return;
            }

            PintaCore.Tools.Commit();

            using (ImageSurface src = doc.Layers.GetClippedLayer(doc.Layers.CurrentUserLayerIndex)) {
                Gdk.Rectangle rect = doc.GetSelectedBounds(true);
                if (rect.Width == 0 || rect.Height == 0)
                {
                    return;
                }

                ImageSurface dest = CairoExtensions.CreateImageSurface(Format.Argb32, rect.Width, rect.Height);

                using (Context g = new Context(dest)) {
                    g.SetSourceSurface(src, -rect.X, -rect.Y);
                    g.Paint();
                }

                cb.Image = dest.ToPixbuf();

                (dest as IDisposable).Dispose();
            }
        }
示例#2
0
        private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast)
        {
            Pixbuf result;

            using (ImageInfo info = new ImageInfo(input)) {
                using (ImageSurface surface = new ImageSurface(Format.Argb32,
                                                               input.Width,
                                                               input.Height)) {
                    using (Context ctx = new Context(surface)) {
                        ctx.Matrix = info.Fill(info.Bounds, angle);
                        using (SurfacePattern p = new SurfacePattern(info.Surface)) {
                            if (fast)
                            {
                                p.Filter = Filter.Fast;
                            }
                            ctx.Source = p;
                            ctx.Paint();
                        }
                        result = surface.ToPixbuf();
                        surface.Flush();
                    }
                }
            }
            return(result);
        }
示例#3
0
        public void Draw(ImageSurface dst)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("PlacedSurface");
            }

            using (Cairo.Context g = new Cairo.Context(dst)) {
                g.Save();

                Rectangle r = what.GetBounds().ToCairoRectangle();

                // We need to use the source operator to fully replace the old
                // data.  Or else we may paint transparent on top of it and
                // it will still be visible.  [Bug #670411]
                using (Path p = g.CreateRectanglePath(new Rectangle(where.X, where.Y, r.Width, r.Height))) {
                    g.AppendPath(p);
                    g.Clip();
                    g.Operator = Operator.Source;
                    g.DrawPixbuf(what.ToPixbuf(), new Cairo.Point(where.X, where.Y));
                }

                g.Restore();
            }
        }
示例#4
0
        private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
        {
            Gtk.Clipboard cb = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            if (PintaCore.Tools.CurrentTool.TryHandleCopy(cb))
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            ImageSurface src = doc.GetClippedLayer(doc.CurrentLayerIndex);

            Gdk.Rectangle rect = doc.GetSelectedBounds(true);

            ImageSurface dest = new ImageSurface(Format.Argb32, rect.Width, rect.Height);

            using (Context g = new Context(dest)) {
                g.SetSourceSurface(src, -rect.X, -rect.Y);
                g.Paint();
            }

            cb.Image = dest.ToPixbuf();

            (src as IDisposable).Dispose();
            (dest as IDisposable).Dispose();
        }
示例#5
0
        public static Surface ScaleSmooth(this Surface source, int width, int height, double zoomX, double zoomY, InterpType interpolation = InterpType.Hyper)
        {
            ImageSurface tempSurface = new ImageSurface(Format.ARGB32, width, height);
            var          tempContext = new Context(tempSurface);

            tempContext.SetSourceSurface(source, 0, 0);
            tempContext.Paint();

            Pixbuf pbSrc = tempSurface.ToPixbuf();

            tempContext.DisposeAll();

            using (Pixbuf pbDest = new Pixbuf(Colorspace.Rgb, true, 8,
                                              (int)(width * zoomX),
                                              (int)(height * zoomY))) {
                pbSrc.Scale(pbDest, 0, 0, pbDest.Width, pbDest.Height, 0, 0, zoomX, zoomY, interpolation);
                pbSrc.Dispose();

                Surface cache        = new ImageSurface(Format.ARGB32, pbDest.Width, pbDest.Height);
                var     cacheContext = new Context(cache);
                CairoHelper.SetSourcePixbuf(cacheContext, pbDest, 0, 0);
                cacheContext.Paint();
                cacheContext.DisposeContext();

                return(cache);
            }
        }
示例#6
0
        private ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max(256 / (double)source.Bounds.Width,
                                    256 / (double)source.Bounds.Height);

            Gdk.Rectangle small = new Gdk.Rectangle(0, 0,
                                                    (int)Math.Ceiling(source.Bounds.Width * scale),
                                                    (int)Math.Ceiling(source.Bounds.Height * scale));

            ImageSurface image = new ImageSurface(Format.Argb32,
                                                  small.Width,
                                                  small.Height);

            Context ctx = new Context(image);

            ctx.Matrix   = source.Fit(small);
            ctx.Operator = Operator.Source;
            Pattern p = new SurfacePattern(source.Surface);

            ctx.Source = p;

            ctx.Paint();
            p.Destroy();
            ((IDisposable)ctx).Dispose();
            Gdk.Pixbuf normal = image.ToPixbuf();

            Gdk.Pixbuf blur = PixbufUtils.Blur(normal, 3, null);

            ImageInfo overlay = new ImageInfo(blur);

            blur.Dispose();
            normal.Dispose();
            image.Destroy();
            return(overlay);
        }
示例#7
0
        public void Export(Document document, string fileName, Gtk.Window parent)
        {
            ZipOutputStream stream = new ZipOutputStream(new FileStream(fileName, FileMode.Create))
            {
                UseZip64 = UseZip64.Off                 // For backwards compatibility with older versions.
            };
            ZipEntry mimetype = new ZipEntry("mimetype");

            mimetype.CompressionMethod = CompressionMethod.Stored;
            stream.PutNextEntry(mimetype);

            byte[] databytes = System.Text.Encoding.ASCII.GetBytes("image/openraster");
            stream.Write(databytes, 0, databytes.Length);

            for (int i = 0; i < document.Layers.UserLayers.Count; i++)
            {
                using Pixbuf pb = document.Layers.UserLayers[i].Surface.ToPixbuf();
                byte[] buf = pb.SaveToBuffer("png");

                stream.PutNextEntry(new ZipEntry("data/layer" + i.ToString() + ".png"));
                stream.Write(buf, 0, buf.Length);
            }

            stream.PutNextEntry(new ZipEntry("stack.xml"));
            databytes = GetLayerXmlData(document.Layers.UserLayers);
            stream.Write(databytes, 0, databytes.Length);

            using ImageSurface flattened = document.GetFlattenedImage();
            using Pixbuf flattenedPb     = flattened.ToPixbuf();

            // Add merged image.
            stream.PutNextEntry(new ZipEntry("mergedimage.png"));
            databytes = flattenedPb.SaveToBuffer("png");
            stream.Write(databytes, 0, databytes.Length);

            // Add thumbnail.
            Size newSize = GetThumbDimensions(flattenedPb.Width, flattenedPb.Height);

            using Pixbuf thumb = flattenedPb.ScaleSimple(newSize.Width, newSize.Height, InterpType.Bilinear);
            stream.PutNextEntry(new ZipEntry("Thumbnails/thumbnail.png"));
            databytes = thumb.SaveToBuffer("png");
            stream.Write(databytes, 0, databytes.Length);

            stream.Close();
        }
示例#8
0
        Pixbuf ProcessImpl(Pixbuf input, Cms.Profile inputProfile, bool fast)
        {
            Pixbuf result;

            using (var info = new ImageInfo(input)) {
                using (var soft = new SoftFocus(info)) {
                    soft.Radius = radius;

                    using (var surface = new ImageSurface(Format.Argb32, input.Width, input.Height)) {
                        using (var ctx = new Context(surface)) {
                            soft.Apply(ctx, info.Bounds);
                        }

                        result = surface.ToPixbuf();
                        surface.Flush();
                    }
                }
            }
            return(result);
        }
示例#9
0
    public static Pixbuf Blur(Pixbuf src, int radius, ThreadProgressDialog dialog)
    {
        ImageSurface sourceSurface      = Hyena.Gui.PixbufImageSurface.Create(src);
        ImageSurface destinationSurface = new ImageSurface(Format.Rgb24, src.Width, src.Height);

        // If we do it as a bunch of single lines (rectangles of one pixel) then we can give the progress
        // here instead of going deeper to provide the feedback
        for (int i = 0; i < src.Height; i++)
        {
            GaussianBlurEffect.RenderBlurEffect(sourceSurface, destinationSurface, new[] { new Gdk.Rectangle(0, i, src.Width, 1) }, radius);

            if (dialog != null)
            {
                // This only half of the entire process
                double fraction = ((double)i / (double)(src.Height - 1)) * 0.75;
                dialog.Fraction = fraction;
            }
        }

        return(destinationSurface.ToPixbuf());
    }
示例#10
0
        public void Export(Document document, string fileName)
        {
            ZipOutputStream stream   = new ZipOutputStream(new FileStream(fileName, FileMode.Create));
            ZipEntry        mimetype = new ZipEntry("mimetype");

            mimetype.CompressionMethod = CompressionMethod.Stored;
            stream.PutNextEntry(mimetype);

            byte[] databytes = System.Text.Encoding.ASCII.GetBytes("image/openraster");
            stream.Write(databytes, 0, databytes.Length);

            for (int i = 0; i < document.Layers.Count; i++)
            {
                Pixbuf pb  = document.Layers[i].Surface.ToPixbuf();
                byte[] buf = pb.SaveToBuffer("png");
                (pb as IDisposable).Dispose();

                stream.PutNextEntry(new ZipEntry("data/layer" + i.ToString() + ".png"));
                stream.Write(buf, 0, buf.Length);
            }

            stream.PutNextEntry(new ZipEntry("stack.xml"));
            databytes = GetLayerXmlData(document.Layers);
            stream.Write(databytes, 0, databytes.Length);

            ImageSurface flattened   = document.GetFlattenedImage();
            Pixbuf       flattenedPb = flattened.ToPixbuf();
            Size         newSize     = GetThumbDimensions(flattenedPb.Width, flattenedPb.Height);
            Pixbuf       thumb       = flattenedPb.ScaleSimple(newSize.Width, newSize.Height, InterpType.Bilinear);

            stream.PutNextEntry(new ZipEntry("Thumbnails/thumbnail.png"));
            databytes = thumb.SaveToBuffer("png");
            stream.Write(databytes, 0, databytes.Length);

            (flattened as IDisposable).Dispose();
            (flattenedPb as IDisposable).Dispose();
            (thumb as IDisposable).Dispose();

            stream.Close();
        }
示例#11
0
        ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max(256 / (double)source.Bounds.Width,
                                    256 / (double)source.Bounds.Height);

            var small = new Gdk.Rectangle(0, 0,
                                          (int)Math.Ceiling(source.Bounds.Width * scale),
                                          (int)Math.Ceiling(source.Bounds.Height * scale));

            var image = new ImageSurface(Format.Argb32,
                                         small.Width,
                                         small.Height);

            var ctx = new Context(image)
            {
                Matrix   = source.Fit(small),
                Operator = Operator.Source
            };
            Pattern p = new SurfacePattern(source.Surface);

            ctx.SetSource(p);

            ctx.Paint();
            p.Dispose();
            ctx.Dispose();

            ImageInfo overlay;

            using (var normal = image.ToPixbuf())
            {
                using (var pixbufBlur = PixbufUtils.Blur(normal, 3, null))
                {
                    overlay = new ImageInfo(pixbufBlur);
                }
            }

            image.Dispose();
            return(overlay);
        }
示例#12
0
        private void HandlerPintaCoreActionsEditCopyMergedActivated(object sender, EventArgs e)
        {
            var cb  = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
            var doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            // Get our merged ("flattened") image
            using (var src = doc.GetFlattenedImage()) {
                var rect = doc.GetSelectedBounds(true);

                // Copy it to a correctly sized surface
                using (var dest = new ImageSurface(Format.Argb32, rect.Width, rect.Height)) {
                    using (Context g = new Context(dest)) {
                        g.SetSourceSurface(src, -rect.X, -rect.Y);
                        g.Paint();
                    }

                    // Give it to the clipboard
                    cb.Image = dest.ToPixbuf();
                }
            }
        }