コード例 #1
0
    public static BitmapLayer DecodeImage(PsdFile psdFile)
    {
      BitmapLayer layer = PaintDotNet.Layer.CreateBackgroundLayer(psdFile.Columns, psdFile.Rows);

      Surface surface = layer.Surface;
      surface.Clear((ColorBgra)0xffffffff);

      for (int y = 0; y < psdFile.Rows; y++)
      {
        unsafe
        {
          int rowIndex = y * psdFile.RowPixels;

          ColorBgra* dstRow = surface.GetRowAddress(y);
          ColorBgra* dstPixel = dstRow;

          for (int x = 0; x < psdFile.Columns; x++)
          {
            int pos = rowIndex + x;
            SetPDNColor(dstPixel, psdFile, pos);
            dstPixel++;
          }
        }
      }

      return layer;
    }
コード例 #2
0
        public MoveToolContentRenderer(BitmapLayer activeLayer, MoveToolChanges changes, Result <IRenderer <ColorAlpha8> > lazyDeltaSelectionMask, Result <IRenderer <ColorAlpha8> > lazyFinalSelectionMask) : base(activeLayer.Width, activeLayer.Height, false)
        {
            Validate.Begin().IsNotNull <BitmapLayer>(activeLayer, "activeLayer").IsNotNull <MoveToolChanges>(changes, "changes").IsNotNull <Result <IRenderer <ColorAlpha8> > >(lazyDeltaSelectionMask, "lazyDeltaSelectionMask").IsNotNull <Result <IRenderer <ColorAlpha8> > >(lazyFinalSelectionMask, "lazyFinalSelectionMask").Check();
            this.activeLayer            = activeLayer;
            this.changes                = changes;
            this.lazyDeltaSelectionMask = lazyDeltaSelectionMask;
            this.lazyFinalSelectionMask = lazyFinalSelectionMask;
            switch (changes.PixelSource)
            {
            case MoveToolPixelSource.ActiveLayer:
                this.source = activeLayer.Surface;
                break;

            case MoveToolPixelSource.Bitmap:
                this.source = changes.BitmapSource.Object;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <MoveToolPixelSource>(changes.PixelSource, "changes.PixelSource");
            }
            Matrix3x2Double matrix = changes.DeltaTransform * changes.EditTransform;

            if ((changes.MoveToolResamplingAlgorithm == ResamplingAlgorithm.NearestNeighbor) || changes.FinalTransform.IsIntegerTranslation)
            {
                this.sourceTx = new TransformedNearestNeighborContentRenderer(activeLayer.Size(), this.source, matrix);
            }
            else
            {
                RectDouble baseBounds        = changes.BaseBounds;
                RectInt32  srcCoverageBounds = changes.BaseTransform.Transform(baseBounds).Int32Bound;
                this.sourceTx = new TransformedBilinearContentRenderer(activeLayer.Size(), this.source, srcCoverageBounds, matrix);
            }
        }
コード例 #3
0
ファイル: CloneStampTool.cs プロジェクト: ykafia/Paint.Net4
        protected override IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > CreateContentRenderers(BitmapLayer layer, CloneStampToolChanges changes)
        {
            BitmapLayer           layer        = (BitmapLayer)this.Document.Layers[changes.SourceLayerIndex];
            IRenderer <ColorBgra> sampleSource = layer.Surface;

            yield return(new CloneStampToolContentRenderer(sampleSource, changes));
        }
コード例 #4
0
        /// <summary>
        /// Store layer metadata and image data.
        /// </summary>
        public static void StoreLayer(BitmapLayer layer,
                                      PhotoshopFile.Layer psdLayer, PsdSaveConfigToken psdToken)
        {
            // Set layer metadata
            psdLayer.Name               = layer.Name;
            psdLayer.Rect               = FindImageRectangle(layer.Surface);
            psdLayer.BlendModeKey       = PsdBlendMode.Normal;
            psdLayer.Opacity            = layer.Opacity;
            psdLayer.Visible            = layer.Visible;
            psdLayer.Masks              = new MaskInfo();
            psdLayer.BlendingRangesData = new BlendingRanges(psdLayer);

            // Store channel metadata
            int layerSize = psdLayer.Rect.Width * psdLayer.Rect.Height;

            for (int i = -1; i < 3; i++)
            {
                var ch = new Channel((short)i, psdLayer);
                ch.ImageCompression = psdToken.RleCompress ? ImageCompression.Rle : ImageCompression.Raw;
                ch.ImageData        = new byte[layerSize];
                psdLayer.Channels.Add(ch);
            }

            // Store and compress channel image data
            var channelsArray = psdLayer.Channels.ToIdArray();

            StoreLayerImage(channelsArray, psdLayer.AlphaChannel, layer.Surface, psdLayer.Rect);
        }
コード例 #5
0
        public static unsafe void Save(Document input, Stream output, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback)
        {
            bool           rle         = token.GetProperty <PaintDotNet.PropertySystem.BooleanProperty>(PropertyNames.RLE).Value;
            AbrFileVersion fileVersion = (AbrFileVersion)token.GetProperty(PropertyNames.FileVersion).Value;

            double progressPercentage = 0.0;
            double progressDelta      = (1.0 / input.Layers.Count) * 100.0;

            using (BinaryReverseWriter writer = new BinaryReverseWriter(output, true))
            {
                writer.Write((short)fileVersion);
                writer.Write((short)input.Layers.Count);

                foreach (Layer item in input.Layers)
                {
                    BitmapLayer layer = (BitmapLayer)item;

                    SaveLayer(writer, layer, fileVersion, rle);

                    progressPercentage += progressDelta;

                    progressCallback(null, new ProgressEventArgs(progressPercentage));
                }
            }
        }
コード例 #6
0
        public static unsafe Document Load(Stream input)
        {
            Document doc = null;

            using (DdsNative.DdsImage image = DdsNative.Load(input))
            {
                doc = new Document(image.Width, image.Height);

                BitmapLayer layer = Layer.CreateBackgroundLayer(image.Width, image.Height);

                Surface surface = layer.Surface;

                for (int y = 0; y < surface.Height; ++y)
                {
                    byte *     src = image.GetRowAddressUnchecked(y);
                    ColorBgra *dst = surface.GetRowAddressUnchecked(y);

                    for (int x = 0; x < surface.Width; ++x)
                    {
                        dst->R = src[0];
                        dst->G = src[1];
                        dst->B = src[2];
                        dst->A = src[3];

                        src += 4;
                        ++dst;
                    }
                }

                doc.Layers.Add(layer);
            }

            return(doc);
        }
コード例 #7
0
ファイル: EraserTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnActivate()
        {
            base.OnActivate();

            // cursor-transitions
            this.cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.EraserToolCursor.cur"));
            this.cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.EraserToolCursorMouseDown.cur"));
            this.Cursor = cursorMouseUp;

            this.savedRects = new List<Rectangle>();

            if (ActiveLayer != null)
            {
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs = new RenderArgs(bitmapLayer.Surface);
            }
            else
            {
                bitmapLayer = null;
                renderArgs = null;
            }

            this.previewRenderer = new BrushPreviewRenderer(this.RendererList);
            this.RendererList.Add(this.previewRenderer, false);
        }
