public IRenderer <ColorBgra> CreateRenderer() { IRenderer <ColorBgra> sourceLHS = null; for (int i = 0; i < this.document.Layers.Count; i++) { DocumentLayerOverlay overlay; Layer key = (Layer)this.document.Layers[i]; if (this.overlays.TryGetValue(key, out overlay)) { if (key.Visible && (key.Opacity != 0)) { CompositionOp op = LayerBlendModeUtil.CreateCompositionOp(key.BlendMode, key.Opacity); sourceLHS = sourceLHS.DrawBlend(op, overlay); } } else { sourceLHS = ((Layer)this.document.Layers[i]).CreateRenderer(sourceLHS); } } if (sourceLHS == null) { sourceLHS = new SolidColorRendererBgra(this.Width, this.Height, ColorBgra.Zero); } return(sourceLHS); }
protected override IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > OnCreateContentRenderers(IHistoryWorkspace historyWorkspace, int width, int height) { IRenderer <ColorBgra> contentRenderer = new SolidColorRendererBgra(width, height, this.fillColor); IRenderer <ColorAlpha8> maskRenderer = new FillRendererAlpha8(width, height, ColorAlpha8.Opaque); MultiplexedMaskedRenderer <ColorBgra, ColorAlpha8> renderer3 = new MultiplexedMaskedRenderer <ColorBgra, ColorAlpha8>(contentRenderer, maskRenderer, ColorAlpha8.Opaque); yield return(renderer3); }
private void RefreshLayerThumbnail(Layer layer) { if (this.layerToItemMap.ContainsKey(layer)) { IRenderer <ColorBgra> layerRenderer = null; if ((layerRenderer == null) && (this.documentWorkspace != null)) { int index = this.document.Layers.IndexOf(layer); if (index != -1) { layerRenderer = this.documentWorkspace.DocumentCanvas.DocumentCanvasLayer.DocumentRenderer.CreateLayerRenderer(index); } } if (layerRenderer == null) { layerRenderer = new SolidColorRendererBgra(layer.Width, layer.Height, ColorBgra.TransparentBlack); } OurThumbnailProvider updateMe = new OurThumbnailProvider(layerRenderer, layer); this.thumbnailManager.QueueThumbnailUpdate(updateMe, base.ThumbEdgeLength, new ValueEventHandler <Tuple <IThumbnailProvider, ISurface <ColorBgra> > >(this.OnThumbnailUpdated)); } }
public bool PerformAction() { bool flag = true; if (!this.QueryCanPerformAction()) { return(false); } try { using (new WaitCursorChanger(this.documentWorkspace)) { IRenderer <ColorBgra> source = this.GetSource(); RectInt32 num = source.Bounds <ColorBgra>(); GeometryList cachedClippingMask = this.documentWorkspace.Selection.GetCachedClippingMask(); RectInt32 a = cachedClippingMask.Bounds.Int32Bound; IRenderer <ColorAlpha8> cachedClippingMaskRenderer = this.documentWorkspace.Selection.GetCachedClippingMaskRenderer(this.documentWorkspace.ToolSettings.Selection.RenderingQuality.Value); RectInt32 sourceRect = RectInt32.Intersect(a, source.Bounds <ColorBgra>()); IRenderer <ColorBgra> renderer3 = new ClippedRenderer <ColorBgra>(source, sourceRect); IRenderer <ColorAlpha8> alpha = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect); IRenderer <ColorBgra> sourceRHS = new MultiplyAlphaChannelRendererBgra32(renderer3, alpha); IRenderer <ColorBgra> sourceLHS = new SolidColorRendererBgra(sourceRHS.Width, sourceRHS.Height, ColorBgra.White); IRenderer <ColorBgra> renderer = new BlendRendererBgra(sourceLHS, CompositionOps.Normal.Static, sourceRHS); if ((a.Width > 0) && (a.Height > 0)) { int num5 = 10; while (num5 >= 0) { try { try { using (Clipboard.Transaction transaction = Clipboard.Open(this.documentWorkspace)) { transaction.Empty(); using (MaskedSurface surface = MaskedSurface.CopyFrom(source, cachedClippingMask)) { transaction.AddManagedData(surface); using (Surface surface2 = surface.Surface.CreateWindow(new Rectangle(0, 0, a.Width, a.Height))) { sourceRHS.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2); using (Bitmap copyBitmap = surface2.CreateAliasedBitmap(true)) { transaction.AddRawNativeData("PNG", delegate(Stream dstStream) { copyBitmap.Save(dstStream, ImageFormat.Png); }); } renderer.Parallelize <ColorBgra>(TilingStrategy.Tiles, 7, WorkItemQueuePriority.Normal).Render <ColorBgra>(surface2); using (Bitmap bitmap = surface2.CreateAliasedBitmap(false)) { transaction.AddDibV5(bitmap); } } goto Label_0292; } } } catch (Exception exception) { if (num5 == 0) { flag = false; ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.TransferToClipboard"), exception.ToString()); } else { CleanupManager.RequestCleanup(); CleanupManager.WaitForPendingCleanup(50); Thread.Sleep(50); } } continue; } finally { num5--; } } } } } catch (OutOfMemoryException exception2) { flag = false; ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.OutOfMemory"), exception2.ToString()); } catch (Exception exception3) { flag = false; ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("CopyAction.Error.Generic"), exception3.ToString()); } Label_0292: CleanupManager.RequestCleanup(); return(flag); }