Пример #1
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.thickness = newToken.GetProperty<Int32Property>(PropertyNames.Thickness).Value;
            this.intensity = newToken.GetProperty<Int32Property>(PropertyNames.Intensity).Value;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #2
0
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            Point[] points = ((MotionBlurEffectConfigToken)parameters).LinePoints;
            Surface dst = dstArgs.Surface;
            Surface src = srcArgs.Surface;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y);

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        Point a = new Point(x + points[0].X, y + points[0].Y);
                        Point b = new Point(x + points[points.Length - 1].X, y + points[points.Length - 1].Y);

                        // If both ends of this line are in bounds, we don't need to do silly clipping
                        if (src.Bounds.Contains(a) && src.Bounds.Contains(b))
                        {
                            *dstPtr = DoLineAverageUnclipped(points, x, y, dst, src);
                        }
                        else
                        {
                            *dstPtr = DoLineAverage(points, x, y, dst, src);
                        }

                        ++dstPtr;
                    }
                }
            }
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            using (PdnGraphicsPath path = new PdnGraphicsPath())
            {
                path.AddPolygons(polygonSet);

                using (PdnRegion fillRegion = new PdnRegion(path))
                {
                    Rectangle boundingBox = fillRegion.GetBoundsInt();

                    Surface surface = ((BitmapLayer)ActiveLayer).Surface;
                    RenderArgs ra = new RenderArgs(surface);
                    HistoryMemento ha;

                    using (PdnRegion affected = Utility.SimplifyAndInflateRegion(fillRegion))
                    {
                        ha = new BitmapHistoryMemento(Name, Image, DocumentWorkspace, DocumentWorkspace.ActiveLayerIndex, affected);
                    }

                    ra.Graphics.CompositingMode = AppEnvironment.GetCompositingMode();
                    ra.Graphics.FillRegion(brush, fillRegion.GetRegionReadOnly());

                    HistoryStack.PushNewMemento(ha);
                    ActiveLayer.Invalidate(boundingBox);
                    Update();
                }
            }
        }
Пример #6
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, System.Drawing.Rectangle[] rois, int startIndex, int length)
        {
            TwoAmountsConfigToken tact = (TwoAmountsConfigToken)parameters;
            PixelOp redEyeRemove = new UnaryPixelOps.RedEyeRemove(tact.Amount1, tact.Amount2);

            redEyeRemove.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length);
        }
        public BackgroundEffectRenderer(Effect effect,
            EffectConfigToken effectToken,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            PdnRegion renderRegion,
            int tileCount,
            int workerThreads)
        {
            this.effect = effect;
            this.effectToken = effectToken;
            this.dstArgs = dstArgs;
            this.srcArgs = srcArgs;
            this.renderRegion = renderRegion;
            this.renderRegion.Intersect(dstArgs.Bounds);
            this.tileRegions = SliceUpRegion(renderRegion, tileCount, dstArgs.Bounds);

            this.tilePdnRegions = new PdnRegion[this.tileRegions.Length];
            for (int i = 0; i < this.tileRegions.Length; ++i)
            {
                PdnRegion pdnRegion = Utility.RectanglesToRegion(this.tileRegions[i]);
                this.tilePdnRegions[i] = pdnRegion;
            }

            this.tileCount = tileCount;
            this.workerThreads = workerThreads;

            if ((effect.EffectDirectives & EffectDirectives.SingleThreaded) != 0)
            {
                this.workerThreads = 1;
            }

            this.threadPool = new Threading.ThreadPool(this.workerThreads, false);
        }
Пример #8
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            lock (this)
            {
                SetRenderInfo(parameters, dstArgs, srcArgs);
            }

            this.gbEffect.Render(this.gbToken, dstArgs, srcArgs, rois, startIndex, length);
        }
Пример #9
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     if (mesh != null)
     {
         for (int i = startIndex; i < startIndex + length; ++i)
         {
             mesh.Render(dstArgs.Surface, srcArgs.Surface, rois[i]);
         }
     }
 }
Пример #10
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int fragments = newToken.GetProperty<Int32Property>(PropertyNames.Fragments).Value;
            double rotation = newToken.GetProperty<DoubleProperty>(PropertyNames.Rotation).Value;
            int distance = newToken.GetProperty<Int32Property>(PropertyNames.Distance).Value;

            RecalcPointOffsets(fragments, rotation, distance);

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #11
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface surface, ProgressEventHandler callback)
        {
            // Do save operation...

            RenderArgs ra = new RenderArgs(new Surface(input.Size));

            input.Render(ra, true);

            ra.Bitmap.Save(output, System.Drawing.Imaging.ImageFormat.Png);
        }
Пример #12
0
 public override sealed void Render(Surface dst, Point offset)
 {
     if (ShouldRender())
     {
         using (var ra = new RenderArgs(dst))
         {
             RenderToGraphics(ra.Graphics, offset);
         }
     }
 }
