Beispiel #1
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if ((this.layerIndex < 1) || (this.layerIndex >= historyWorkspace.Document.Layers.Count))
            {
                object[] objArray1 = new object[] { "layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=", this.layerIndex, ", allowableRange=[0,", historyWorkspace.Document.Layers.Count, ")" };
                throw new ArgumentException(string.Concat(objArray1));
            }
            int          layerIndex = this.layerIndex - 1;
            RectInt32    rect       = historyWorkspace.Document.Bounds();
            GeometryList list       = new GeometryList();

            list.AddRect(rect);
            RectInt32[]          changedRegion = list.EnumerateInteriorScans().ToArrayEx <RectInt32>();
            BitmapHistoryMemento memento       = new BitmapHistoryMemento(null, null, historyWorkspace, layerIndex, changedRegion);
            BitmapLayer          layer         = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer          layer2        = (BitmapLayer)historyWorkspace.Document.Layers[layerIndex];
            RenderArgs           args          = new RenderArgs(layer2.Surface);

            base.EnterCriticalRegion();
            foreach (RectInt32 num4 in changedRegion)
            {
                layer.Render(args, num4.ToGdipRectangle());
            }
            layer2.Invalidate();
            args.Dispose();
            args = null;
            list = null;
            HistoryMemento memento2 = new DeleteLayerFunction(this.layerIndex).Execute(historyWorkspace);

            return(new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { memento, memento2 }));
        }
Beispiel #2
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            GeometryList cachedClippingMask = historyWorkspace.Selection.GetCachedClippingMask();

            if (historyWorkspace.Selection.IsEmpty || (cachedClippingMask.Bounds.Area < 1.0))
            {
                return(null);
            }
            Document document = historyWorkspace.Document;
            List <HistoryMemento> mementos   = new List <HistoryMemento>(document.Layers.Count);
            RectInt32             b          = cachedClippingMask.Bounds.GetInt32Bound(1E-05);
            RectInt32             sourceRect = RectInt32.Intersect(document.Bounds(), b);
            Document document2 = new Document(sourceRect.Width, sourceRect.Height);

            document2.ReplaceMetadataFrom(document);
            RectInt32 rect = new RectInt32(0, 0, sourceRect.Width, sourceRect.Height);
            IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value);
            IRenderer <ColorAlpha8> newClipMaskRenderer        = new ClippedRenderer <ColorAlpha8>(cachedClippingMaskRenderer, sourceRect);
            SelectionHistoryMemento item = new SelectionHistoryMemento(null, null, historyWorkspace);

            mementos.Add(item);
            base.EnterCriticalRegion();
            int count = document.Layers.Count;

            while (document.Layers.Count > 0)
            {
                BitmapLayer layer          = (BitmapLayer)document.Layers[0];
                Surface     croppedSurface = layer.Surface.CreateWindow(sourceRect);
                BitmapLayer newLayer       = RetryManager.RunMemorySensitiveOperation <BitmapLayer>(() => new BitmapLayer(croppedSurface));
                newLayer.LoadProperties(layer.SaveProperties());
                HistoryMemento deleteLayerMemento = new DeleteLayerFunction(0).Execute(historyWorkspace);
                mementos.Add(deleteLayerMemento);
                Task task = Task.Factory.StartNew(delegate {
                    deleteLayerMemento.Flush();
                }, TaskCreationOptions.LongRunning);
                Parallel.ForEach <RectInt32>(rect.GetTiles(TilingStrategy.Tiles, 7), delegate(RectInt32 newTileRect) {
                    ISurface <ColorBgra> surface = newLayer.Surface.CreateWindow(newTileRect);
                    IRenderer <ColorAlpha8> mask = new ClippedRenderer <ColorAlpha8>(newClipMaskRenderer, newTileRect);
                    surface.MultiplyAlphaChannel(mask);
                });
                document2.Layers.Add(newLayer);
                task.Wait();
                if (document2.Layers.Count > count)
                {
                    ExceptionUtil.ThrowInternalErrorException("newDocument.Layers.Count > oldLayerCount");
                }
            }
            ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);

            mementos.Add(memento2);
            historyWorkspace.Document = document2;
            return(HistoryMemento.Combine(HistoryMementoName, HistoryMementoImage, mementos));
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count)
            {
                throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" +
                                            layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")");
            }

            int       bottomLayerIndex = this.layerIndex - 1;
            Rectangle bounds           = historyWorkspace.Document.Bounds;
            PdnRegion region           = new PdnRegion(bounds);

            BitmapHistoryMemento bhm = new BitmapHistoryMemento(
                null,
                null,
                historyWorkspace,
                bottomLayerIndex,
                region);

            BitmapLayer topLayer    = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex];
            RenderArgs  bottomRA    = new RenderArgs(bottomLayer.Surface);

            EnterCriticalRegion();

            topLayer.Render(bottomRA, region);
            bottomLayer.Invalidate();

            bottomRA.Dispose();
            bottomRA = null;

            region.Dispose();
            region = null;

            DeleteLayerFunction dlf  = new DeleteLayerFunction(this.layerIndex);
            HistoryMemento      dlhm = dlf.Execute(historyWorkspace);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm });

            return(chm);
        }
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (this.layerIndex < 1 || this.layerIndex >= historyWorkspace.Document.Layers.Count)
            {
                throw new ArgumentException("layerIndex must be greater than or equal to 1, and a valid layer index. layerIndex=" + 
                    layerIndex + ", allowableRange=[0," + historyWorkspace.Document.Layers.Count + ")");
            }

            int bottomLayerIndex = this.layerIndex - 1;
            Rectangle bounds = historyWorkspace.Document.Bounds;
            PdnRegion region = new PdnRegion(bounds);

            BitmapHistoryMemento bhm = new BitmapHistoryMemento(
                null,
                null,
                historyWorkspace,
                bottomLayerIndex,
                region);

            BitmapLayer topLayer = (BitmapLayer)historyWorkspace.Document.Layers[this.layerIndex];
            BitmapLayer bottomLayer = (BitmapLayer)historyWorkspace.Document.Layers[bottomLayerIndex];
            RenderArgs bottomRA = new RenderArgs(bottomLayer.Surface);

            EnterCriticalRegion();

            topLayer.Render(bottomRA, region);
            bottomLayer.Invalidate();

            bottomRA.Dispose();
            bottomRA = null;

            region.Dispose();
            region = null;

            DeleteLayerFunction dlf = new DeleteLayerFunction(this.layerIndex);
            HistoryMemento dlhm = dlf.Execute(historyWorkspace);

            CompoundHistoryMemento chm = new CompoundHistoryMemento(StaticName, StaticImage, new HistoryMemento[] { bhm, dlhm });
            return chm;
        }