コード例 #8
0
        private BitmapLayerToolLayerOverlay <TTool, TChanges> CreateLayerOverlay(BitmapLayer layer, TChanges changes)
        {
            IRenderer <ColorAlpha8> renderer;
            RectInt32 num;

            this.tool.VerifyAccess <TTool>();
            if (this.autoClipToSelection)
            {
                this.GetDefaultContentClip(changes, out num, out renderer);
            }
            else
            {
                this.tool.GetContentClip(changes, out num, out renderer);
            }
            ContentBlendMode blendMode = this.tool.GetBlendMode(changes);
            IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.tool.CreateContentRenderers(layer, changes);

            if (contentRenderers == null)
            {
                ExceptionUtil.ThrowInternalErrorException("OnCreateContentRenderer() returned null");
            }
            RectInt32 maxRenderBounds = changes.GetMaxRenderBounds();

            return(new BitmapLayerToolLayerOverlay <TTool, TChanges>(layer, RectInt32.Intersect(layer.Bounds(), RectInt32.Intersect(num, maxRenderBounds)), changes, blendMode, contentRenderers, renderer));
        }
コード例 #9
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return(null);
            }

            PdnRegion   region           = historyWorkspace.Selection.CreateRegion();
            BitmapLayer layer            = ((BitmapLayer)historyWorkspace.ActiveLayer);
            PdnRegion   simplifiedRegion = Utility.SimplifyAndInflateRegion(region);

            HistoryMemento hm = new BitmapHistoryMemento(
                StaticName,
                StaticImage,
                historyWorkspace,
                historyWorkspace.ActiveLayerIndex,
                simplifiedRegion);

            EnterCriticalRegion();

            layer.Surface.Clear(region, this.fillColor);
            layer.Invalidate(simplifiedRegion);

            simplifiedRegion.Dispose();
            region.Dispose();

            return(hm);
        }
コード例 #10
0
ファイル: EraserTool.cs プロジェクト: leejungho2/xynotecgui
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            if (cursorMouseUp != null)
            {
                cursorMouseUp.Dispose();
                cursorMouseUp = null;
            }

            if (cursorMouseDown != null)
            {
                cursorMouseDown.Dispose();
                cursorMouseDown = null;
            }

            if (mouseDown)
            {
                OnMouseUp(new MouseEventArgs(mouseButton, 0, lastMouseXY.X, lastMouseXY.Y, 0));
            }

            this.RendererList.Remove(this.previewRenderer);
            this.previewRenderer.Dispose();
            this.previewRenderer = null;

            this.savedRects.Clear();

            if (renderArgs != null)
            {
                renderArgs.Dispose();
                renderArgs = null;
            }

            bitmapLayer = null;
        }
コード例 #11
0
        protected override void OnActivate()
        {
            base.OnActivate();

            this.pencilToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.PencilToolCursor.cur"));
            this.Cursor           = this.pencilToolCursor;

            this.savedRects = new List <Rectangle>();

            if (ActiveLayer != null)
            {
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs  = new RenderArgs(bitmapLayer.Surface);
                tracePoints = new List <Point>();
            }
            else
            {
                bitmapLayer = null;

                if (renderArgs != null)
                {
                    renderArgs.Dispose();
                    renderArgs = null;
                }
            }
        }
コード例 #12
0
        public RecolorToolContentRenderer(BitmapLayer activeLayer, RecolorToolChanges changes) : base(activeLayer.Width, activeLayer.Height, changes)
        {
            IRenderer <ColorAlpha8> renderer2;

            this.sampleSource = activeLayer.Surface;
            byte x         = (byte)Math.Round((double)(changes.Tolerance * 255.0), MidpointRounding.AwayFromZero);
            byte tolerance = ByteUtil.FastScale(x, x);

            if (changes.SamplingMode == RecolorToolSamplingMode.SecondaryColor)
            {
                this.basisColor = changes.BasisColor;
            }
            else
            {
                this.basisColor = GetBasisColor(changes, this.sampleSource);
            }
            IRenderer <ColorAlpha8> stencilSource = new FillStencilByColorRenderer(this.sampleSource, this.basisColor, tolerance, this);

            if (changes.Antialiasing)
            {
                renderer2 = new FeatheredMaskRenderer(this.sampleSource, changes.BasisColor, stencilSource, tolerance, this);
            }
            else
            {
                renderer2 = stencilSource;
            }
            IRenderer <ColorAlpha8> first = changes.RenderCache.CreateMaskRenderer(activeLayer.Size(), this);

            this.maskRenderer = new MultiplyRendererAlpha8(first, renderer2);
        }
コード例 #13
0
ファイル: PencilTool.cs プロジェクト: cyberjaxx/OpenPDN
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (mouseDown)
            {
                return;
            }

            if (((e.Button & MouseButtons.Left) == MouseButtons.Left) ||
                ((e.Button & MouseButtons.Right) == MouseButtons.Right))
            {
                mouseDown   = true;
                mouseButton = e.Button;
                tracePoints = new List <Point>();
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs  = new RenderArgs(bitmapLayer.Surface);

                clipRegion?.Dispose();
                clipRegion = null;

                clipRegion = Selection.CreateRegion();
                renderArgs.Graphics.SetClip(clipRegion.GetRegionReadOnly(), CombineMode.Replace);
                OnMouseMove(e);
            }
        }
コード例 #14
0
        protected override HistoryMemento OnUndo(ProgressEventHandler progressCallback)
        {
            BitmapHistoryMementoData data = base.Data as BitmapHistoryMementoData;
            BitmapLayer layer             = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];

            RectInt32[]          savedRegion = data.SavedRegion;
            MaskedSurface        surface     = null;
            BitmapHistoryMemento memento     = new BitmapHistoryMemento(base.Name, base.Image, this.historyWorkspace, this.layerIndex, savedRegion);

            if (surface != null)
            {
                surface.Draw(layer.Surface);
            }
            else
            {
                using (FileStream stream = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Read))
                {
                    LoadSurfaceRegion(stream, layer.Surface, data.SavedRegion);
                }
                this.tempFileHandle.Dispose();
                this.tempFileHandle = null;
            }
            if (savedRegion.Length != 0)
            {
                RectInt32 roi = savedRegion.Bounds();
                layer.Invalidate(roi);
            }
            return(memento);
        }