Пример #13
0
        protected override sealed void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.token   = (TToken)parameters;
            this.dstArgs = dstArgs;
            this.srcArgs = srcArgs;

            this.OnSetRenderInfo((TToken)parameters, dstArgs, srcArgs);

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
Пример #14
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.zoom = newToken.GetProperty<DoubleProperty>(PropertyNames.Zoom).Value;
            this.quality = newToken.GetProperty<Int32Property>(PropertyNames.Quality).Value;
            this.angle = newToken.GetProperty<DoubleProperty>(PropertyNames.Angle).Value;
            this.angleTheta = (this.angle * Math.PI * 2) / 360.0;
            this.factor = newToken.GetProperty<DoubleProperty>(PropertyNames.Factor).Value;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #15
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token,
            Surface scratchSurface, ProgressEventHandler callback)
        {
            using (RenderArgs ra = new RenderArgs(new Surface(input.Size)) {

            

            }
            
        }
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            BrightnessAndContrastAdjustmentConfigToken token = (BrightnessAndContrastAdjustmentConfigToken)parameters;
            int contrast   = token.Contrast;
            int brightness = token.Brightness;
            int multiply   = token.Multiply;
            int divide     = token.Divide;

            byte[] rgbTable = token.RgbTable;

            for (int r = startIndex; r < startIndex + length; ++r)
            {
                Rectangle rect = rois[r];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    ColorBgra *srcRowPtr    = srcArgs.Surface.GetPointAddress(rect.Left, y);
                    ColorBgra *dstRowPtr    = dstArgs.Surface.GetPointAddress(rect.Left, y);
                    ColorBgra *dstRowEndPtr = dstRowPtr + rect.Width;

                    if (divide == 0)
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col = *srcRowPtr;
                            int       i   = col.GetIntensityByte();
                            uint      c   = rgbTable[i];
                            dstRowPtr->Bgra = (col.Bgra & 0xff000000) | c | (c << 8) | (c << 16);

                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                    else
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col        = *srcRowPtr;
                            int       i          = col.GetIntensityByte();
                            int       shiftIndex = i * 256;

                            col.R = rgbTable[shiftIndex + col.R];
                            col.G = rgbTable[shiftIndex + col.G];
                            col.B = rgbTable[shiftIndex + col.B];

                            *dstRowPtr = col;
                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                }
            }

            return;
        }
Пример #17
0
        //        public new OpenTK.Vector3d Position { get { return -base.Position; } set { base.Position = value; } }
        //        
        //        public new OpenTK.Vector3d Rotation { get { return - base.Rotation; } set { base.Rotation = value; } }
        //        public static AutoTraceSource Trace = AutoTraceSource.GetOrCreate(AsyncXmlFileTraceListener.GetOrCreate("JGL"));
        /// <summary>
        /// Initializes a new instance of the <see cref="JGL.Heirarchy.Camera"/> class.
        /// </summary>
        /// <param name='name'>Camera's entity name</param>
        //        public Camera(string name)
        //            : base(name)
        //        {
        //        }
        /// <summary>
        /// Render owner <see cref="JGL.Heirarchy.Scene"/> using the perspective of this <see cref="JGL.Heirarchy.Camera"/>,
        /// </summary>
        /// <param name='renderArgs'>Render arguments.</param>
        /// <remarks>IRenderable implementation</remarks>
        public void Render(RenderArgs renderArgs)
        {
            Stack<Entity> entityStack = renderArgs.Entities;
            if (entityStack.Count > 0)
                throw new InvalidOperationException("RenderArgs.Entities stack should be empty when calling Camera.Render");
            entityStack.Push(renderArgs.Scene);

            GL.Rotate(-Rotation.X, 1, 0, 0);
            GL.Rotate(-Rotation.Y, 0, 1, 0);
            GL.Rotate(-Rotation.Z, 0, 0, 1);
            GL.Translate(-Position);

            bool[] eFlags = new bool[4];
            while (entityStack.Count > 0)
            {
                Entity entity = entityStack.Pop();
                if (entity == null)									// check for null values in the stack; they are markers that indicate that an EntityContext's
                    GL.PopMatrix();						// child Entities have just finished rendering, so the context's position/rotation changes can be reversed
                else
                {
                    eFlags[0] = entity is IRenderable && entity != this && entity.GetType() != typeof(Camera) && entity.GetType() != typeof(Scene) && !entity.GetType().IsSubclassOf(typeof(Scene));		//!entity.GetType().IsSubclassOf(typeof(Camera)); 		// if e == this, this is the current execution of e as Irenderable.Render so don't want to call itself again
                    eFlags[1] = entity is EntityContext;
            //					if (eFlags[0] || eFlags[1])					// if entity is not renderable and does not contains child entities, no point translating right?
            //					{
                    eFlags[2] = entity is IPositionable && entity.GetType() != typeof(Camera);		//!entity.GetType().IsSubclassOf(typeof(Camera));
                    eFlags[3] = entity is IRotatable && entity.GetType() != typeof(Camera);		//!entity.GetType().IsSubclassOf(typeof(Camera));
                    if (eFlags[2] || eFlags[3])
                    {
                        GL.PushMatrix();
                        if (eFlags[2])							// (e is IPositionable)
                            GL.Translate((entity as IPositionable).Position);
                        if (eFlags[3])							// (e is IRotatable)
                        {
                            IRotatable ir = entity as IRotatable;
                            GL.Rotate(ir.Rotation.X, 1, 0, 0);
                            GL.Rotate(ir.Rotation.Y, 0, 1, 0);
                            GL.Rotate(ir.Rotation.Z, 0, 0, 1);
                        }
                    }

                    if (eFlags[0])								// (e is IRenderable)
                        (entity as IRenderable).Render(renderArgs);
                    if (eFlags[1])								// (e is EntityContext)
                    {
                        if (eFlags[2] || eFlags[3])			// only need to worry about popping the GL matrix stack if something has been pushed on it (ie this EntityContext must be IPositionable or IRotatable)
                            entityStack.Push(null);				// marks location in the stack where the GL modelview matrix should be popped (after rendering a EntityContext's child Entities which were pushed immediately before this marker)
                        foreach (Entity _e in (entity as EntityContext))
                            entityStack.Push(_e);				// Push this EntityContext's child Entities (if any) onto the stack, so they will be next to be rendered (while the modelview matrix has been set by the containg EntityContext)
                    }
                    else if (eFlags[2] || eFlags[3])		// Entity is not an EntityContext (so can't have child Entities), but it is IPositionable and/or IRotatable so the modelview matrix has been pushed. Because no children, can pop it immediately
                            GL.PopMatrix();
            //					}
                }
            }
        }
