示例#1
0
        protected unsafe override void OnFillRegionComputed(IBitVector2D stencil)
        {
            Document     doc  = PintaCore.Workspace.ActiveDocument;
            ImageSurface surf = doc.ToolLayer.Surface;

            using (var g = new Context(surf)) {
                g.Operator = Operator.Source;
                g.SetSource(doc.CurrentUserLayer.Surface);
                g.Paint();
            }

            SimpleHistoryItem hist = new SimpleHistoryItem(Icon, Name);

            hist.TakeSnapshotOfLayer(doc.CurrentUserLayer);

            ColorBgra  color  = fill_color.ToColorBgra().ToPremultipliedAlpha();
            ColorBgra *dstPtr = (ColorBgra *)surf.DataPtr;
            int        width  = surf.Width;

            surf.Flush();

            // Color in any pixel that the stencil says we need to fill
            Parallel.For(0, stencil.Height, y =>
            {
                int stencil_width = stencil.Width;
                for (int x = 0; x < stencil_width; ++x)
                {
                    if (stencil.GetUnchecked(x, y))
                    {
                        surf.SetColorBgraUnchecked(dstPtr, width, color, x, y);
                    }
                }
            });

            surf.MarkDirty();

            // Transfer the temp layer to the real one,
            // respecting any selection area
            using (var g = doc.CreateClippedContext()) {
                g.Operator = Operator.Source;
                g.SetSource(surf);
                g.Paint();
            }

            doc.ToolLayer.Clear();

            doc.History.PushNewItem(hist);
            doc.Workspace.Invalidate();
        }