コード例 #15
0
        private Document OnLoadImpl(Stream input)
        {
            WmpBitmapDecoder wbd    = new WmpBitmapDecoder(input, BitmapCreateOptions.None, BitmapCacheOption.None);
            BitmapFrame      frame0 = wbd.Frames[0];

            Document output = new Document(frame0.PixelWidth, frame0.PixelHeight);

            output.DpuUnit = MeasurementUnit.Inch;
            output.DpuX    = frame0.DpiX;
            output.DpuY    = frame0.DpiY;

            BitmapLayer layer       = Layer.CreateBackgroundLayer(output.Width, output.Height);
            MemoryBlock memoryBlock = layer.Surface.Scan0;
            IntPtr      scan0       = memoryBlock.Pointer;

            FormatConvertedBitmap fcb = new FormatConvertedBitmap(frame0, System.Windows.Media.PixelFormats.Bgra32, null, 0);

            fcb.CopyPixels(Int32Rect.Empty, scan0, (int)memoryBlock.Length, layer.Surface.Stride);
            output.Layers.Add(layer);

            BitmapMetadata hdMetadata = (BitmapMetadata)frame0.Metadata;

            CopyMetadataTo(output.Metadata, hdMetadata);

            // WPF doesn't give us an IDisposable implementation on its types
            Utility.GCFullCollect();

            return(output);
        }
コード例 #16
0
        protected override Document OnLoad(Stream input)
        {
            DdsFile file = new DdsFile();

            file.Load(input);
            BitmapLayer layer   = Layer.CreateBackgroundLayer(file.GetWidth(), file.GetHeight());
            Surface     surface = layer.Surface;
            ColorBgra   bgra    = new ColorBgra();

            byte[] pixelData = file.GetPixelData();
            for (int i = 0; i < file.GetHeight(); i++)
            {
                for (int j = 0; j < file.GetWidth(); j++)
                {
                    int index = ((i * file.GetWidth()) * 4) + (j * 4);
                    bgra.R        = pixelData[index];
                    bgra.G        = pixelData[index + 1];
                    bgra.B        = pixelData[index + 2];
                    bgra.A        = pixelData[index + 3];
                    surface[j, i] = bgra;
                }
            }
            Document document = new Document(surface.Width, surface.Height);

            document.Layers.Add(layer);
            return(document);
        }
コード例 #17
0
        protected override void OnActivate()
        {
            base.OnActivate();

            cursorMouseDown          = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur"));
            cursorMouseDownSetSource = new Cursor(PdnResources.GetResourceStream("Cursors.CloneStampToolCursorSetSource.cur"));
            cursorMouseUp            = new Cursor(PdnResources.GetResourceStream("Cursors.CloneStampToolCursor.cur"));
            this.Cursor = cursorMouseUp;

            this.rendererDst = new BrushPreviewRenderer(this.RendererList);
            this.RendererList.Add(this.rendererDst, false);

            this.rendererSrc = new BrushPreviewRenderer(this.RendererList);
            this.rendererSrc.BrushLocation = GetStaticData().takeFrom;
            this.rendererSrc.BrushSize     = AppEnvironment.PenInfo.Width / 2.0f;
            this.rendererSrc.Visible       = (GetStaticData().takeFrom != Point.Empty);
            this.RendererList.Add(this.rendererSrc, false);

            if (ActiveLayer != null)
            {
                switchedTo   = true;
                historyRects = new Vector <Rectangle>();

                if (GetStaticData().wr != null && GetStaticData().wr.IsAlive)
                {
                    takeFromLayer = (BitmapLayer)GetStaticData().wr.Target;
                }
                else
                {
                    takeFromLayer = null;
                }
            }

            AppEnvironment.PenInfoChanged += new EventHandler(Environment_PenInfoChanged);
        }
コード例 #18
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (!this.QueryCanExecute(historyWorkspace))
            {
                return(null);
            }
            HistoryMemento          memento                    = this.OnPreRender(historyWorkspace);
            int                     activeLayerIndex           = historyWorkspace.ActiveLayerIndex;
            BitmapLayer             activeLayer                = (BitmapLayer)historyWorkspace.ActiveLayer;
            RectInt32               num2                       = activeLayer.Bounds();
            RectDouble              bounds                     = historyWorkspace.Selection.GetCachedClippingMask().Bounds;
            IRenderer <ColorAlpha8> cachedClippingMaskRenderer = historyWorkspace.Selection.GetCachedClippingMaskRenderer(historyWorkspace.ToolSettings.Selection.RenderingQuality.Value);
            IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers = this.OnCreateContentRenderers(historyWorkspace, num2.Width, num2.Height);
            ContentBlendMode    contentBlendMode = this.GetContentBlendMode();
            ContentRendererBgra renderer         = new ContentRendererBgra(activeLayer.Surface, contentBlendMode, contentRenderers, cachedClippingMaskRenderer);

            base.EnterCriticalRegion();
            HistoryMemento memento2 = new ApplyRendererToBitmapLayerHistoryFunction(this.HistoryMementoName, this.HistoryMementoImage, activeLayerIndex, renderer, bounds.Int32Bound, 4, 0x7d0, ActionFlags.None).Execute(historyWorkspace);
            HistoryMemento memento3 = this.OnPostRender(historyWorkspace);

            HistoryMemento[] items   = new HistoryMemento[] { memento, memento2, memento3 };
            HistoryMemento[] actions = ArrayUtil.Infer <HistoryMemento>(items).WhereNotNull <HistoryMemento>().ToArrayEx <HistoryMemento>();
            if (actions.Length == 0)
            {
                return(null);
            }
            return(new CompoundHistoryMemento(this.HistoryMementoName, this.HistoryMementoImage, actions));
        }
コード例 #19
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 }));
        }
コード例 #20
0
ファイル: PencilTool.cs プロジェクト: metadeta96/openpdn
        protected override void OnActivate()
        {
            base.OnActivate();

            this.pencilToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.PencilToolCursor.cur"));
            this.Cursor = this.pencilToolCursor;

            this.savedRects = new List<Rectangle>();

            if (ActiveLayer != null)
            {
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs = new RenderArgs(bitmapLayer.Surface);
                tracePoints = new List<Point>();
            }
            else
            {
                bitmapLayer = null;

                if (renderArgs != null)
                {
                    renderArgs.Dispose();
                    renderArgs = null;
                }
            }
        }
コード例 #21
0
ファイル: WsqFileType.cs プロジェクト: zkscar/Delta.Imaging
        protected override Document OnLoad(Stream input)
        {
            if (input == null || input.Length == 0)
            {
                return(null);
            }
            var length = input.Length;
            var bytes  = new byte[length];

            input.ProperRead(bytes, 0, (int)length);

            var dec = new WsqDecoder();

            using (var bitmap = dec.DecodeGdi(bytes))
            {
                var surface = new Surface(bitmap.Width, bitmap.Height);
                surface.CopyFromGdipBitmap(bitmap);

                var layer    = new BitmapLayer(surface);
                var document = new Document(layer.Width, layer.Height);

                document.Layers.Add(layer);

                document.DpuUnit = MeasurementUnit.Inch;
                document.DpuX    = (double)bitmap.HorizontalResolution;
                document.DpuY    = (double)bitmap.VerticalResolution;

                return(document);
            }
        }