Пример #18
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            PDNPresetsConfigToken token = (PDNPresetsConfigToken)parameters;

            this.effects = token.effects;
            this.dialogs = token.dialogs;

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);

            needReRender = true;
        }
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            BrightnessAndContrastAdjustmentConfigToken token = (BrightnessAndContrastAdjustmentConfigToken)parameters;
            int contrast = token.Contrast;
            int brightness = token.Brightness;
            int multiply = token.Multiply;
            int divide = token.Divide;
            byte[] rgbTable = token.RgbTable;

            for (int r = startIndex; r < startIndex + length; ++r)
            {
                Rectangle rect = rois[r];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    ColorBgra *srcRowPtr = srcArgs.Surface.GetPointAddress(rect.Left, y);
                    ColorBgra *dstRowPtr = dstArgs.Surface.GetPointAddress(rect.Left, y);
                    ColorBgra *dstRowEndPtr = dstRowPtr + rect.Width;

                    if (divide == 0)
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col = *srcRowPtr;
                            int i = col.GetIntensityByte();
                            uint c = rgbTable[i];
                            dstRowPtr->Bgra = (col.Bgra & 0xff000000) | c | (c << 8) | (c << 16);

                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                    else
                    {
                        while (dstRowPtr < dstRowEndPtr)
                        {
                            ColorBgra col = *srcRowPtr;
                            int i = col.GetIntensityByte();
                            int shiftIndex = i * 256;

                            col.R = rgbTable[shiftIndex + col.R];
                            col.G = rgbTable[shiftIndex + col.G];
                            col.B = rgbTable[shiftIndex + col.B];

                            *dstRowPtr = col;
                            ++dstRowPtr;
                            ++srcRowPtr;
                        }
                    }
                }
            }

            return;
        }
Пример #20
0
 // Draws a point, but first intersects it with the selection
 private void DrawPoint(RenderArgs ra, Point p, ColorBgra color)
 {
     if (ra.Surface.Bounds.Contains(p))
     {
         if (ra.Graphics.IsVisible(p))
         {
             BinaryPixelOp op = AppEnvironment.AlphaBlending ? blendOp : copyOp;
             ra.Surface[p.X, p.Y] = op.Apply(ra.Surface[p.X, p.Y], color);
         }
     }
 }
Пример #21
0
        public override void Render(GraphicsContext context, RenderArgs renderArgs)
        {
            var renderer = _currentRenderer;

            if (renderer == null)
            {
                return;
            }

            renderer?.Render(renderArgs, Location, false);
        }
Пример #22
0
        public override unsafe void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs,
                                           Rectangle[] rois, int startIndex, int length)
        {
            TwoAmountsConfigToken tact = (TwoAmountsConfigToken)parameters;
            int dev = tact.Amount1 * tact.Amount1 / 64; //dev = target stddev / 16
            int sat = tact.Amount2 * 4096 / 100;

            if (threadRand == null)
            {
                threadRand = new Random(unchecked (System.Threading.Thread.CurrentThread.GetHashCode() ^
                                                   unchecked ((int)DateTime.Now.Ticks)));
            }

            Random localRand = threadRand;

            int[] localLookup = lookup;

            for (int ri = startIndex; ri < startIndex + length; ++ri)
            {
                Rectangle rect = rois[ri];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    ColorBgra *srcPtr = srcArgs.Surface.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *dstPtr = dstArgs.Surface.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = 0; x < rect.Width; ++x)
                    {
                        int r;
                        int g;
                        int b;
                        int i;

                        r = localLookup[localRand.Next(tableSize)];
                        g = localLookup[localRand.Next(tableSize)];
                        b = localLookup[localRand.Next(tableSize)];

                        i = (1867 * r + 9618 * g + 4899 * b) >> 14;

                        r = i + (((r - i) * sat) >> 12);
                        g = i + (((g - i) * sat) >> 12);
                        b = i + (((b - i) * sat) >> 12);

                        dstPtr->R = Utility.ClampToByte(srcPtr->R + ((r * dev * 16 + 32768) >> 16));
                        dstPtr->G = Utility.ClampToByte(srcPtr->G + ((g * dev * 16 + 32768) >> 16));
                        dstPtr->B = Utility.ClampToByte(srcPtr->B + ((b * dev * 16 + 32768) >> 16));
                        dstPtr->A = srcPtr->A;

                        ++srcPtr;
                        ++dstPtr;
                    }
                }
            }
        }
