예제 #1
0
        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)
                {
                    ColorBgra srcCurrent = *src;
                    // PDN transparet is 255,255,255,0 Pinta is 0,0,0,0
                    if (srcCurrent.A == 0)
                    {
                        srcCurrent.B = 0;
                        srcCurrent.G = 0;
                        srcCurrent.R = 0;
                    }
                    *dst = srcCurrent;
                    dst++;
                    src++;
                }
            }

            surf.MarkDirty();
        }
예제 #2
0
파일: PlainBrush.cs 프로젝트: msiyer/Pinta
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			// Cairo does not support a single-pixel-long single-pixel-wide line
			if (x == lastX && y == lastY && g.LineWidth == 1 &&
			    PintaCore.Workspace.ActiveWorkspace.PointInCanvas (new PointD(x,y))) {
				surface.Flush ();

				ColorBgra source = surface.GetColorBgraUnchecked (x, y);
				source = UserBlendOps.NormalBlendOp.ApplyStatic (source, strokeColor.ToColorBgra ());
				surface.SetColorBgra (source, x, y);
				surface.MarkDirty ();

				return new Gdk.Rectangle (x - 1, y - 1, 3, 3);
			}

			g.MoveTo (lastX + 0.5, lastY + 0.5);
			g.LineTo (x + 0.5, y + 0.5);
			g.StrokePreserve ();

			Gdk.Rectangle dirty = g.FixedStrokeExtents ().ToGdkRectangle ();

			// For some reason (?!) we need to inflate the dirty
			// rectangle for small brush widths in zoomed images
			dirty.Inflate (1, 1);

			return dirty;
		}
예제 #3
0
파일: Document.cs 프로젝트: JoeyScarr/Pinta
        public ImageSurface GetFlattenedImage()
        {
            // Create a new image surface
            var surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            // Blend each visible layer onto our surface
            foreach (var layer in GetLayersToPaint())
            {
                var blendop = UserBlendOps.GetBlendOp(layer.BlendMode, layer.Opacity);
                blendop.Apply(surf, layer.Surface);
            }

            surf.MarkDirty();
            return(surf);
        }
예제 #4
0
파일: Document.cs 프로젝트: xiexin36/Pinta
        public ImageSurface GetFlattenedImage()
        {
            // Create a new image surface
            var surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            // Blend each visible layer onto our surface
            foreach (var layer in GetLayersToPaint())
            {
                using (var g = new Context(surf))
                    layer.Draw(g);
            }

            surf.MarkDirty();
            return(surf);
        }
예제 #5
0
파일: SurfaceDiff.cs 프로젝트: msiyer/Pinta
		private unsafe void ApplyAndSwap (ImageSurface dst, bool swap)
		{
			dst.Flush ();

			var dest_width = dst.Width;
			var dst_ptr = (ColorBgra*)dst.DataPtr;
			var mask_index = 0;
			ColorBgra swap_pixel;

			fixed (ColorBgra* fixed_ptr = pixels) {
				var pixel_ptr = fixed_ptr;
				dst_ptr += bounds.X + bounds.Y * dest_width;

				for (int y = bounds.Y; y <= bounds.GetBottom (); y++) {
					for (int x = bounds.X; x <= bounds.GetRight (); x++) {
						if (bitmask[mask_index++])
							if (swap) {
								swap_pixel = *dst_ptr;
								*dst_ptr = *pixel_ptr;
								*pixel_ptr++ = swap_pixel;
							} else {
								*dst_ptr = *pixel_ptr++;
							}

						dst_ptr++;
					}

					dst_ptr += dest_width - bounds.Width;
				}
			}
			
			dst.MarkDirty ();
		}