コード例 #22
0
ファイル: PencilTool.cs プロジェクト: metadeta96/openpdn
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            if (this.pencilToolCursor != null)
            {
                this.pencilToolCursor.Dispose();
                this.pencilToolCursor = null;
            }

            if (mouseDown)
            {
                Point lastTracePoint = (Point)tracePoints[tracePoints.Count - 1];
                OnMouseUp(new MouseEventArgs(mouseButton, 0, lastTracePoint.X, lastTracePoint.Y, 0));
            }

            this.savedRects = null;
            this.tracePoints = null;
            this.bitmapLayer = null;

            if (this.renderArgs != null)
            {
                this.renderArgs.Dispose();
                this.renderArgs = null;
            }

            this.mouseDown = false;

            if (clipRegion != null)
            {
                clipRegion.Dispose();
                clipRegion = null;
            }
        }
コード例 #23
0
ファイル: EraserTool.cs プロジェクト: leejungho2/xynotecgui
        protected override void OnActivate()
        {
            base.OnActivate();

            // cursor-transitions
            this.cursorMouseUp   = new Cursor(PdnResources.GetResourceStream("Cursors.EraserToolCursor.cur"));
            this.cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.EraserToolCursorMouseDown.cur"));
            this.Cursor          = cursorMouseUp;

            this.savedRects = new List <Rectangle>();

            if (ActiveLayer != null)
            {
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs  = new RenderArgs(bitmapLayer.Surface);
            }
            else
            {
                bitmapLayer = null;
                renderArgs  = null;
            }

            this.previewRenderer = new BrushPreviewRenderer(this.RendererList);
            this.RendererList.Add(this.previewRenderer, false);
        }
コード例 #24
0
ファイル: PencilTool.cs プロジェクト: cyberjaxx/OpenPDN
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            pencilToolCursor?.Dispose();
            pencilToolCursor = null;

            if (mouseDown)
            {
                Point lastTracePoint = (Point)tracePoints[tracePoints.Count - 1];
                OnMouseUp(new MouseEventArgs(mouseButton, 0, lastTracePoint.X, lastTracePoint.Y, 0));
            }

            this.savedRects  = null;
            this.tracePoints = null;
            this.bitmapLayer = null;

            renderArgs?.Dispose();
            renderArgs = null;

            this.mouseDown = false;

            clipRegion?.Dispose();
            clipRegion = null;
        }
コード例 #25
0
ファイル: DdsFileType.cs プロジェクト: smile-ttxp/Paint.NET
        protected override Document OnLoad(Stream input)
        {
            DdsFile ddsFile = new DdsFile();

            ddsFile.Load(input);

            BitmapLayer layer       = Layer.CreateBackgroundLayer(ddsFile.GetWidth(), ddsFile.GetHeight());
            Surface     surface     = layer.Surface;
            ColorBgra   writeColour = new ColorBgra();

            byte[] readPixelData = ddsFile.GetPixelData();

            for (int y = 0; y < ddsFile.GetHeight(); y++)
            {
                for (int x = 0; x < ddsFile.GetWidth(); x++)
                {
                    int readPixelOffset = (y * ddsFile.GetWidth() * 4) + (x * 4);

                    writeColour.R = readPixelData[readPixelOffset + 0];
                    writeColour.G = readPixelData[readPixelOffset + 1];
                    writeColour.B = readPixelData[readPixelOffset + 2];
                    writeColour.A = readPixelData[readPixelOffset + 3];

                    surface[x, y] = writeColour;
                }
            }

            // Create a document, add the surface layer to it, and return to caller.
            Document document = new Document(surface.Width, surface.Height);

            document.Layers.Add(layer);
            return(document);
        }
コード例 #26
0
        protected override void OnDeactivate()
        {
            AppEnvironment.ResamplingAlgorithmChanged -= AppEnvironment_ResamplingAlgorithmChanged;

            if (this.moveToolCursor != null)
            {
                this.moveToolCursor.Dispose();
                this.moveToolCursor = null;
            }

            if (context.lifted)
            {
                Drop();
            }

            this.activeLayer = null;

            if (this.renderArgs != null)
            {
                this.renderArgs.Dispose();
                this.renderArgs = null;
            }

            this.tracking = false;
            DestroyNubs();
            base.OnDeactivate();
        }
コード例 #27
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (!(ActiveLayer is BitmapLayer))
            {
                return;
            }

            Cursor = cursorMouseDown;

            if (IsMouseLeftDown(e))
            {
                this.rendererDst.Visible = false;

                if (IsCtrlDown())
                {
                    GetStaticData().takeFrom = new Point(e.X, e.Y);

                    this.rendererSrc.BrushLocation   = new Point(e.X, e.Y);
                    this.rendererSrc.BrushSize       = AppEnvironment.PenInfo.Width / 2.0f;
                    this.rendererSrc.Visible         = true;
                    GetStaticData().updateSrcPreview = false;

                    GetStaticData().wr        = new WeakReference(((BitmapLayer)ActiveLayer));
                    takeFromLayer             = (BitmapLayer)(GetStaticData().wr.Target);
                    GetStaticData().lastMoved = Point.Empty;
                    ra = new RenderArgs(((BitmapLayer)ActiveLayer).Surface);
                }
                else
                {
                    GetStaticData().updateSrcPreview = true;

                    // Determine if there is something to work if, if there isn't return
                    if (GetStaticData().takeFrom == Point.Empty)
                    {
                    }
                    else if (!GetStaticData().wr.IsAlive || takeFromLayer == null)
                    {
                        GetStaticData().takeFrom  = Point.Empty;
                        GetStaticData().lastMoved = Point.Empty;
                    }
                    // Make sure the layer is still there!
                    else if (takeFromLayer != null && !Document.Layers.Contains(takeFromLayer))
                    {
                        GetStaticData().takeFrom  = Point.Empty;
                        GetStaticData().lastMoved = Point.Empty;
                    }
                    else
                    {
                        this.antialiasing = AppEnvironment.AntiAliasing;
                        this.ra           = new RenderArgs(((BitmapLayer)ActiveLayer).Surface);
                        this.ra.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        OnMouseMove(e);
                    }
                }
            }
        }