Пример #23
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            lock (this)
            {
                this.gbToken = new PropertyBasedEffectConfigToken(this.gbProps);
                this.gbToken.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, ((AmountEffectConfigToken)parameters).Amount);
                this.gbEffect.SetRenderInfo(this.gbToken, dstArgs, srcArgs);
            }

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
        protected override void OnSetRenderInfo(
            PropertyBasedEffectConfigToken newToken,
            RenderArgs dstArgs,
            RenderArgs srcArgs)
        {
            _colorChart            = (ColorChart)newToken.GetProperty <StaticListChoiceProperty>(PropertyNames.ColorChart).Value;
            _includeSecondaryColor = newToken.GetProperty <BooleanProperty>(PropertyNames.IncludeSecondaryColor).Value;
            _colorMap = ComputeColorMap();

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #25
0
        private static unsafe void RenderWithClipMask(
            Effect effect,
            EffectConfigToken token,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            Rectangle[] rois,
            IRenderer <ColorAlpha8> clipMaskRenderer)
        {
            // Render the effect
            effect.Render(token, dstArgs, srcArgs, rois);

            if (effect.IsCancelRequested)
            {
                return;
            }

            if (clipMaskRenderer != null)
            {
                RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32();

                if (bounds.HasPositiveArea)
                {
                    // dstArgs = (srcArgs * (1 - clipMask)) + (dstArgs * clipMask)
                    // TODO: optimize, or at least refactor into its own method
                    using (ISurface <ColorAlpha8> clipMask = clipMaskRenderer.UseTileOrToSurface(bounds))
                    {
                        int width  = bounds.Width;
                        int height = bounds.Height;
                        int left   = bounds.Left;
                        int top    = bounds.Top;
                        int bottom = bounds.Bottom;

                        int dstStride      = dstArgs.Surface.Stride;
                        int srcStride      = srcArgs.Surface.Stride;
                        int clipMaskStride = clipMask.Stride;

                        ColorBgra *dstNextRowPtr      = dstArgs.Surface.GetPointAddress(left, top);
                        ColorBgra *srcNextRowPtr      = srcArgs.Surface.GetPointAddress(left, top);
                        byte *     clipMaskNextRowPtr = (byte *)clipMask.Scan0;

                        int rows = height;
                        while (rows > 0)
                        {
                            ColorBgra.Underwrite(srcNextRowPtr, dstNextRowPtr, clipMaskNextRowPtr, width);

                            dstNextRowPtr      = (ColorBgra *)((byte *)dstNextRowPtr + dstStride);
                            srcNextRowPtr      = (ColorBgra *)((byte *)srcNextRowPtr + srcStride);
                            clipMaskNextRowPtr = clipMaskNextRowPtr + clipMaskStride;
                            --rows;
                        }
                    }
                }
            }
        }
Пример #26
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     if (this.renderProofingTransform)
     {
         this.colorManagement.ApplyProofingTransformBGRA8(srcArgs.Surface, dstArgs.Surface, rois, startIndex, length);
     }
     else
     {
         dstArgs.Surface.CopySurface(srcArgs.Surface, rois, startIndex, length);
     }
 }
Пример #27
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     if (length == 0)
     {
         return;
     }
     for (int i = startIndex; i < startIndex + length; ++i)
     {
         Render(dstArgs.Surface, srcArgs.Surface, rois[i]);
     }
 }
Пример #28
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

            using (RenderArgs ra = new RenderArgs(scratchSurface))
            {
                input.Render(ra, true);
            }

            SaveTga(scratchSurface, output, token, callback);
        }
Пример #29
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            lock (this)
            {
                this.gbToken = new PropertyBasedEffectConfigToken(this.gbProps);
                this.gbToken.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, ((AmountEffectConfigToken)parameters).Amount);
                this.gbEffect.SetRenderInfo(this.gbToken, dstArgs, srcArgs);
            }

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
Пример #30
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            if (dialog != null && dialog.DialogResult == System.Windows.Forms.DialogResult.None)
            {
                changed = true;
                dstArgs.Surface.CopySurface(srcArgs.Surface);

                dialog.ClearProgressBars();
            }
            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
Пример #31
0
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            TwoAmountsConfigToken token = (TwoAmountsConfigToken)parameters;

            this.percentile = token.Amount2;

            foreach (Rectangle rect in rois)
            {
                RenderRect(token.Amount1, srcArgs.Surface, dstArgs.Surface, rect);
            }
        }