예제 #6
0
        public unsafe void Render(ImageSurface surface, Gdk.Rectangle[] rois)
        {
            byte startAlpha;
            byte endAlpha;

            if (this.alphaOnly) {
                ComputeAlphaOnlyValuesFromColors (this.startColor, this.endColor, out startAlpha, out endAlpha);
            } else {
                startAlpha = this.startColor.A;
                endAlpha = this.endColor.A;
            }

            surface.Flush ();

            ColorBgra* src_data_ptr = (ColorBgra*)surface.DataPtr;
            int src_width = surface.Width;

            for (int ri = 0; ri < rois.Length; ++ri) {
                Gdk.Rectangle rect = rois[ri];

                if (this.startPoint.X == this.endPoint.X && this.startPoint.Y == this.endPoint.Y) {
                    // Start and End point are the same ... fill with solid color.
                    for (int y = rect.Top; y <= rect.GetBottom (); ++y) {
                        ColorBgra* pixelPtr = surface.GetPointAddress(rect.Left, y);

                        for (int x = rect.Left; x <= rect.GetRight (); ++x) {
                            ColorBgra result;

                            if (this.alphaOnly && this.alphaBlending) {
                                byte resultAlpha = (byte)Utility.FastDivideShortByByte ((ushort)(pixelPtr->A * endAlpha), 255);
                                result = *pixelPtr;
                                result.A = resultAlpha;
                            } else if (this.alphaOnly && !this.alphaBlending) {
                                result = *pixelPtr;
                                result.A = endAlpha;
                            } else if (!this.alphaOnly && this.alphaBlending) {
                                result = this.normalBlendOp.Apply (*pixelPtr, this.endColor);
                            //if (!this.alphaOnly && !this.alphaBlending)
                            } else {
                                result = this.endColor;
                            }

                            *pixelPtr = result;
                            ++pixelPtr;
                        }
                    }
                } else {
                    var mainrect = rect;
                    var start = Environment.TickCount;
                    Parallel.ForEach(Enumerable.Range (rect.Top, rect.GetBottom () + 1),
                        (y) => ProcessGradientLine(startAlpha, endAlpha, y, mainrect, surface, src_data_ptr, src_width));
                    var end = Environment.TickCount;
                    Console.WriteLine ("Time: " + (end - start)+ "ms");
                }
            }

            surface.MarkDirty ();
            AfterRender ();
        }
예제 #7
0
파일: Document.cs 프로젝트: msiyer/Pinta
		public ImageSurface GetFlattenedImage ()
		{
			// Create a new image surface
			var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

			// Blend each visible layer onto our surface
			foreach (var layer in GetLayersToPaint (include_tool_layer: false)) {
                using (var g = new Context (surf))
                    layer.Draw (g);
			}

			surf.MarkDirty ();
			return surf;
		}
예제 #8
0
파일: Document.cs 프로젝트: Kharevich/Pinta
        public ImageSurface GetFlattenedImage()
        {
            // Create a new image surface
            var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            // Blend each visible layer onto our surface
            foreach (var layer in GetLayersToPaint ()) {
                var blendop = UserBlendOps.GetBlendOp (layer.BlendMode, layer.Opacity);
                blendop.Apply (surf, layer.Surface);
            }

            surf.MarkDirty ();
            return surf;
        }
예제 #9
0
		protected override void Render (ImageSurface src, ImageSurface dst, Gdk.Rectangle roi)
		{
            var r = roi.ToCairoRectangle ();

            using (var temp = new ImageSurface (Format.Argb32, roi.Width, roi.Height)) {

                RenderClouds (temp, roi, Data.Scale, (byte)(Data.Seed ^ instanceSeed), Data.Power / 100.0, 
                              PintaCore.Palette.PrimaryColor.ToColorBgra (), PintaCore.Palette.SecondaryColor.ToColorBgra ());
                
                temp.MarkDirty ();

                // Have to lock because effect renderer is multithreaded
                lock (render_lock) {
                    using (var g = new Context (dst)) {
                        // - Clear any previous render from the destination
                        // - Copy the source to the destination
                        // - Blend the clouds over the source
                        g.Clear (r);
                        g.BlendSurface (src, r);
                        g.BlendSurface (temp, r.Location (), (BlendMode)CloudsData.BlendOps[Data.BlendMode]);
                    }
                }
            }
		}