コード例 #28
0
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            SegmentedList <HistoryMemento> items = new SegmentedList <HistoryMemento>();
            bool flag = true;

            if (flag && !documentWorkspace.Selection.IsEmpty)
            {
                HistoryMemento item = new DeselectFunction().Execute(documentWorkspace);
                items.Add(item);
            }
            if (flag && ((layer.Width > documentWorkspace.Document.Width) || (layer.Height > documentWorkspace.Document.Height)))
            {
                HistoryMemento memento3 = this.DoCanvasResize(documentWorkspace, layer.Size);
                if (memento3 == null)
                {
                    flag = false;
                }
                else
                {
                    items.Add(memento3);
                }
            }
            if (flag && (layer.Size != documentWorkspace.Document.Size))
            {
                BitmapLayer layer2;
                try
                {
                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        CleanupManager.RequestCleanup();
                        layer2 = CanvasSizeAction.ResizeLayer(layer, documentWorkspace.Document.Size, AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                    }
                }
                catch (OutOfMemoryException exception)
                {
                    ExceptionDialog.ShowErrorDialog(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"), exception);
                    flag   = false;
                    layer2 = null;
                }
                if (layer2 != null)
                {
                    layer.Dispose();
                    layer = layer2;
                }
            }
            if (flag)
            {
                NewLayerHistoryMemento memento4 = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                items.Add(memento4);
            }
            if (flag)
            {
                return(new CompoundHistoryMemento(string.Empty, null, items.ToArrayEx <HistoryMemento>()));
            }
            this.Rollback(items);
            return(null);
        }
コード例 #29
0
 public SaveLayerPixelsContext(BitmapLayer layer, PsdFile psdFile,
                               Document input, PhotoshopFile.Layer psdLayer, PsdSaveConfigToken psdToken)
 {
     this.layer    = layer;
     this.psdFile  = psdFile;
     this.input    = input;
     this.psdToken = psdToken;
     this.psdLayer = psdLayer;
 }
コード例 #30
0
        protected override HistoryMemento OnUndo(ProgressEventHandler progressCallback)
        {
            FlipLayerHistoryMemento memento = new FlipLayerHistoryMemento(base.Name, base.Image, this.historyWorkspace, this.layerIndex, this.flipType);
            BitmapLayer             layer   = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];

            FlipInPlace(layer.Surface, this.flipType);
            layer.Invalidate();
            return(memento);
        }
コード例 #31
0
 public BitmapLayerToolLayerOverlay(BitmapLayer layer, RectInt32 affectedBounds, TChanges changes, ContentBlendMode blendMode, IEnumerable <IMaskedRenderer <ColorBgra, ColorAlpha8> > contentRenderers, IRenderer <ColorAlpha8> clipMaskRenderer) : base(layer, affectedBounds)
 {
     Validate.IsNotNull <TChanges>(changes, "changes");
     this.changes          = changes;
     this.blendMode        = blendMode;
     this.contentRenderers = contentRenderers.ToArrayEx <IMaskedRenderer <ColorBgra, ColorAlpha8> >();
     this.clipMaskRenderer = clipMaskRenderer;
     this.renderer         = new ContentRendererBgra(base.Layer.Surface, this.blendMode, this.contentRenderers, this.clipMaskRenderer);
 }
コード例 #32
0
        /// <summary>
        /// Decodes the gray scale PixMap into a BitmapLayer.
        /// </summary>
        /// <param name="width">The width of the image.</param>
        /// <param name="height">The height of the image.</param>
        /// <param name="sixteenBit"><c>true</c> if the image data is 16 bits-per-channel; otherwise, <c>false</c>.</param>
        /// <returns>A BitmapLayer containing the decoded image.</returns>
        private unsafe BitmapLayer DecodeGrayScale(int width, int height, bool sixteenBit)
        {
            BitmapLayer layer     = null;
            BitmapLayer tempLayer = null;

            try
            {
                tempLayer = Layer.CreateBackgroundLayer(width, height);
                Surface surface = tempLayer.Surface;

                if (sixteenBit)
                {
                    byte[] map = CreateEightBitLookupTable();

                    for (int y = 0; y < height; y++)
                    {
                        ColorBgra *p = surface.GetRowAddressUnchecked(y);
                        for (int x = 0; x < width; x++)
                        {
                            ushort value = reader.ReadUInt16();
                            p->R = p->G = p->B = map[value];
                            p->A = 255;

                            p++;
                        }
                    }
                }
                else
                {
                    for (int y = 0; y < height; y++)
                    {
                        ColorBgra *p = surface.GetRowAddressUnchecked(y);
                        for (int x = 0; x < width; x++)
                        {
                            p->R = p->G = p->B = reader.ReadByte();
                            p->A = 255;

                            p++;
                        }
                    }
                }

                layer     = tempLayer;
                tempLayer = null;
            }
            finally
            {
                if (tempLayer != null)
                {
                    tempLayer.Dispose();
                    tempLayer = null;
                }
            }

            return(layer);
        }
コード例 #33
0
        private void RenderElement(SvgElement element, bool setOpacityForLayer,
                                   bool importHiddenLayers)
        {
            float opacity       = element.Opacity;
            var   visible       = true;
            var   visualElement = element as SvgVisualElement;

            if (visualElement != null)
            {
                visible = IsVisibleOriginally(visualElement);
                if (importHiddenLayers)
                {
                    // Set visible to render image and then item can be hidden.
                    visualElement.Visibility = "visible";
                }
                else if (!visible)
                {
                    // Hidden layers are ignored.
                    return;
                }
            }

            // Store opacity as layer options.
            if (setOpacityForLayer)
            {
                // Set full opacity when enabled to render 100%.
                // Anyway opacity will be set as paint layer options.
                if (element.Opacity > 0.01)
                {
                    element.Opacity = 1;
                }
            }

            BitmapLayer pdnLayer;

            pdnDocument = pdnDocument ?? new Document(width, height);
            using (Bitmap bmp = RenderSvgDocument())
                using (Surface surface = Surface.CopyFromBitmap(bmp))
                {
                    pdnLayer = new BitmapLayer(surface);
                }

            pdnLayer.Name = GetLayerTitle(element); //leg_left_top
            if (setOpacityForLayer)
            {
                pdnLayer.Opacity = (byte)(opacity * 255);
            }

            if (importHiddenLayers && visualElement != null)
            {
                pdnLayer.Visible = visible;
            }

            pdnDocument.Layers.Add(pdnLayer);
        }
コード例 #34
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            BitmapLayer newLayer = null;
            newLayer = new BitmapLayer(historyWorkspace.Document.Width, historyWorkspace.Document.Height);
            string newLayerNameFormat = PdnResources.GetString("AddNewBlankLayer.LayerName.Format");
            newLayer.Name = string.Format(newLayerNameFormat, (1 + historyWorkspace.Document.Layers.Count).ToString());

            NewLayerHistoryMemento ha = new NewLayerHistoryMemento(
                PdnResources.GetString("AddNewBlankLayer.HistoryMementoName"),
                ImageResource.Get("Icons.MenuLayersAddNewLayerIcon.png"),
                historyWorkspace,
                historyWorkspace.Document.Layers.Count);

            EnterCriticalRegion();
            historyWorkspace.Document.Layers.Add(newLayer);

            return ha;
        }
コード例 #35
0
ファイル: ResizeAction.cs プロジェクト: leejungho2/xynotecgui
 public static BitmapLayer ResizeLayer(BitmapLayer layer, int width, int height, ResamplingAlgorithm algorithm)
 {
     bool pleaseStop = false;
     return ResizeLayer(layer, width, height, algorithm, 0, null, ref pleaseStop);
 }