Пример #32
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     if (filterparsed)
     {
         ffparse.Render(enviromentDataHandle, rois, startIndex, length, dstArgs.Surface);
     }
     else
     {
         dstArgs.Surface.CopySurface(srcArgs.Surface, rois, startIndex, length);
     }
 }
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            margin  = newToken.GetProperty <Int32Property>(PropertyNames.Margin).Value;
            spread  = newToken.GetProperty <Int32Property>(PropertyNames.Spread).Value;
            blur    = newToken.GetProperty <Int32Property>(PropertyNames.Blur).Value;
            color   = ColorBgra.FromUInt32(unchecked ((uint)newToken.GetProperty <Int32Property>(PropertyNames.Color).Value));
            offsetX = newToken.GetProperty <Int32Property>(PropertyNames.OffsetX).Value;
            offsetY = newToken.GetProperty <Int32Property>(PropertyNames.OffsetY).Value;

            if (shadowSurface == null)
            {
                shadowSurface = new Surface(srcArgs.Surface.Size);
            }
            else
            {
                shadowSurface.Clear(Color.Transparent);
            }

            // Setup for calling the Gaussian Blur effect
            PropertyCollection             blurProps      = blurEffect.CreatePropertyCollection();
            PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps);

            BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, blur);
            blurEffect.SetRenderInfo(BlurParameters, dstArgs, new RenderArgs(shadowSurface));

            Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();

            PointF topStart    = new PointF(selection.Left, selection.Top + (margin + spread + offsetY) / 2f);
            PointF topEnd      = new PointF(selection.Right, selection.Top + (margin + spread + offsetY) / 2f);
            PointF rightStart  = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Top);
            PointF rightEnd    = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Bottom);
            PointF bottomStart = new PointF(selection.Left, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF bottomEnd   = new PointF(selection.Right, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF leftStart   = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Top);
            PointF leftEnd     = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Bottom);

            using (Graphics shadow = new RenderArgs(shadowSurface).Graphics)
                using (Pen shadowPen = new Pen(color))
                {
                    shadowPen.Width = margin + spread + offsetX;
                    shadow.DrawLine(shadowPen, leftStart, leftEnd);

                    shadowPen.Width = margin + spread - offsetX;
                    shadow.DrawLine(shadowPen, rightStart, rightEnd);

                    shadowPen.Width = margin + spread + offsetY;
                    shadow.DrawLine(shadowPen, topStart, topEnd);

                    shadowPen.Width = margin + spread - offsetY;
                    shadow.DrawLine(shadowPen, bottomStart, bottomEnd);
                }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #34
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (!ScanningAndPrinting.CanPrint)
            {
                Utility.ShowWiaError(documentWorkspace);
                return(null);
            }

            using (new PushNullToolMode(documentWorkspace))
            {
                // render image to a bitmap, save it to disk
                Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()");

                try
                {
                    scratch.Clear();
                    RenderArgs ra = new RenderArgs(scratch);

                    documentWorkspace.Update();

                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        ra.Surface.Clear(ColorBgra.White);
                        documentWorkspace.Document.Render(ra, false);
                    }

                    string tempName = Path.GetTempFileName() + ".bmp";
                    ra.Bitmap.Save(tempName, ImageFormat.Bmp);

                    try
                    {
                        ScanningAndPrinting.Print(documentWorkspace, tempName);
                    }

                    catch (Exception ex)
                    {
                        Utility.ShowWiaError(documentWorkspace);
                        Tracing.Ping(ex.ToString());
                        // TODO: do a "better" error dialog here
                    }

                    // Try to delete the temp file but don't worry if we can't
                    bool result = FileSystem.TryDeleteFile(tempName);
                }

                finally
                {
                    documentWorkspace.ReturnScratchSurface(scratch);
                }
            }

            return(null);
        }
Пример #35
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            if (parameters is CurvesEffectConfigToken token)
            {
                UnaryPixelOp uop = token.Uop;

                for (int i = startIndex; i < startIndex + length; ++i)
                {
                    uop.Apply(dstArgs.Surface, srcArgs.Surface, rois[i]);
                }
            }
        }
Пример #36
0
        public void DrawArea(RenderArgs ra, Point offset)
        {
            if (_surface == null)
            {
                return;
            }

            if (_renderContext == null ||
                (_renderContext.Windows != null && _renderContext.Windows.Length != Processor.LogicalCpuCount))
            {
                _renderContext = new RenderContext {
                    Owner = this
                };
                _renderContext.WaitCallback = _renderContext.RenderThreadMethod;
                _renderContext.Windows      = new Surface[Processor.LogicalCpuCount];
                _renderContext.Offsets      = new Point[Processor.LogicalCpuCount];
                _renderContext.Rects        = new Rectangle[Processor.LogicalCpuCount];
            }

            Utility.SplitRectangle(ra.Bounds, _renderContext.Rects);



            for (int i = 0; i < _renderContext.Rects.Length; ++i)
            {
                var rect = _renderContext.Rects[i];
                if (rect.Width > 0 && rect.Height > 0)
                {
                    _renderContext.Offsets[i] = new Point(rect.X + offset.X, rect.Y + offset.Y);
                    if (_renderContext.Windows != null)
                    {
                        _renderContext.Windows[i] = ra.Surface.CreateWindow(rect);
                    }
                }
                else
                {
                    if (_renderContext.Windows != null)
                    {
                        _renderContext.Windows[i] = null;
                    }
                }
            }

            for (int i = 0; i < _renderContext.Windows.Length; ++i)
            {
                if (_renderContext.Windows[i] != null)
                {
                    this._threadPool.QueueTask(_renderContext.WaitCallback, BoxedConstants.GetInt32(i));
                }
            }

            this._threadPool.Drain();
        }
