public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { #if false Surface = new ImageSurface(Format.RGB24, allocation.Width, allocation.Height); Context ctx = new Context(Surface); #else Console.WriteLine("source status = {0}", info.Surface.Status); Surface = info.Surface.CreateSimilar(Content.Color, allocation.Width, allocation.Height); System.Console.WriteLine("status = {1} pointer = {0}", Surface.Handle.ToString(), Surface.Status); Context ctx = new Context(Surface); #endif Bounds = allocation; ctx.Matrix = info.Fill(allocation); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); }
public void imagepattern(Context cr, int width, int height) { Normalize(cr, width, height); ImageSurface image = new ImageSurface("data/romedalen.png"); int w = image.Width; int h = image.Height; SurfacePattern pattern = new SurfacePattern(image); pattern.Extend = Extend.Repeat; cr.Translate(0.5, 0.5); cr.Rotate(Math.PI / 4); cr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2)); cr.Translate(-0.5, -0.5); Matrix matrix = new Matrix(); matrix.InitScale(w * 5.0, h * 5.0); pattern.Matrix = matrix; cr.Source = pattern; cr.Rectangle(0, 0, 1.0, 1.0); cr.Fill(); pattern.Destroy(); image.Destroy(); }
/// <summary> /// Gets a surface pattern from a named file. /// </summary> /// <param name="capi">The Client API</param> /// <param name="textureLoc">The name of the file.</param> /// <param name="doCache">Do we cache the file?</param> /// <returns>The resulting surface pattern.</returns> public static SurfacePattern getPattern(ICoreClientAPI capi, AssetLocation textureLoc, bool doCache = true, int mulAlpha = 255) { if (cachedPatterns.ContainsKey(textureLoc) && cachedPatterns[textureLoc].Key.HandleValid) { return(cachedPatterns[textureLoc].Key); } ImageSurface patternSurface = getImageSurfaceFromAsset(capi, textureLoc, mulAlpha); SurfacePattern pattern = new SurfacePattern(patternSurface); pattern.Extend = Extend.Repeat; if (doCache) { cachedPatterns[textureLoc] = new KeyValuePair <SurfacePattern, ImageSurface>(pattern, patternSurface); } Matrix m = new Matrix(); m.Scale(1f / RuntimeEnv.GUIScale, 1f / RuntimeEnv.GUIScale); pattern.Matrix = m; return(pattern); }
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); }
public void Apply(Context ctx, Gdk.Rectangle allocation) { var p = new SurfacePattern(info.Surface); ctx.Matrix = new Matrix(); var m = info.Fit(allocation); ctx.Operator = Operator.Over; ctx.Matrix = m; ctx.SetSource(p); ctx.Paint(); var overlay = new SurfacePattern(blur.Surface); ctx.Matrix = new Matrix(); ctx.Matrix = blur.Fit(allocation); ctx.Operator = Operator.Over; ctx.SetSource(overlay); // FIXME ouch this is ugly. if (mask == null) { Radius = Radius; } //ctx.Paint (); ctx.Mask(mask); overlay.Dispose(); p.Dispose(); }
// Thanks to: Owen Taylor // https://lists.freedesktop.org/archives/cairo/2006-January/006178.html private static Surface scale_surface(Surface old_surface, int old_width, int old_height, int new_width, int new_height) { Surface new_surface = old_surface.CreateSimilar(Cairo.Content.ColorAlpha, new_width, new_height); Context cr = new Context(new_surface); /* Scale *before* setting the source surface (1) */ cr.Scale((double)new_width / old_width, (double)new_height / old_height); cr.SetSourceSurface(old_surface, 0, 0); /* To avoid getting the edge pixels blended with 0 alpha, which would * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2) */ Cairo.Pattern pattern = new SurfacePattern(old_surface); pattern.Extend = Cairo.Extend.Reflect; /* Replace the destination with the source instead of overlaying */ cr.Operator = Cairo.Operator.Source; /* Do the actual drawing */ cr.Paint(); cr.Dispose(); return(new_surface); }
private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast) { Pixbuf result; using (ImageInfo info = new ImageInfo(input)) { MemorySurface surface = new MemorySurface(Format.Argb32, input.Width, input.Height); Context ctx = new Context(surface); ctx.Matrix = info.Fill(info.Bounds, angle); SurfacePattern p = new SurfacePattern(info.Surface); if (fast) { p.Filter = Filter.Fast; } ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); result = MemorySurface.CreatePixbuf(surface); surface.Flush(); } return(result); }
public bool OnExpose(Context ctx, Gdk.Rectangle allocation) { fraction = Math.Min(fraction, 1.0); ctx.Operator = Operator.Source; Matrix em = end_buffer.Fill(allocation); em.Translate(Math.Round(allocation.Width - allocation.Width * fraction), 0); ctx.Matrix = em; SurfacePattern sur = new SurfacePattern(end_buffer.Surface); sur.Filter = Filter.Fast; ctx.Source = sur; ctx.Paint(); sur.Destroy(); ctx.Operator = Operator.Over; SurfacePattern p = new SurfacePattern(begin_buffer.Surface); Matrix m = begin_buffer.Fill(allocation); m.Translate(Math.Round(-allocation.Width * fraction), 0); ctx.Matrix = m; p.Filter = Filter.Fast; ctx.Source = p; ctx.Paint(); p.Destroy(); return(fraction < 1.0); }
void FillChecks(Context cr, int x, int y, int width, int height) { int CHECK_SIZE = 32; cr.Save(); Surface check = cr.Target.CreateSimilar(Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE); // draw the check using (Context cr2 = new Context(check)) { cr2.Operator = Operator.Source; cr2.Color = new Cairo.Color(0.4, 0.4, 0.4); cr2.Rectangle(0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE); //0,0 cr2.Fill(); cr2.Color = new Cairo.Color(0.7, 0.7, 0.7); cr2.Rectangle(x, y, CHECK_SIZE, CHECK_SIZE); cr2.Fill(); cr2.Rectangle(x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE); cr2.Fill(); } // Fill the whole surface with the check SurfacePattern check_pattern = new SurfacePattern(check); check_pattern.Extend = Extend.Repeat; cr.Source = check_pattern; cr.Rectangle(0, 0, width, height); //0,0 cr.Fill(); check_pattern.Destroy(); check.Destroy(); cr.Restore(); }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; Uri dest = req.TempUri(Path.GetExtension(source)); using (ImageFile img = ImageFile.Create(source)) { using (Pixbuf pixbuf = img.Load()) { using (ImageInfo info = new ImageInfo(pixbuf)) { MemorySurface surface = new MemorySurface(Format.Argb32, pixbuf.Width, pixbuf.Height); Context ctx = new Context(surface); ctx.Matrix = info.Fill(info.Bounds, angle); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); using (Pixbuf result = CairoUtils.CreatePixbuf(surface)) { using (Stream output = File.OpenWrite(dest.LocalPath)) { img.Save(result, output); } } surface.Flush(); info.Dispose(); req.Current = dest; return(true); } } } }
public void Apply(Context ctx, Gdk.Rectangle allocation) { SurfacePattern p = new SurfacePattern(info.Surface); ctx.Matrix = new Matrix(); Matrix m = info.Fit(allocation); ctx.Operator = Operator.Over; ctx.Matrix = m; ctx.Source = p; ctx.Paint(); SurfacePattern overlay = new SurfacePattern(blur.Surface); ctx.Matrix = new Matrix(); ctx.Matrix = blur.Fit(allocation); ctx.Operator = Operator.Over; ctx.Source = overlay; // FIXME ouch this is ugly. if (mask == null) { Radius = Radius; } //ctx.Paint (); ctx.Mask(mask); overlay.Destroy(); p.Destroy(); }
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); }
public bool OnExpose(Context ctx, Gdk.Rectangle allocation) { ctx.Operator = Operator.Source; SurfacePattern p = new SurfacePattern(begin_buffer.Surface); ctx.Matrix = begin_buffer.Fill(allocation); p.Filter = Filter.Fast; ctx.Source = p; ctx.Paint(); ctx.Operator = Operator.Over; ctx.Matrix = end_buffer.Fill(allocation); SurfacePattern sur = new SurfacePattern(end_buffer.Surface); sur.Filter = Filter.Fast; ctx.Source = sur; Pattern mask = CreateMask(allocation, fraction); ctx.Mask(mask); mask.Destroy(); p.Destroy(); sur.Destroy(); return(fraction < 1.0); }
protected void DrawBackground(Cairo.Context cr) { var totalRect = GetTotalBounds(); cr.SetSourceColor(BackgroundColor); cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height); cr.Fill(); cr.Save(); cr.Translate(XOffset, YOffset); cr.Scale(Scale, Scale); if (Surface != null) { cr.SetSource(Surface, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } else if (Image != null) { using (Surface source = new BitmapSurface(Image)) { cr.SetSource(source, 0, 0); using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) { pattern.Filter = Filter.Nearest; } cr.Paint(); } } else { Cairo.Rectangle extents = cr.ClipExtents(); for (int i = 0; i < Width * Height; i++) { int tileX = i % Width; int tileY = i / Width; Cairo.Rectangle rect = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false); if (!CairoHelper.RectsOverlap(extents, rect)) { continue; } cr.Save(); cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY); cr.Rectangle(0, 0, TileWidth, TileHeight); cr.Clip(); TileDrawer(i, cr); cr.Restore(); } } cr.Restore(); // Undo scale, offset }
internal SurfacePattern paintWithPattern(ICoreClientAPI capi, Context ctx, string texFileName) { SurfacePattern pattern = getPattern(capi, texFileName); ctx.SetSource(pattern); ctx.Paint(); return(pattern); }
internal SurfacePattern paintWithPattern(ICoreClientAPI capi, Context ctx, AssetLocation textureLoc) { SurfacePattern pattern = getPattern(capi, textureLoc); ctx.SetSource(pattern); ctx.Paint(); return(pattern); }
/// <summary> /// Gets a surface pattern based off the bitmap. /// </summary> /// <param name="bitmap">The provided bitmap.</param> /// <returns>The resulting surface pattern.</returns> public static SurfacePattern getPattern(Bitmap bitmap) { ImageSurface patternSurface = getImageSurfaceFromAsset(bitmap); SurfacePattern pattern = new SurfacePattern(patternSurface); pattern.Extend = Extend.Repeat; return(pattern); }
public override void TexturePolygon(ShapeDescriptor d, List <Point> points) { context.Save(); OutlinePolygon(points); using (SurfacePattern pattern = new SurfacePattern(cache.GetSurface(d))) { pattern.Extend = Cairo.Extend.Repeat; context.SetSource(pattern); context.Fill(); } context.Restore(); }
public bool OnExpose(Context ctx, Gdk.Rectangle allocation) { if (frames == 0) { start = DateTime.UtcNow; } frames++; TimeSpan elapsed = DateTime.UtcNow - start; double fraction = elapsed.Ticks / (double)duration.Ticks; double opacity = Math.Sin(Math.Min(fraction, 1.0) * Math.PI * 0.5); ctx.Operator = Operator.Source; SurfacePattern p = new SurfacePattern(begin_buffer.Surface); ctx.Matrix = begin_buffer.Fill(allocation); p.Filter = Filter.Fast; ctx.Source = p; ctx.Paint(); ctx.Operator = Operator.Over; ctx.Matrix = end_buffer.Fill(allocation); SurfacePattern sur = new SurfacePattern(end_buffer.Surface); #if MONO_1_2_5 Pattern black = new SolidPattern(new Cairo.Color(0.0, 0.0, 0.0, opacity)); #else Pattern black = new SolidPattern(new Cairo.Color(0.0, 0.0, 0.0, opacity), true); #endif //ctx.Source = black; //ctx.Fill (); sur.Filter = Filter.Fast; ctx.Source = sur; ctx.Mask(black); //ctx.Paint (); ctx.Matrix = new Matrix(); ctx.MoveTo(allocation.Width / 2.0, allocation.Height / 2.0); ctx.Source = new SolidPattern(1.0, 0, 0); #if debug ctx.ShowText(String.Format("{0} {1} {2} {3} {4} {5} {6} {7}", frames, sur.Status, p.Status, opacity, fraction, elapsed, start, DateTime.UtcNow)); #endif sur.Destroy(); p.Destroy(); return(fraction < 1.0); }
private void OnExpose(Context ctx, Region region) { SetClip(ctx, region); if (Transition != null) { bool done = false; foreach (Gdk.Rectangle area in GetRectangles(region)) { BlockProcessor proc = new BlockProcessor(area, block_size); Gdk.Rectangle subarea; while (proc.Step(out subarea)) { ctx.Save(); SetClip(ctx, subarea); done = !Transition.OnExpose(ctx, Allocation); ctx.Restore(); } } if (done) { System.Console.WriteLine("frames = {0}", Transition.Frames); Transition = null; } } else if (effect != null) { foreach (Gdk.Rectangle area in GetRectangles(region)) { BlockProcessor proc = new BlockProcessor(area, block_size); Gdk.Rectangle subarea; while (proc.Step(out subarea)) { ctx.Save(); SetClip(ctx, subarea); effect.OnExpose(ctx, Allocation); ctx.Restore(); } } } else { ctx.Operator = Operator.Source; SurfacePattern p = new SurfacePattern(current.Surface); p.Filter = Filter.Fast; SetClip(ctx, region); ctx.Matrix = current.Fill(Allocation); ctx.Source = p; ctx.Paint(); p.Destroy(); } }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { using (var similar = CairoUtils.CreateSurface(w.GdkWindow)) { Bounds = bounds; Surface = similar.CreateSimilar(Content.ColorAlpha, Bounds.Width, Bounds.Height); var ctx = new Context(Surface); ctx.Matrix = info.Fill(Bounds); Pattern p = new SurfacePattern(info.Surface); ctx.SetSource(p); ctx.Paint(); ctx.Dispose(); p.Dispose(); } }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { Cairo.Surface similar = CairoUtils.CreateSurface(w.GdkWindow); Bounds = bounds; Surface = similar.CreateSimilar(Content.ColorAlpha, Bounds.Width, Bounds.Height); Context ctx = new Context(Surface); ctx.Matrix = info.Fill(Bounds); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); }
public virtual void Draw(Context cr) { var r = Rect; using (var pat = new SurfacePattern(Image)) { pat.Matrix = new Matrix() { X0 = -r.X, Y0 = -r.Y }; pat.Extend = Extend.Repeat; cr.SetSource(pat); cr.Rectangle(new Rectangle(r.X, r.Y, r.Width, r.Height)); cr.Fill(); } }
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { Surface = info.Surface.CreateSimilar(Content.Color, allocation.Width, allocation.Height); var ctx = new Context(Surface); Bounds = allocation; ctx.Matrix = info.Fill(allocation); Pattern p = new SurfacePattern(info.Surface); ctx.SetSource(p); ctx.Paint(); ctx.Dispose(); p.Dispose(); }
public static bool Subsumes(PatternFactory.PatternType patternClass, Edu.Stanford.Nlp.Patterns.Pattern pat, Edu.Stanford.Nlp.Patterns.Pattern p) { if (patternClass.Equals(PatternFactory.PatternType.Surface)) { return(SurfacePattern.Subsumes((SurfacePattern)pat, (SurfacePattern)p)); } else { if (patternClass.Equals(PatternFactory.PatternType.Dep)) { return(DepPattern.Subsumes((DepPattern)pat, (DepPattern)p)); } else { throw new NotSupportedException(); } } }
public bool OnExpose(Context ctx, Gdk.Rectangle allocation) { ctx.Operator = Operator.Source; SurfacePattern p = new SurfacePattern(info.Surface); p.Filter = Filter.Fast; Matrix m = info.Fill(allocation, angle); ctx.Matrix = m; ctx.Source = p; ctx.Paint(); p.Destroy(); return(true); }
public ImageBrushImpl( ITileBrush brush, IBitmapImpl bitmap, Size targetSize) { var calc = new TileBrushCalculator(brush, new Size(bitmap.PixelWidth, bitmap.PixelHeight), targetSize); using (var intermediate = new ImageSurface(Format.ARGB32, (int)calc.IntermediateSize.Width, (int)calc.IntermediateSize.Height)) { using (var context = new RenderTarget(intermediate).CreateDrawingContext(null)) { var rect = new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight); context.Clear(Colors.Transparent); context.PushClip(calc.IntermediateClip); context.Transform = calc.IntermediateTransform; context.DrawImage(bitmap, 1, rect, rect); context.PopClip(); } var result = new SurfacePattern(intermediate); if ((brush.TileMode & TileMode.FlipXY) != 0) { // TODO: Currently always FlipXY as that's all cairo supports natively. // Support separate FlipX and FlipY by drawing flipped images to intermediate // surface. result.Extend = Extend.Reflect; } else { result.Extend = Extend.Repeat; } if (brush.TileMode != TileMode.None) { var matrix = result.Matrix; matrix.InitTranslate(-calc.DestinationRect.X, -calc.DestinationRect.Y); result.Matrix = matrix; } PlatformBrush = result; } }
internal void ComposeWaterTexture() { double sliderWidth = Bounds.InnerWidth - 2 * padding - handleWidth / 2; double handlePosition = sliderWidth * (1.0 * currentValue - minValue) / (maxValue - minValue); double insetHeight = Bounds.InnerHeight - 2 * padding; ImageSurface surface = new ImageSurface(Format.Argb32, (int)(handlePosition + 5), (int)insetHeight); Context ctx = genContext(surface); SurfacePattern pattern = getPattern(api, waterTextureName); RoundRectangle(ctx, 0, 0, surface.Width, surface.Height, 1); ctx.SetSource(pattern); ctx.Fill(); generateTexture(surface, ref waterTexture); ctx.Dispose(); surface.Dispose(); }
public static void SetSourceDrawable(Context ctx, Gdk.Drawable d, double x, double y) { try { gdk_cairo_set_source_pixmap(ctx.Handle, d.Handle, x, y); } catch (EntryPointNotFoundException) { int width, height; d.GetSize(out width, out height); XlibSurface surface = new XlibSurface(GdkUtils.GetXDisplay(d.Display), (IntPtr)GdkUtils.GetXid(d), GdkUtils.GetXVisual(d.Visual), width, height); SurfacePattern p = new SurfacePattern(surface); Matrix m = new Matrix(); m.Translate(-x, -y); p.Matrix = m; ctx.Source = p; } }
public bool OnExpose(Context ctx, Gdk.Rectangle viewport) { double percent = Math.Min((DateTime.UtcNow - start).Ticks / (double)duration.Ticks, 1.0); //Matrix m = info.Fill (allocation); Matrix m = new Matrix(); m.Translate(pan_x, pan_y); m.Scale(zoom, zoom); ctx.Matrix = m; SurfacePattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); p.Destroy(); return(percent < 1.0); }