コード例 #36
0
ファイル: MoveTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnActivate()
        {
            AppEnvironment.ResamplingAlgorithmChanged += AppEnvironment_ResamplingAlgorithmChanged;

            this.moveToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.MoveToolCursor.cur"));
            this.Cursor = this.moveToolCursor;

            this.context.lifted = false;
            this.ourContext.LiftedPixels = null;
            this.context.offset = new Point(0, 0);
            this.context.liftedBounds = Selection.GetBoundsF();
            this.activeLayer = (BitmapLayer)ActiveLayer;

            if (this.renderArgs != null)
            {
                this.renderArgs.Dispose();
                this.renderArgs = null;
            }

            if (this.activeLayer == null)
            {
                this.renderArgs = null;
            }
            else
            {
                this.renderArgs = new RenderArgs(this.activeLayer.Surface);
            }

            this.tracking = false;
            PositionNubs(this.context.currentMode);

#if ALWAYSHIGHQUALITY
            this.fullQuality = true;
#endif

            base.OnActivate();
        }
コード例 #37
0
ファイル: PencilTool.cs プロジェクト: metadeta96/openpdn
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (mouseDown)
            {
                return;
            }

            if (((e.Button & MouseButtons.Left) == MouseButtons.Left) ||
                ((e.Button & MouseButtons.Right) == MouseButtons.Right))
            {
                mouseDown = true;
                mouseButton = e.Button;
                tracePoints = new List<Point>();
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs = new RenderArgs(bitmapLayer.Surface);

                if (clipRegion != null)
                {
                    clipRegion.Dispose();
                    clipRegion = null;
                }

                clipRegion = Selection.CreateRegion();
                renderArgs.Graphics.SetClip(clipRegion.GetRegionReadOnly(), CombineMode.Replace);
                OnMouseMove(e);
            }
        }
コード例 #38
0
ファイル: MoveTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnDeactivate()
        {
            AppEnvironment.ResamplingAlgorithmChanged -= AppEnvironment_ResamplingAlgorithmChanged;

            if (this.moveToolCursor != null)
            {
                this.moveToolCursor.Dispose();
                this.moveToolCursor = null;
            }

            if (context.lifted)
            {   
                Drop();
            }

            this.activeLayer = null;

            if (this.renderArgs != null)
            {
                this.renderArgs.Dispose();
                this.renderArgs = null;
            }

            this.tracking = false;
            DestroyNubs();
            base.OnDeactivate();
        }
コード例 #39
0
ファイル: EraserTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            if (cursorMouseUp != null)
            {
                cursorMouseUp.Dispose();
                cursorMouseUp = null;
            }

            if (cursorMouseDown != null)
            {
                cursorMouseDown.Dispose();
                cursorMouseDown = null;
            }
            
            if (mouseDown)
            {
                OnMouseUp(new MouseEventArgs(mouseButton, 0, lastMouseXY.X, lastMouseXY.Y, 0));
            }

            this.RendererList.Remove(this.previewRenderer);
            this.previewRenderer.Dispose();
            this.previewRenderer = null;

            this.savedRects.Clear();

            if (renderArgs != null)
            {
                renderArgs.Dispose();
                renderArgs = null;
            }

            bitmapLayer = null;
        }
コード例 #40
0
        public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace)
        {
            if (historyWorkspace.Selection.IsEmpty)
            {
                return null;
            }
            else
            {
                PdnRegion selectionRegion = historyWorkspace.Selection.CreateRegion();

                if (selectionRegion.GetArea() == 0)
                {
                    selectionRegion.Dispose();
                    return null;
                }

                SelectionHistoryMemento sha = new SelectionHistoryMemento(StaticName, null, historyWorkspace);
                ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(StaticName, null, historyWorkspace);
                Rectangle boundingBox;
                Rectangle[] inverseRegionRects = null;

                boundingBox = Utility.GetRegionBounds(selectionRegion);

                using (PdnRegion inverseRegion = new PdnRegion(boundingBox))
                {
                    inverseRegion.Exclude(selectionRegion);

                    inverseRegionRects = Utility.TranslateRectangles(
                        inverseRegion.GetRegionScansReadOnlyInt(),
                        -boundingBox.X,
                        -boundingBox.Y);
                }

                selectionRegion.Dispose();
                selectionRegion = null;

                Document oldDocument = historyWorkspace.Document; // TODO: serialize this to disk so we don't *have* to store the full thing
                Document newDocument = new Document(boundingBox.Width, boundingBox.Height);

                // copy the document's meta data over
                newDocument.ReplaceMetaDataFrom(oldDocument);

                foreach (Layer layer in oldDocument.Layers)
                {
                    if (layer is BitmapLayer)
                    {
                        BitmapLayer oldLayer = (BitmapLayer)layer;
                        Surface croppedSurface = oldLayer.Surface.CreateWindow(boundingBox);
                        BitmapLayer newLayer = new BitmapLayer(croppedSurface);

                        ColorBgra clearWhite = ColorBgra.White.NewAlpha(0);

                        foreach (Rectangle rect in inverseRegionRects)
                        {
                            newLayer.Surface.Clear(rect, clearWhite);
                        }

                        newLayer.LoadProperties(oldLayer.SaveProperties());
                        newDocument.Layers.Add(newLayer);
                    }
                    else
                    {
                        throw new InvalidOperationException("Crop does not support Layers that are not BitmapLayers");
                    }
                }

                CompoundHistoryMemento cha = new CompoundHistoryMemento(
                    StaticName,
                    PdnResources.GetImageResource("Icons.MenuImageCropIcon.png"),
                    new HistoryMemento[] { sha, rdha });

                EnterCriticalRegion();
                historyWorkspace.Document = newDocument;

                return cha;
            }
        }
コード例 #41
0
        private BitmapLayer RotateLayer(BitmapLayer layer, RotateType rotationType, int width, int height, double startProgress, double endProgress)
        {
            Surface surface = new Surface(width, height);

            if (rotationType == RotateType.Clockwise180 ||
                rotationType == RotateType.CounterClockwise180)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        surface[x, y] = layer.Surface[width - x - 1, height - y - 1];
                    }

                    OnProgress(((double)y / (double)height) * (endProgress - startProgress) + startProgress);
                }
            }
            else if (rotationType == RotateType.Clockwise270 ||
                     rotationType == RotateType.CounterClockwise90)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        surface[x, y] = layer.Surface[height - y - 1, x];
                    }

                    OnProgress(((double)y / (double)height) * (endProgress - startProgress) + startProgress);
                }
            }
            else if (rotationType == RotateType.Clockwise90 ||
                     rotationType == RotateType.CounterClockwise270)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        surface[x, y] = layer.Surface[y, width - 1 - x];
                    }

                    OnProgress(((double)y / (double)height) * (endProgress - startProgress) + startProgress);
                }
            }

            BitmapLayer returnMe = new BitmapLayer(surface, true);
            returnMe.LoadProperties(layer.SaveProperties());
            return returnMe;
        }