Пример #37
0
        /// <summary>
        /// Causes the layer to render a given region of interest (roi) to the given destination surface.
        /// </summary>
        /// <param name="args">Contains information about which objects to use for rendering</param>
        /// <param name="roi">The region to be rendered.</param>
        public void Render(RenderArgs args, GeometryRegion roi)
        {
            Rectangle roiBounds = roi.GetBoundsInt();

            if (!IsInBounds(roiBounds))
            {
                throw new ArgumentOutOfRangeException("roi");
            }

            Rectangle[] rects = roi.GetRegionScansReadOnlyInt();
            RenderImpl(args, rects);
        }
Пример #38
0
 /// <summary>
 /// This is a helper function. It allows you to render an effect "in place."
 /// That is, you don't need both a destination and a source Surface.
 /// </summary>
 public void RenderInPlace(RenderArgs srcAndDstArgs, PdnRegion roi)
 {
     using (Surface renderSurface = new Surface(srcAndDstArgs.Surface.Size))
     {
         using (RenderArgs renderArgs = new RenderArgs(renderSurface))
         {
             Rectangle[] scans = roi.GetRegionScansReadOnlyInt();
             Render(null, renderArgs, srcAndDstArgs, scans);
             srcAndDstArgs.Surface.CopySurface(renderSurface, roi);
         }
     }
 }
Пример #39
0
        public override HistoryMemento PerformAction(DocumentWorkspace documentWorkspace)
        {
            if (!ScanningAndPrinting.CanPrint)
            {
                Utility.ShowWiaError(documentWorkspace);
                return null;
            }

            using (new PushNullToolMode(documentWorkspace))
            {
                // render image to a bitmap, save it to disk
                Surface scratch = documentWorkspace.BorrowScratchSurface(this.GetType().Name + ".PerformAction()");

                try
                {
                    scratch.Clear();
                    RenderArgs ra = new RenderArgs(scratch);

                    documentWorkspace.Update();

                    using (new WaitCursorChanger(documentWorkspace))
                    {
                        ra.Surface.Clear(ColorBgra.White);
                        documentWorkspace.Document.Render(ra, false);
                    }

                    string tempName = Path.GetTempFileName() + ".bmp";
                    ra.Bitmap.Save(tempName, ImageFormat.Bmp);

                    try
                    {
                        ScanningAndPrinting.Print(documentWorkspace, tempName);
                    }

                    catch (Exception ex)
                    {
                        Utility.ShowWiaError(documentWorkspace);
                        Tracing.Ping(ex.ToString());
                        // TODO: do a "better" error dialog here
                    }

                    // Try to delete the temp file but don't worry if we can't
                    bool result = FileSystem.TryDeleteFile(tempName);
                }

                finally
                {
                    documentWorkspace.ReturnScratchSurface(scratch);
                }
            }

            return null;
        }
Пример #40
0
 public override void Render(RenderArgs arg)
 {
     /*var context = Device.Context;
      *
      * // Setup state
      * ((Dx11RenderingSwapChain)arg.RenderTarget).Bind();
      * Device.TestShader.Apply(context, arg.StateBuffer);
      * context.InputAssembler.SetVertexBuffers(0, VertexBufferBindings);
      *
      * // Render
      * context.Draw(3, 0);*/
 }
Пример #41
0
        protected override void OnRender(ISurface <ColorBgra> dstCropped, PointInt32 renderOffset)
        {
            RectInt32 num = this.Bounds <ColorBgra>();

            using (RenderArgs args = new RenderArgs(dstCropped))
            {
                args.Graphics.Clear(Color.Transparent);
                this.sourceOutset.Render(dstCropped, renderOffset);
                args.Graphics.TranslateTransform((float)-renderOffset.X, (float)-renderOffset.Y, MatrixOrder.Append);
                DropShadow.DrawInside(args.Graphics, new Rectangle(0, 0, base.Width, base.Height), this.shadowExtent);
            }
        }
Пример #42
0
 public static void Save(Document input, Stream output, Surface scratchSurface, System.Drawing.Imaging.ImageFormat format, ProgressEventHandler callback)
 {
     scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0));
     using (RenderArgs args = new RenderArgs(scratchSurface))
     {
         input.Render(args, true);
     }
     using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
     {
         LoadProperties(bitmap, input);
         bitmap.Save(output, format);
     }
 }
Пример #43
0
 protected override void doProvide(RenderArgs ra)
 {
     if (sh != null)
     {
         Shader.Bind(sh);
     }
     callCommands(); // lets call the commands
     FullscreenQuad.render(null, Target.Width, Target.Height);
     if (sh != null)
     {
         Shader.Unbind();
     }
 }
Пример #44
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            PSFilterPdnConfigToken token = (PSFilterPdnConfigToken)parameters;

            if (token.Dest != null)
            {
                dstArgs.Surface.CopySurface(token.Dest, rois, startIndex, length);
            }
            else
            {
                dstArgs.Surface.CopySurface(srcArgs.Surface, rois, startIndex, length);
            }
        }
Пример #45
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            CurvesEffectConfigToken token = parameters as CurvesEffectConfigToken;

            if (token != null)
            {
                UnaryPixelOp uop = token.Uop;

                for (int i = startIndex; i < startIndex + length; ++i)
                {
                    uop.Apply(dstArgs.Surface, srcArgs.Surface, rois[i]);
                }
            }
        }
Пример #46
0
        public unsafe override void Render(
            EffectConfigToken parameters,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            Rectangle[] rois,
            int startIndex,
            int length)
        {
            AmountEffectConfigToken token = (AmountEffectConfigToken)parameters;

            foreach (Rectangle rect in rois)
            {
                RenderRect(token.Amount, srcArgs.Surface, dstArgs.Surface, rect);
            }
        }
Пример #47
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            CloudEffectConfigToken token = (CloudEffectConfigToken)parameters;
            PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds);

            this.r1 = token.R1;
            this.r2 = token.R2;
            this.r3 = token.R3;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        if (selectionRegion.IsVisible(x, y))
                        {
                            ColorBgra srcBgra = srcArgs.Surface[x, y];
                            byte c = (byte)(PerlinNoise2d(x, y, token) * 255);

                            switch (token.DisplayOption)
                            {
                                case CloudEffect.REPLACE_SOURCE:
                                    dstArgs.Surface[x, y] = ColorBgra.FromBgra(srcBgra.B, srcBgra.G, srcBgra.R, c);
                                    break;
                                case CloudEffect.OVERLAY_PRIMARY:
                                    ColorBgra primary = (ColorBgra)EnvironmentParameters.ForeColor;
                                    dstArgs.Surface[x, y] = ColorBgra.FromBgra(primary.B, primary.G, primary.R, c);
                                    break;
                                case CloudEffect.OVERLAY_SECONDARY:
                                    ColorBgra secondary = (ColorBgra)EnvironmentParameters.BackColor;
                                    dstArgs.Surface[x, y] = ColorBgra.FromBgra(secondary.B, secondary.G, secondary.R, c);
                                    break;
                                case CloudEffect.REPLACE_TRANSPARENT:
                                    dstArgs.Surface[x, y] = (0 == srcBgra.A) ? ColorBgra.FromBgra(srcBgra.B, srcBgra.G, srcBgra.R, c) : srcArgs.Surface[x, y];
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
        }
Пример #48
0
        private ColorBgra ComputeCellColor(int x, int y, RenderArgs src, int cellSize)
        {
            Rectangle cell = GetCellBox(x, y, cellSize);
            cell.Intersect(src.Bounds);
            
            int left = cell.Left;
            int right = cell.Right - 1;
            int bottom = cell.Bottom - 1;
            int top = cell.Top;
 
            ColorBgra colorTopLeft = src.Surface[left, top];
            ColorBgra colorTopRight = src.Surface[right, top];
            ColorBgra colorBottomLeft = src.Surface[left, bottom];
            ColorBgra colorBottomRight = src.Surface[right, bottom];

            ColorBgra c = ColorBgra.BlendColors4W16IP(colorTopLeft, 16384, colorTopRight, 16384, colorBottomLeft, 16384, colorBottomRight, 16384);

            return c;
        }
Пример #49
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.pencilTipSize = newToken.GetProperty<Int32Property>(PropertyNames.PencilTipSize).Value;
            this.colorRange = newToken.GetProperty<Int32Property>(PropertyNames.ColorRange).Value;

            PropertyBasedEffectConfigToken blurToken = new PropertyBasedEffectConfigToken(this.blurProps);
            blurToken.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, this.pencilTipSize);
            this.blurEffect.SetRenderInfo(blurToken, dstArgs, srcArgs);

            PropertyBasedEffectConfigToken bacToken = new PropertyBasedEffectConfigToken(this.bacProps);
            bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, this.colorRange);
            bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, -this.colorRange);
            this.bacAdjustment.SetRenderInfo(bacToken, dstArgs, dstArgs);

            this.desaturateEffect.SetRenderInfo(null, dstArgs, dstArgs);

            this.invertEffect.SetRenderInfo(null, dstArgs, dstArgs);

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #50
0
        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;
        }
Пример #51
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)parameters;
            Effect userEffect = sect.UserScriptObject;

            if (userEffect != null)
            {
                userEffect.EnvironmentParameters = this.EnvironmentParameters;

                try
                {
                    userEffect.Render(null, dstArgs, srcArgs, rois, startIndex, length);
                }

                catch (Exception exc)
                {
                    sect.LastExceptions.Add(exc);
                    dstArgs.Surface.CopySurface(srcArgs.Surface);
                    sect.UserScriptObject = null;
                }
            }
        }
Пример #52
0
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            AmountEffectConfigToken aecd = (AmountEffectConfigToken)parameters;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int yEnd = y + 1;

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        Rectangle cellRect = GetCellBox(x, y, aecd.Amount);
                        cellRect.Intersect(dstArgs.Bounds);
                        ColorBgra color = ComputeCellColor(x, y, srcArgs, aecd.Amount);

                        int xEnd = Math.Min(rect.Right, cellRect.Right);
                        yEnd = Math.Min(rect.Bottom, cellRect.Bottom);

                        for (int y2 = y; y2 < yEnd; ++y2)
                        {
                            ColorBgra *ptr = dstArgs.Surface.GetPointAddressUnchecked(x, y2);

                            for (int x2 = x; x2 < xEnd; ++x2)
                            {
                                ptr->Bgra = color.Bgra;
                                ++ptr;
                            }
                        }

                        x = xEnd - 1;
                    }

                    y = yEnd - 1;
                }
            }
        }