コード例 #42
0
ファイル: CloneStampTool.cs プロジェクト: nkaligin/paint-mono
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (!(ActiveLayer is BitmapLayer))
            {
                return;
            }

            Cursor = cursorMouseDown;

            if (IsMouseLeftDown(e))
            {
                this.rendererDst.Visible = false;

                if (IsCtrlDown())
                {
                    GetStaticData().takeFrom = new Point(e.X, e.Y);

                    this.rendererSrc.BrushLocation = new Point(e.X, e.Y);
                    this.rendererSrc.BrushSize = AppEnvironment.PenInfo.Width / 2.0f;
                    this.rendererSrc.Visible = true;
                    GetStaticData().updateSrcPreview = false;

                    GetStaticData().wr = new WeakReference(((BitmapLayer)ActiveLayer));
                    takeFromLayer = (BitmapLayer)(GetStaticData().wr.Target);
                    GetStaticData().lastMoved = Point.Empty;
                    ra = new RenderArgs(((BitmapLayer)ActiveLayer).Surface);
                }
                else
                {
                    GetStaticData().updateSrcPreview = true;

                    // Determine if there is something to work if, if there isn't return
                    if (GetStaticData().takeFrom == Point.Empty)
                    {
                    }
                    else if (!GetStaticData().wr.IsAlive || takeFromLayer == null)
                    {
                        GetStaticData().takeFrom = Point.Empty;
                        GetStaticData().lastMoved = Point.Empty;
                    }
                    // Make sure the layer is still there!
                    else if (takeFromLayer != null && !Document.Layers.Contains(takeFromLayer))
                    {
                        GetStaticData().takeFrom = Point.Empty;
                        GetStaticData().lastMoved = Point.Empty;
                    }
                    else
                    {
                        this.antialiasing = AppEnvironment.AntiAliasing;
                        this.ra = new RenderArgs(((BitmapLayer)ActiveLayer).Surface);
                        this.ra.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        OnMouseMove(e);
                    }
                }
            }
        }
コード例 #43
0
        public static BitmapLayer ResizeLayer(BitmapLayer layer, Size newSize, AnchorEdge anchor, ColorBgra background)
        {
            BitmapLayer newLayer = new BitmapLayer(newSize.Width, newSize.Height);

            // Background
            new UnaryPixelOps.Constant(background).Apply(newLayer.Surface, newLayer.Surface.Bounds);

            // non-background = clear the alpha channel (see-through)
            if (!layer.IsBackground)
            {
                new UnaryPixelOps.SetAlphaChannel(0).Apply(newLayer.Surface, newLayer.Surface.Bounds);
            }

            int topY = 0;
            int leftX = 0;
            int rightX = newSize.Width - layer.Width;
            int bottomY = newSize.Height - layer.Height;
            int middleX = (newSize.Width - layer.Width) / 2;
            int middleY = (newSize.Height - layer.Height) / 2;

            int x = 0;
            int y = 0;

            #region choose x,y from AnchorEdge
            switch (anchor)
            {
                case AnchorEdge.TopLeft:
                    x = leftX;
                    y = topY;
                    break;

                case AnchorEdge.Top:
                    x = middleX;
                    y = topY;
                    break;

                case AnchorEdge.TopRight:
                    x = rightX;
                    y = topY;
                    break;

                case AnchorEdge.Left:
                    x = leftX;
                    y = middleY;
                    break;

                case AnchorEdge.Middle:
                    x = middleX;
                    y = middleY;
                    break;

                case AnchorEdge.Right:
                    x = rightX;
                    y = middleY;
                    break;

                case AnchorEdge.BottomLeft:
                    x = leftX;
                    y = bottomY;
                    break;

                case AnchorEdge.Bottom:
                    x = middleX;
                    y = bottomY;
                    break;

                case AnchorEdge.BottomRight:
                    x = rightX;
                    y = bottomY;
                    break;
            }
            #endregion

            newLayer.Surface.CopySurface(layer.Surface, new Point(x, y));
            newLayer.LoadProperties(layer.SaveProperties());
            return newLayer;
        }
コード例 #44
0
ファイル: RecoloringTool.cs プロジェクト: metadeta96/openpdn
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            if (mouseDown)
            {
                OnMouseUp(new MouseEventArgs(mouseButton, 0, lastMouseXY.X, lastMouseXY.Y, 0));
            }

            this.RendererList.Remove(this.previewRenderer);
            this.previewRenderer.Dispose();
            this.previewRenderer = null;

            if (savedSurfaces != null)
            {
                if (savedSurfaces != null)
                {
                    foreach (PlacedSurface ps in savedSurfaces)
                    {
                        ps.Dispose();
                    }
                }

                savedSurfaces.Clear();
                savedSurfaces = null;
            }

            renderArgs.Dispose();;
            renderArgs = null;

            aaPoints = null;
            renderArgs = null;
            bitmapLayer = null;

            if (clipRegion != null)
            {
                clipRegion.Dispose();
                clipRegion = null;
            }


            if (cursorMouseUp != null)
            {
                cursorMouseUp.Dispose();
                cursorMouseUp = null;
            }

            if (cursorMouseDown != null)
            {
                cursorMouseDown.Dispose();
                cursorMouseDown = null;
            }

            if (cursorMouseDownPickColor != null)
            {
                cursorMouseDownPickColor.Dispose();
                cursorMouseDownPickColor = null;
            }

            if (cursorMouseDownAdjustColor != null)
            {
                cursorMouseDownAdjustColor.Dispose();
                cursorMouseDownAdjustColor = null;
            }
        }
コード例 #45
0
        private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer)
        {
            HistoryMemento retHA;
            List<HistoryMemento> historyMementos = new List<HistoryMemento>();
            bool success = true;

            if (success)
            {
                if (!documentWorkspace.Selection.IsEmpty)
                {
                    HistoryMemento ha = new DeselectFunction().Execute(documentWorkspace);
                    historyMementos.Add(ha);
                }
            }

            if (success)
            {
                if (layer.Width > documentWorkspace.Document.Width ||
                    layer.Height > documentWorkspace.Document.Height)
                {
                    HistoryMemento ha = DoCanvasResize(documentWorkspace, layer.Size);

                    if (ha == null)
                    {
                        success = false;
                    }
                    else
                    {
                        historyMementos.Add(ha);
                    }
                }
            }

            if (success)
            {
                if (layer.Size != documentWorkspace.Document.Size)
                {
                    BitmapLayer newLayer;

                    try
                    {
                        using (new WaitCursorChanger(documentWorkspace))
                        {
                            Utility.GCFullCollect();

                            newLayer = CanvasSizeAction.ResizeLayer((BitmapLayer)layer, documentWorkspace.Document.Size,
                                AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0));
                        }
                    }

                    catch (OutOfMemoryException)
                    {
                        Utility.ErrorBox(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"));
                        success = false;
                        newLayer = null;
                    }

                    if (newLayer != null)
                    {
                        layer.Dispose();
                        layer = newLayer;
                    }
                }
            }

            if (success)
            {
                NewLayerHistoryMemento nlha = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count);
                documentWorkspace.Document.Layers.Add(layer);
                historyMementos.Add(nlha);
            }

            if (success)
            {
                HistoryMemento[] has = historyMementos.ToArray();
                retHA = new CompoundHistoryMemento(string.Empty, null, has);
            }
            else
            {
                Rollback(historyMementos);
                retHA = null;
            }

            return retHA;
        }