Пример #53
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.angle = newToken.GetProperty<DoubleProperty>(PropertyNames.Angle).Value;
            this.distance = newToken.GetProperty<Int32Property>(PropertyNames.Distance).Value;
            this.centered = newToken.GetProperty<BooleanProperty>(PropertyNames.Centered).Value;

            PointF start = new PointF(0, 0);
            double theta = ((double)(this.angle + 180) * 2 * Math.PI) / 360.0;
            double alpha = (double)distance;
            double x = alpha * Math.Cos(theta);
            double y = alpha * Math.Sin(theta);
            PointF end = new PointF((float)x, (float)(-y));

            if (this.centered)
            {
                start.X = -end.X / 2.0f;
                start.Y = -end.Y / 2.0f;

                end.X /= 2.0f;
                end.Y /= 2.0f;
            }

            this.points = new PointF[((1 + this.distance) * 3) / 2];

            if (this.points.Length == 1)
            {
                this.points[0] = new PointF(0, 0);
            }
            else
            {
                for (int i = 0; i < this.points.Length; ++i)
                {
                    float frac = (float)i / (float)(this.points.Length - 1);
                    this.points[i] = Utility.Lerp(start, end, frac);
                }
            }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #54
0
 public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
 {
     UnaryPixelOps.Level levels = (parameters as LevelsEffectConfigToken).Levels;
     levels.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length);
 }
Пример #55
0
        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;
            }
        }
Пример #56
0
        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);
            }
        }
Пример #57
0
        private void DrawLines(RenderArgs ra, List<Point> points, int startIndex, int length, ColorBgra color)
        {
            // Draw a point in the line
            if (points.Count == 0)
            {
                return;
            }
            else if (points.Count == 1)
            {
                Point p = (Point)points[0];

                if (ra.Surface.Bounds.Contains(p))
                {
                    DrawPoint(ra, p, color);
                }
            }
            else
            {
                for (int i = startIndex + 1; i < startIndex + length; ++i)
                {
                    Point[] linePoints = Utility.GetLinePoints(points[i - 1], points[i]);
                    int startPoint = 0;

                    if (i != 1)
                    {
                        startPoint = 1;
                    }

                    for (int pi = startPoint; pi < linePoints.Length; ++pi)
                    {
                        Point p = linePoints[pi];
                        DrawPoint(ra, p, color);
                    }
                }
            }       
        }
Пример #58
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int red = newToken.GetProperty<Int32Property>(PropertyNames.RedLevels).Value;
            int green = newToken.GetProperty<Int32Property>(PropertyNames.GreenLevels).Value;
            int blue = newToken.GetProperty<Int32Property>(PropertyNames.BlueLevels).Value;

            this.op = new PosterizePixelOp(red, green, blue);

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #59
0
        protected override void OnSetRenderInfo2(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            double scale = newToken.GetProperty<DoubleProperty>(PropertyNames.Scale).Value;

            double refraction = newToken.GetProperty<DoubleProperty>(PropertyNames.Refraction).Value;
            double detail1 = newToken.GetProperty<DoubleProperty>(PropertyNames.Roughness).Value;
            double detail2 = detail1;
            double roughness = detail2;

            double turbulence = newToken.GetProperty<DoubleProperty>(PropertyNames.Tension).Value;

            int quality = newToken.GetProperty<Int32Property>(PropertyNames.Quality).Value;
            byte newSeed = (byte)newToken.GetProperty<Int32Property>(PropertyNames.Seed).Value;

            this.seed = (byte)(this.instanceSeed ^ newSeed);

            this.scaleR = (400.0 / base.DefaultRadius) / scale;
            this.refractionScale = (refraction / 100.0) / scaleR;
            this.theta = Math.PI * 2.0 * turbulence / 10.0;
            this.roughness = roughness / 100.0;

            double detail3 = 1.0 + (detail2 / 10.0);

            // we don't want the perlin noise frequency components exceeding
            // the nyquist limit, so we will limit 'detail' appropriately
            double maxDetail = Math.Floor(Math.Log(this.scaleR) / Math.Log(0.5));

            if (detail3 > maxDetail && maxDetail >= 1.0)
            {
                this.detail = maxDetail;
            }
            else
            {
                this.detail = detail3;
            }

            base.Quality = quality;

            base.OnSetRenderInfo2(newToken, dstArgs, srcArgs);
        }
Пример #60
0
 // Draws a point, but first intersects it with the selection
 private void DrawPoint(RenderArgs ra, Point p, ColorBgra color)
 {
     if (ra.Surface.Bounds.Contains(p))
     {
         if (ra.Graphics.IsVisible(p))
         {
             BinaryPixelOp op = AppEnvironment.AlphaBlending ? blendOp : copyOp;
             ra.Surface[p.X, p.Y] = op.Apply(ra.Surface[p.X, p.Y], color);
         }
     }
 }