コード例 #46
0
ファイル: ResizeAction.cs プロジェクト: leejungho2/xynotecgui
        private static BitmapLayer ResizeLayer(BitmapLayer layer, int width, int height, ResamplingAlgorithm algorithm,
            int tileCount, Procedure progressCallback, ref bool pleaseStopMonitor)
        {
            Surface surface = new Surface(width, height);
            surface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

            PaintDotNet.Threading.ThreadPool threadPool = new PaintDotNet.Threading.ThreadPool();
            int rectCount;

            if (tileCount == 0)
            {
                rectCount = Processor.LogicalCpuCount;
            }
            else
            {
                rectCount = tileCount;
            }

            Rectangle[] rects = new Rectangle[rectCount];
            Utility.SplitRectangle(surface.Bounds, rects);

            FitSurfaceContext fsc = new FitSurfaceContext(surface, layer.Surface, rects, algorithm);

            if (progressCallback != null)
            {
                fsc.RenderedRect += progressCallback;
            }

            WaitCallback callback = new WaitCallback(fsc.FitSurface);

            for (int i = 0; i < rects.Length; ++i)
            {
                if (pleaseStopMonitor)
                {
                    break;
                }
                else
                {
                    threadPool.QueueUserWorkItem(callback, BoxedConstants.GetInt32(i));
                }
            }

            threadPool.Drain();
            threadPool.DrainExceptions();

            if (pleaseStopMonitor)
            {
                surface.Dispose();
                surface = null;
            }

            BitmapLayer newLayer;

            if (surface == null)
            {
                newLayer = null;
            }
            else
            {
                newLayer = new BitmapLayer(surface, true);
                newLayer.LoadProperties(layer.SaveProperties());
            }

            if (progressCallback != null)
            {
                fsc.RenderedRect -= progressCallback;
            }

            return newLayer;
        }
コード例 #47
0
ファイル: CloneStampTool.cs プロジェクト: nkaligin/paint-mono
        protected override void OnActivate()
        {
            base.OnActivate();

            cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur"));
            cursorMouseDownSetSource = new Cursor(PdnResources.GetResourceStream("Cursors.CloneStampToolCursorSetSource.cur"));
            cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.CloneStampToolCursor.cur"));
            this.Cursor = cursorMouseUp;

            this.rendererDst = new BrushPreviewRenderer(this.RendererList);
            this.RendererList.Add(this.rendererDst, false);

            this.rendererSrc = new BrushPreviewRenderer(this.RendererList);
            this.rendererSrc.BrushLocation = GetStaticData().takeFrom;
            this.rendererSrc.BrushSize = AppEnvironment.PenInfo.Width / 2.0f;
            this.rendererSrc.Visible = (GetStaticData().takeFrom != Point.Empty);
            this.RendererList.Add(this.rendererSrc, false);

            if (ActiveLayer != null)
            {
                switchedTo = true;
                historyRects = new Vector<Rectangle>();

                if (GetStaticData().wr != null && GetStaticData().wr.IsAlive)
                {
                    takeFromLayer = (BitmapLayer)GetStaticData().wr.Target;
                }
                else
                {
                    takeFromLayer = null;
                }
            }

            AppEnvironment.PenInfoChanged += new EventHandler(Environment_PenInfoChanged);
        }
コード例 #48
0
ファイル: ShapeTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnDeactivate()
        {
            base.OnDeactivate();

            if (mouseDown)
            {
                PointF lastPoint = (PointF)points[points.Count - 1];
                OnStylusUp(new StylusEventArgs(mouseButton, 0, lastPoint.X, lastPoint.Y, 0));
            }

            if (!this.shapeWasCommited)
            {
                CommitShape();
            }

            bitmapLayer = null;

            if (renderArgs != null)
            {
                renderArgs.Dispose();
                renderArgs = null;
            }

            if (outlineSaveRegion != null)
            {
                outlineSaveRegion.Dispose();
                outlineSaveRegion = null;
            }

            if (interiorSaveRegion != null)
            {
                interiorSaveRegion.Dispose();
                interiorSaveRegion = null;
            }

            points = null;
        }
コード例 #49
0
ファイル: RecoloringTool.cs プロジェクト: metadeta96/openpdn
        protected override void OnActivate()
        {
            base.OnActivate();

            // initialize any state information you need
            cursorMouseUp = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursor.cur"));
            cursorMouseDown = new Cursor(PdnResources.GetResourceStream("Cursors.GenericToolCursorMouseDown.cur"));
            cursorMouseDownPickColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorPickColor.cur"));
            cursorMouseDownAdjustColor = new Cursor(PdnResources.GetResourceStream("Cursors.RecoloringToolCursorAdjustColor.cur"));

            this.previewRenderer = new BrushPreviewRenderer(this.RendererList);
            this.RendererList.Add(this.previewRenderer, false);

            Cursor = cursorMouseUp;
            mouseDown = false;

            // fetch colors from workspace palette
            this.colorToReplace = this.AppEnvironment.PrimaryColor;
            this.colorReplacing = this.AppEnvironment.SecondaryColor;

            this.aaPoints = this.ScratchSurface;
            this.isPointAlreadyAA = new BitVector2D(aaPoints.Width, aaPoints.Height);

            if (savedSurfaces != null)
            {
                foreach (PlacedSurface ps in savedSurfaces)
                {
                    ps.Dispose();
                }
            }

            savedSurfaces = new ArrayList();

            if (ActiveLayer != null)
            {
                bitmapLayer = (BitmapLayer)ActiveLayer;
                renderArgs = new RenderArgs(bitmapLayer.Surface);
            }
            else
            {
                bitmapLayer = null;
                renderArgs = null;
            }
        }
コード例 #50
0
ファイル: ShapeTool.cs プロジェクト: herbqiao/paint.net
        protected override void OnActivate()
        {
            base.OnActivate();

            outlineSaveRegion = null;
            interiorSaveRegion = null;

            // creates a bitmap layer from the active layer
            bitmapLayer = (BitmapLayer)ActiveLayer;

            // create Graphics object
            renderArgs = new RenderArgs(bitmapLayer.Surface);

            lastDrawnRegion = new PdnRegion();
            lastDrawnRegion.MakeEmpty();
        }