Пример #1
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.radius = newToken.GetProperty<Int32Property>(PropertyNames.Radius).Value;
            this.strength = -0.2 * newToken.GetProperty<DoubleProperty>(PropertyNames.Strength).Value;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #2
0
        private void MyRender(Surface dst, Surface src)
        {
            PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
            ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
            ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
            int BrushWidth = (int)EnvironmentParameters.BrushWidth;
            if (PGP.Length > 0 && Draw )
            {
                using (Graphics g = new RenderArgs(dst).Graphics)
                {
                    using (Region reg = new Region(selectionRegion.GetRegionData()))
                    {
                        g.SetClip(reg, CombineMode.Replace);
                    }
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    Pen p = new Pen(PrimaryColor);
                    p.Width = BrushWidth;
                    for (int i = 0; i < PGP.Length; i++)
                    {
                        if (PGP[i].PointCount > 0)
                        {

                            g.DrawPath(p, PGP[i]);
                        }
                    }
                }
            }
        }
Пример #3
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.angle = newToken.GetProperty<DoubleProperty>(PropertyNames.Angle).Value;

            // adjust and convert angle to radians
            double r = (double)this.angle * 2.0 * Math.PI / 360.0;

            // angle delta for each weight
            double dr = Math.PI / 4.0;

            // for r = 0 this builds an emboss filter pointing straight left
            this.weights = new double[3][];

            for (int i = 0; i < 3; ++i)
            {
                this.weights[i] = new double[3];
            }

            this.weights[0][0] = Math.Cos(r + dr);
            this.weights[0][1] = Math.Cos(r + 2.0 * dr);
            this.weights[0][2] = Math.Cos(r + 3.0 * dr);

            this.weights[1][0] = Math.Cos(r);
            this.weights[1][1] = 0;
            this.weights[1][2] = Math.Cos(r + 4.0 * dr);

            this.weights[2][0] = Math.Cos(r - dr);
            this.weights[2][1] = Math.Cos(r - 2.0 * dr);
            this.weights[2][2] = Math.Cos(r - 3.0 * dr);

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #4
0
        protected sealed override void OnExecute()
        {
            for (int i = 0; i < this.iterations; ++i)
            {
                EffectConfigToken localToken;

                if (this.token == null)
                {
                    localToken = null;
                }
                else
                {
                    localToken = (EffectConfigToken)this.token.Clone();
                }

                RenderArgs srcArgs = new RenderArgs(image);
                RenderArgs dstArgs = new RenderArgs(dst);

                BackgroundEffectRenderer ber = new BackgroundEffectRenderer(effect, localToken, dstArgs, srcArgs, region,
                    25 * Processor.LogicalCpuCount, Processor.LogicalCpuCount);

                ber.Start();
                ber.Join();

                ber.Dispose();
                ber = null;
            }
        }
Пример #5
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.radius = newToken.GetProperty<Int32Property>(PropertyNames.Radius).Value;
            this.percentile = newToken.GetProperty<Int32Property>(PropertyNames.Percentile).Value;

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

            ra.Bitmap.Save(output, ImageFormat.Bmp);
        }
Пример #7
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            HistogramRgb histogram = new HistogramRgb();
            histogram.UpdateHistogram(srcArgs.Surface, this.EnvironmentParameters.GetSelection(dstArgs.Bounds));
            this.levels = histogram.MakeLevelsAuto();

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #8
0
 protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
 {
     EffectPluginConfigToken token = (EffectPluginConfigToken)parameters;
     PGP = token.GP;
     Draw = token.Draw;
     if (PGP != null) MyRender(dstArgs.Surface, srcArgs.Surface);
     base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
 }
Пример #9
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.intensity = newToken.GetProperty<Int32Property>(PropertyNames.Intensity).Value;
            this.saturation = newToken.GetProperty<Int32Property>(PropertyNames.Saturation).Value;
            this.coverage = 0.01 * newToken.GetProperty<DoubleProperty>(PropertyNames.Coverage).Value;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #10
0
        public unsafe override void Render(EffectConfigToken configToken, RenderArgs dstArgs, RenderArgs srcArgs, 
            Rectangle[] rois, int startIndex, int length)
        {
            EmbossEffectConfigToken eect = (EmbossEffectConfigToken)configToken;

            double[,] weights = eect.Weights;

            Surface dst = dstArgs.Surface;
            Surface src = srcArgs.Surface;

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

                // loop through each line of target rectangle
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int fyStart = 0;
                    int fyEnd = 3;

                    if (y == src.Bounds.Top) fyStart = 1;
                    if (y == src.Bounds.Bottom - 1) fyEnd = 2;

                    // loop through each point in the line
                    ColorBgra *dstPtr = dst.GetPointAddress(rect.Left, y);
                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        int fxStart = 0;
                        int fxEnd = 3;

                        if (x == src.Bounds.Left) fxStart = 1;
                        if (x == src.Bounds.Right - 1) fxEnd = 2;

                        // loop through each weight
                        double sum = 0.0;

                        for (int fy = fyStart; fy < fyEnd; ++fy)
                        {
                            for (int fx = fxStart; fx < fxEnd; ++fx)
                            {
                                double weight = weights[fy, fx];
                                ColorBgra c = src.GetPointUnchecked(x - 1 + fx, y - 1 + fy);
                                double intensity = (double)c.GetIntensityByte();
                                sum += weight * intensity;
                            }
                        }

                        int iSum = (int)sum;
                        iSum += 128;
                        if (iSum > 255) iSum = 255;
                        if (iSum < 0) iSum = 0;
                        *dstPtr = ColorBgra.FromBgra((byte)iSum, (byte)iSum, (byte)iSum, 255);

                        ++dstPtr;
                    }
                }
            }
        }
Пример #11
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.tolerance = newToken.GetProperty<Int32Property>(PropertyNames.Tolerance).Value;
            this.saturation = newToken.GetProperty<Int32Property>(PropertyNames.Saturation).Value;

            this.redEyeOp = new UnaryPixelOps.RedEyeRemove(this.tolerance, this.saturation);

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
 public override sealed void Render(Surface dst, Point offset)
 {
     if (ShouldRender())
     {
         using (RenderArgs ra = new RenderArgs(dst))
         {
             RenderToGraphics(ra.Graphics, offset);
         }
     }
 }
Пример #13
0
 public override sealed void Render(Surface dst, Point offset)
 {
     if (ShouldRender())
     {
         using (RenderArgs ra = new RenderArgs(dst))
         {
             RenderToGraphics(ra.Graphics, offset);
         }
     }
 }
Пример #14
0
 private void OnThumbnailUpdated(DocumentWorkspace dw)
 {
     // We must double check that the DW is still around, because there's a chance
     // that the DW was been removed while the thumbnail was being rendered.
     if (this.dw2button.ContainsKey(dw))
     {
         ImageStrip.Item docButton = this.dw2button[dw];
         RenderArgs      docRA     = this.thumbs[dw];
         docButton.Image = docRA.Bitmap;
         docButton.Update();
     }
 }
        protected override void OnPreRender(RenderArgs dstArgs, RenderArgs srcArgs)
        {
            KeyValueConfigurationElement displayTimer = GetDllConfig().AppSettings.Settings["Timer"];

            if (displayTimer != null && displayTimer.Value == "1")
            {
                this.tmr = new System.Diagnostics.Stopwatch();
                this.tmr.Start();
            }

            base.OnPreRender(dstArgs, srcArgs);
        }
Пример #16
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, PdnRegion roi)
        {
            Rectangle roiBounds = roi.GetBoundsInt();

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

            Rectangle[] rects = roi.GetRegionScansReadOnlyInt();
            RenderImpl(args, rects);
        }
Пример #17
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            GifSaveConfigToken gsct = (GifSaveConfigToken)token;

            // Flatten and pre-process the image
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

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

            for (int y = 0; y < scratchSurface.Height; ++y)
            {
                unsafe
                {
                    ColorBgra *ptr = scratchSurface.GetRowAddressUnchecked(y);

                    for (int x = 0; x < scratchSurface.Width; ++x)
                    {
                        if (ptr->A < gsct.Threshold)
                        {
                            ptr->Bgra = 0;
                        }
                        else
                        {
                            if (gsct.PreMultiplyAlpha)
                            {
                                int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int a = 255;

                                *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
                            }
                            else
                            {
                                ptr->Bgra |= 0xff000000;
                            }
                        }

                        ++ptr;
                    }
                }
            }

            using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback))
            {
                quantized.Save(output, ImageFormat.Gif);
            }
        }
Пример #18
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            GifSaveConfigToken gsct = (GifSaveConfigToken)token;

            // Flatten and pre-process the image
            scratchSurface.Clear(ColorBgra.FromBgra(255, 255, 255, 0));

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

            for (int y = 0; y < scratchSurface.Height; ++y)
            {
                unsafe
                {
                    ColorBgra* ptr = scratchSurface.GetRowAddressUnchecked(y);

                    for (int x = 0; x < scratchSurface.Width; ++x)
                    {
                        if (ptr->A < gsct.Threshold)
                        {
                            ptr->Bgra = 0;
                        }
                        else
                        {
                            if (gsct.PreMultiplyAlpha)
                            {
                                int r = ((ptr->R * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int g = ((ptr->G * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int b = ((ptr->B * ptr->A) + (255 * (255 - ptr->A))) / 255;
                                int a = 255;

                                *ptr = ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a);
                            }
                            else
                            {
                                ptr->Bgra |= 0xff000000;
                            }
                        }

                        ++ptr;
                    }
                }
            }

            using (Bitmap quantized = Quantize(scratchSurface, gsct.DitherLevel, 255, progressCallback))
            {
                quantized.Save(output, ImageFormat.Gif);
            }
        }
Пример #19
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, 
            Rectangle[] rois, int startIndex, int length)
        {
            if (levels == null)
            {
                HistogramRgb histogram = new HistogramRgb();
                histogram.UpdateHistogram(srcArgs.Surface, this.EnvironmentParameters.GetSelection(dstArgs.Bounds));
                levels = histogram.MakeLevelsAuto();
            }

            if (levels.isValid)
            {
                levels.Apply(dstArgs.Surface, srcArgs.Surface, rois, startIndex, length);
            }
        }
        public unsafe override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            int width = srcArgs.Surface.Width;

              double[][] diffusion = new double[][] { new double[width], new double[width] };
              int currentBuffer = 0;

              for (int y = 0; y < srcArgs.Surface.Height; y++)
              {
            byte* srcRow = (byte*)srcArgs.Surface.Scan0.Pointer + y * srcArgs.Surface.Stride;
            byte* dstRow = (byte*)dstArgs.Surface.Scan0.Pointer + y * dstArgs.Surface.Stride;

            Array.Clear(diffusion[currentBuffer], 0, width);
            currentBuffer = 1 - currentBuffer;

            bool forward = y % 2 == 0;
            int start = forward ? 0 : width - 1;
            int end = forward ? width : -1;
            int increment = forward ? 1 : -1;

            for (int x = start; x != end; x += increment)
            {
              double intensity = (0.0721 * srcRow[x * 4] + 0.7154 * srcRow[x * 4 + 1] + 0.2125 * srcRow[x * 4 + 2]) / 255.0;
              intensity += diffusion[currentBuffer][x];

              double error = 0.0;
              if (intensity > 0.5)
              {
            error = intensity > 1.0 ? 0.0 : intensity - 1.0;
            *((uint*)(dstRow + x * 4)) = 0xFFFFFFFF;
              }
              else
              {
            error = intensity;
            *((uint*)(dstRow + x * 4)) = 0xFF000000;
              }

              diffusion[1 - currentBuffer][x] += (error * 5 / 16);
              if ((forward && x > start) || (!forward && x < start))
            diffusion[1 - currentBuffer][x - increment] += (error * 3 / 16);
              if ((forward && x < width - 1) || (!forward && x > start + 1))
              {
            diffusion[currentBuffer][x + increment] += (error * 7 / 16);
            diffusion[1 - currentBuffer][x + increment] += (error / 16);
              }
            }
              }
        }
Пример #21
0
        public static void Save(Document input, Stream output, Surface scratchSurface, ImageFormat format, ProgressEventHandler callback)
        {
            // flatten the document
            scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0));

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                LoadProperties(bitmap, input);
                bitmap.Save(output, format);
            }
        }
Пример #22
0
        /// <summary>
        /// Causes the layer to render a given rectangle 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 rectangular region to be rendered.</param>
        public void Render(RenderArgs args, Rectangle roi)
        {
            // the bitmap we're rendering to must match the size of the layer we're rendering from
            if (args.Surface.Width != Width || args.Surface.Height != Height)
            {
                throw new ArgumentException();
            }

            // the region of interest can not be out of bounds!
            if (!IsInBounds(roi))
            {
                throw new ArgumentOutOfRangeException("roi");
            }

            RenderImpl(args, roi);
        }
Пример #23
0
        public static void Save(Document input, Stream output, Surface scratchSurface, ImageFormat format, ProgressEventHandler callback)
        {
            // flatten the document
            scratchSurface.Clear(ColorBgra.FromBgra(0, 0, 0, 0));

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                LoadProperties(bitmap, input);
                bitmap.Save(output, format);
            }
        }
Пример #24
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds);

            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)
                    {
                        // Render Code Here
                    }
                }
            }
        }
Пример #25
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.backBuffer != null)
                {
                    this.backBuffer.Dispose();
                    this.backBuffer = null;
                }

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

            base.Dispose(disposing);
        }
        protected override void OnPreRender(RenderArgs dstArgs, RenderArgs srcArgs)
        {
            KeyValueConfigurationElement displayTimer = GetDllConfig().AppSettings.Settings["Timer"];

            CleanUp();

            if (displayTimer != null && displayTimer.Value == "1")
            {
                this.tmr = new System.Diagnostics.Stopwatch();
                this.tmr.Start();
            }

            base.OnPreRender(dstArgs, srcArgs);

            this.IsLargeImage = (srcArgs.Width > base.MaxTextureSize || srcArgs.Height > base.MaxTextureSize);

            try
            {
                if (this.IsInitialized)
                {
                    // Copy source image pixels
                    imageData = SurfaceToStream(srcArgs.Surface);

                    if (this.IsLargeImage)
                    {
                        // Create the source image buffer and views
                        imageBuffer = CreateBuffer(base.Device, imageData, BUFF_SIZE);
                        imageView = CreateView(base.Device, imageBuffer);
                    }
                    else
                    {
                        // Create the source texture view
                        imageView = CreateView(out texture, base.Device, imageData, srcArgs.Width, srcArgs.Height);
                    }
                }
            }
            catch (SharpDX.SharpDXException ex)
            {
                MessageBox.Show(ex.Message);
                this.IsInitialized = false;
            }
        }
Пример #27
0
        /// <summary>
        /// Draws an area of the SurfaceBox.
        /// </summary>
        /// <param name="ra">The rendering surface object to draw to.</param>
        /// <param name="offset">The virtual offset of ra, in client (destination) coordinates.</param>
        /// <remarks>
        /// If drawing to ra.Surface or ra.Bitmap, copy the roi of the source surface to (0,0) of ra.Surface or ra.Bitmap
        /// If drawing to ra.Graphics, copy the roi of the surface to (roi.X, roi.Y) of ra.Graphics
        /// </remarks>
        private unsafe void DrawArea(RenderArgs ra, Point offset)
        {
            if (surface == null)
            {
                return;
            }

            if (renderContext == null || (renderContext.windows != null && renderContext.windows.Length != Processor.LogicalCpuCount))
            {
                renderContext              = new RenderContext();
                renderContext.owner        = this;
                renderContext.waitCallback = new 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)
            {
                if (renderContext.rects[i].Width > 0 && renderContext.rects[i].Height > 0)
                {
                    renderContext.offsets[i] = new Point(renderContext.rects[i].X + offset.X, renderContext.rects[i].Y + offset.Y);
                    renderContext.windows[i] = ra.Surface.CreateWindow(renderContext.rects[i]);
                }
                else
                {
                    renderContext.windows[i] = null;
                }
            }

            for (int i = 0; i < renderContext.windows.Length; ++i)
            {
                if (renderContext.windows[i] != null)
                {
                    this.threadPool.QueueUserWorkItem(renderContext.waitCallback, BoxedConstants.GetInt32(i));
                }
            }

            this.threadPool.Drain();
        }
Пример #28
0
        private void OnPaintImpl(PaintEventArgs2 e)
        {
            using (Surface doubleBuffer = GetDoubleBuffer(e.ClipRectangle.Size))
            {
                using (RenderArgs renderArgs = new RenderArgs(doubleBuffer))
                {
                    OnPrePaint(e);
                    DrawArea(renderArgs, e.ClipRectangle.Location);
                    OnPainted(e);

                    IntPtr tracking;
                    Point  childOffset;
                    Size   parentSize;
                    doubleBuffer.GetDrawBitmapInfo(out tracking, out childOffset, out parentSize);

                    PdnGraphics.DrawBitmap(e.Graphics, e.ClipRectangle, e.Graphics.Transform,
                                           tracking, childOffset.X, childOffset.Y);
                }
            }
        }
Пример #29
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            PropertyCollection blurValues = this.blurProps.Clone();
            blurValues[GaussianBlurEffect.PropertyNames.Radius].Value = newToken.GetProperty<Int32Property>(PropertyNames.Radius).Value;
            PropertyBasedEffectConfigToken blurToken = new PropertyBasedEffectConfigToken(blurValues);
            this.blurEffect.SetRenderInfo(blurToken, dstArgs, srcArgs);

            PropertyCollection bcValues = this.bcProps.Clone();

            bcValues[BrightnessAndContrastAdjustment.PropertyNames.Brightness].Value =
                newToken.GetProperty<Int32Property>(PropertyNames.Brightness).Value;

            bcValues[BrightnessAndContrastAdjustment.PropertyNames.Contrast].Value =
                newToken.GetProperty<Int32Property>(PropertyNames.Contrast).Value;

            PropertyBasedEffectConfigToken bcToken = new PropertyBasedEffectConfigToken(bcValues);
            this.bcAdjustment.SetRenderInfo(bcToken, dstArgs, dstArgs); // have to do adjustment in place, hence dstArgs for both 'args' parameters

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #30
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int quality = token.GetProperty<Int32Property>(PropertyNames.Quality).Value;

            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
Пример #31
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;

            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
Пример #32
0
        protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
        {
            int quality = token.GetProperty <Int32Property>(PropertyNames.Quality).Value;

            ImageCodecInfo    icf   = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter  parm  = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);

            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
Пример #33
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            JpegSaveConfigToken jsct = (JpegSaveConfigToken)token;

            ImageCodecInfo    icf   = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Jpeg);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter  parm  = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jsct.Quality); // force '95% quality'

            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

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

            using (Bitmap bitmap = scratchSurface.CreateAliasedBitmap())
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            this.hue = newToken.GetProperty<Int32Property>(PropertyNames.Hue).Value;
            this.saturation = newToken.GetProperty<Int32Property>(PropertyNames.Saturation).Value;
            this.lightness = newToken.GetProperty<Int32Property>(PropertyNames.Lightness).Value;

            // map the range [0,100] -> [0,100] and the range [101,200] -> [103,400]
            if (this.saturation > 100)
            {
                this.saturation = ((this.saturation - 100) * 3) + 100;
            }

            if (this.hue == 0 && this.saturation == 100 && this.lightness == 0)
            {
                this.pixelOp = new UnaryPixelOps.Identity();
            }
            else
            {
                this.pixelOp = new UnaryPixelOps.HueSaturationLightness(this.hue, this.saturation, this.lightness);
            }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #35
0
        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface scratchSurface, ProgressEventHandler callback)
        {
            ImageCodecInfo icf = GdiPlusFileType.GetImageCodecInfo(ImageFormat.Bmp);
            EncoderParameters parms = new EncoderParameters(1);
            EncoderParameter parm = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 24); // BMP's should always save as 24-bit
            parms.Param[0] = parm;

            scratchSurface.Clear(ColorBgra.White);

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

            // In order to save memory, we 'squish' the 32-bit bitmap down to 24-bit in-place
            // instead of allocating a new bitmap and copying it over.
            SquishSurfaceTo24Bpp(scratchSurface);

            using (Bitmap bitmap = CreateAliased24BppBitmap(scratchSurface))
            {
                GdiPlusFileType.LoadProperties(bitmap, input);
                bitmap.Save(output, icf, parms);
            }
        }
Пример #36
0
        public void RemoveDocumentWorkspace(DocumentWorkspace removeMe)
        {
            removeMe.CompositionUpdated -= Workspace_CompositionUpdated;

            if (this.selectedDocument == removeMe)
            {
                this.selectedDocument = null;
            }

            removeMe.DocumentChanging -= Workspace_DocumentChanging;
            removeMe.DocumentChanged  -= Workspace_DocumentChanged;

            if (removeMe.Document != null)
            {
                removeMe.Document.DirtyChanged -= Document_DirtyChanged;
            }

            this.documents.Remove(removeMe);
            this.thumbnailManager.RemoveFromQueue(removeMe);

            ImageStrip.Item docButton = this.dw2button[removeMe];
            this.RemoveItem(docButton);
            this.dw2button.Remove(removeMe);
            this.documentButtons.Remove(docButton);

            if (this.thumbs.ContainsKey(removeMe))
            {
                RenderArgs thumbRA = this.thumbs[removeMe];
                Surface    surface = thumbRA.Surface;
                thumbRA.Dispose();
                this.thumbs.Remove(removeMe);
                surface.Dispose();
            }

            OnDocumentListChanged();
        }
Пример #37
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            double minRadiusP = newToken.GetProperty<DoubleProperty>(PropertyNames.MinScatterRadius).Value;

            this.minRadius = Math.Min(minRadiusP, Math.Min(srcArgs.Width, srcArgs.Height) / 2); 
            this.maxRadius = newToken.GetProperty<DoubleProperty>(PropertyNames.MaxScatterRadius).Value;
            this.sampleCount = newToken.GetProperty<Int32Property>(PropertyNames.NumSamples).Value;

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #38
0
 /// <summary>
 /// Override this method to provide your layer's rendering capabilities.
 /// </summary>
 /// <param name="args">Contains information about which objects to use for rendering</param>
 /// <param name="roi">The rectangular region to be rendered.</param>
 protected abstract void RenderImpl(RenderArgs args, Rectangle roi);
Пример #39
0
        public unsafe override void Render(EffectConfigToken properties, RenderArgs dstArgs, RenderArgs srcArgs, 
            Rectangle[] rois, int startIndex, int length)
        {
            TwoAmountsConfigToken token = (TwoAmountsConfigToken)properties;
            int brushSize = token.Amount1;
            byte smoothness = (byte)token.Amount2;
            Surface src = srcArgs.Surface;
            Surface dst = dstArgs.Surface;
            int width = src.Width;
            int height = src.Height;

            int arrayLens = 1 + smoothness;
            int* intensityCount = stackalloc int[arrayLens];
            uint* avgRed = stackalloc uint[arrayLens];
            uint* avgGreen = stackalloc uint[arrayLens];
            uint* avgBlue = stackalloc uint[arrayLens];
            uint* avgAlpha = stackalloc uint[arrayLens];

            byte maxIntensity = smoothness;

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

                int rectTop = rect.Top;
                int rectBottom = rect.Bottom;
                int rectLeft = rect.Left;
                int rectRight = rect.Right;

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

                    int top = y - brushSize;
                    int bottom = y + brushSize + 1;

                    if (top < 0)
                    {
                        top = 0;
                    }

                    if (bottom > height)
                    {
                        bottom = height;
                    }

                    for (int x = rectLeft; x < rectRight; ++x)
                    {
                        int left = x - brushSize;
                        int right = x + brushSize + 1;

                        if (left < 0)
                        {
                            left = 0;
                        }

                        if (right > width)
                        {
                            right = width;
                        }

                        for (int i = 0; i < arrayLens; ++i)
                        {
                            intensityCount[i] = 0;
                            avgRed[i] = 0;
                            avgGreen[i] = 0;
                            avgBlue[i] = 0;
                            avgAlpha[i] = 0;
                        }

                        int numInt = 0;

                        for (int j = top; j < bottom; ++j)
                        {
                            ColorBgra *srcPtr = src.GetPointAddress(left, j);

                            for (int i = left; i < right; ++i)
                            {
                                byte intensity = (byte)((srcPtr->GetIntensityByte() * maxIntensity) / 255);
                                ++intensityCount[intensity];
                                ++numInt;

                                avgRed[intensity] += srcPtr->R;
                                avgGreen[intensity] += srcPtr->G;
                                avgBlue[intensity] += srcPtr->B;
                                avgAlpha[intensity] += srcPtr->A;

                                ++srcPtr;
                            }
                        }

                        byte chosenIntensity = 0;
                        int maxInstance = 0;

                        for (int i = 0; i <= maxIntensity; ++i)
                        {
                            if (intensityCount[i] > maxInstance)
                            {
                                chosenIntensity = (byte)i;
                                maxInstance = intensityCount[i];
                            }
                        }

                        byte R = (byte)(avgRed[chosenIntensity] / maxInstance);
                        byte G = (byte)(avgGreen[chosenIntensity] / maxInstance);
                        byte B = (byte)(avgBlue[chosenIntensity] / maxInstance);
                        byte A = (byte)(avgAlpha[chosenIntensity] / maxInstance);

                        *dstPtr = ColorBgra.FromBgra(B, G, R, A);
                        ++dstPtr;
                    }
                }
            }
        }
Пример #40
0
        protected unsafe override sealed void OnSaveT(
            Document input,
            Stream output,
            PropertyBasedSaveConfigToken token,
            Surface scratchSurface,
            ProgressEventHandler progressCallback)
        {
            // flatten the document -- render w/ transparent background
            scratchSurface.Clear(ColorBgra.Transparent);

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

            // load properties from token
            int thresholdFromToken = GetThresholdFromToken(token);
            int ditherLevel        = GetDitherLevelFromToken(token);

            Set <SavableBitDepths> allowedBitDepths = CreateAllowedBitDepthListFromToken(token);

            if (allowedBitDepths.Count == 0)
            {
                throw new ArgumentException("there must be at least 1 element returned from CreateAllowedBitDepthListFromToken()");
            }

            // allowedBitDepths.Count >= 1

            // set to 1 unless allowedBitDepths contains only Rgb8 and Rgba8
            int threshold;

            if (allowedBitDepths.IsSubsetOf(Set.Create(SavableBitDepths.Rgb8, SavableBitDepths.Rgba8)))
            {
                threshold = thresholdFromToken;
            }
            else
            {
                threshold = 1;
            }

            // Analyze image, try to detect what bit-depth or whatever to use, based on allowedBitDepths
            bool allOpaque;
            bool all0or255Alpha;
            int  uniqueColorCount;

            Analyze(scratchSurface, out allOpaque, out all0or255Alpha, out uniqueColorCount);

            Set <SavableBitDepths> losslessBitDepths = new Set <SavableBitDepths>();

            losslessBitDepths.Add(SavableBitDepths.Rgba32);

            if (allOpaque)
            {
                losslessBitDepths.Add(SavableBitDepths.Rgb24);

                if (uniqueColorCount <= 256)
                {
                    losslessBitDepths.Add(SavableBitDepths.Rgb8);
                }
            }
            else if (all0or255Alpha && uniqueColorCount < 256)
            {
                losslessBitDepths.Add(SavableBitDepths.Rgba8);
            }

            SavableBitDepths bitDepth = ChooseBitDepth(allowedBitDepths, losslessBitDepths, allOpaque, all0or255Alpha, uniqueColorCount);

            if (bitDepth == SavableBitDepths.Rgba8 && threshold == 0 && allowedBitDepths.Contains(SavableBitDepths.Rgba8) && allowedBitDepths.Contains(SavableBitDepths.Rgb8))
            {
                // threshold of 0 should effectively force full 256 color palette, instead of 255+1 transparent
                bitDepth = SavableBitDepths.Rgb8;
            }

            // if bit depth is 24 or 8, then we have to do away with the alpha channel
            // for 8-bit, we must have pixels that have either 0 or 255 alpha
            if (bitDepth == SavableBitDepths.Rgb8 ||
                bitDepth == SavableBitDepths.Rgba8 ||
                bitDepth == SavableBitDepths.Rgb24)
            {
                UserBlendOps.NormalBlendOp blendOp = new UserBlendOps.NormalBlendOp();

                for (int y = 0; y < scratchSurface.Height; ++y)
                {
                    for (int x = 0; x < scratchSurface.Width; ++x)
                    {
                        ColorBgra p = scratchSurface[x, y];

                        if (p.A < threshold && bitDepth == SavableBitDepths.Rgba8)
                        {
                            p = ColorBgra.FromBgra(0, 0, 0, 0);
                        }
                        else
                        {
                            p = blendOp.Apply(ColorBgra.White, p);
                        }

                        scratchSurface[x, y] = p;
                    }
                }
            }

            Tracing.Ping("Chose " + bitDepth + ", ditherLevel=" + ditherLevel + ", threshold=" + threshold);

            // finally, do the save.
            FinalSave(input, output, scratchSurface, ditherLevel, bitDepth, token, progressCallback);
        }
Пример #41
0
 protected void RenderImpl(RenderArgs args, Rectangle[] roi)
 {
     RenderImpl(args, roi, 0, roi.Length);
 }
Пример #42
0
        private void OnPaintButtonImpl(Graphics g, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            Color backColor;
            Color outlineColor;
            Color arrowFillColor;
            Color arrowOutlineColor;

            switch (state)
            {
                case PushButtonState.Disabled:
                    backColor = Color.Transparent;
                    outlineColor = BackColor;
                    arrowFillColor = Color.Gray;
                    arrowOutlineColor = Color.Black;
                    break;

                case PushButtonState.Hot:
                    backColor = Color.FromArgb(64, SystemColors.HotTrack);
                    outlineColor = backColor;
                    arrowFillColor = Color.Blue;
                    arrowOutlineColor = Color.White;
                    break;

                case PushButtonState.Default:
                case PushButtonState.Normal:
                    backColor = Color.Transparent;
                    outlineColor = Color.Transparent;
                    arrowFillColor = Color.Black;
                    arrowOutlineColor = Color.White;
                    break;

                case PushButtonState.Pressed:
                    backColor = Color.FromArgb(192, SystemColors.Highlight);
                    outlineColor = Color.FromArgb(192, SystemColors.Highlight);
                    arrowFillColor = Color.Blue;
                    arrowOutlineColor = Color.White;
                    break;

                default:
                    throw new InvalidEnumArgumentException("buttonState");
            }

            // Draw parent background
            IPaintBackground asIpb = Parent as IPaintBackground;

            if (!this.drawWithGradient || asIpb == null)
            {
                if (asIpb != null)
                {
                    Rectangle screenRect = RectangleToScreen(ClientRectangle);
                    Rectangle parentRect = Parent.RectangleToClient(screenRect);

                    g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(g, parentRect);
                    g.TranslateTransform(+Left, +Top, MatrixOrder.Append);
                }
                else
                {
                    using (SolidBrush backBrush = new SolidBrush(BackColor))
                    {
                        g.FillRectangle(backBrush, ClientRectangle);
                    }
                }
            }
            else
            {
                if (this.backBufferSurface != null &&
                    (this.backBufferSurface.Width != ClientSize.Width || this.backBufferSurface.Height != ClientSize.Height))
                {
                    this.backBuffer.Dispose();
                    this.backBuffer = null;

                    this.backBufferSurface.Dispose();
                    this.backBufferSurface = null;
                }

                if (this.backBufferSurface == null)
                {
                    this.backBufferSurface = new Surface(ClientSize.Width, ClientSize.Height);
                    this.backBuffer = new RenderArgs(this.backBufferSurface);
                }

                Rectangle screenRect = RectangleToScreen(ClientRectangle);
                Rectangle parentRect = Parent.RectangleToClient(screenRect);

                using (Graphics bg = Graphics.FromImage(this.backBuffer.Bitmap))
                {
                    bg.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(bg, parentRect);
                }

                BitmapData bitmapData = this.backBuffer.Bitmap.LockBits(
                    new Rectangle(0, 0, this.backBuffer.Bitmap.Width, this.backBuffer.Bitmap.Height), 
                    ImageLockMode.ReadWrite, 
                    PixelFormat.Format32bppArgb);

                int startAlpha;
                int finishAlpha;

                if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Up)
                {
                    startAlpha = 255;
                    finishAlpha = 0;
                }
                else if (this.arrowDirection == ArrowDirection.Right || this.ArrowDirection == ArrowDirection.Down)
                {
                    startAlpha = 0;
                    finishAlpha = 255;
                }
                else
                {
                    throw new InvalidEnumArgumentException("this.arrowDirection");
                }

                unsafe
                {
                    if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Right)
                    {
                        for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                        {
                            float lerp = (float)x / (float)(this.backBuffer.Bitmap.Width - 1);

                            if (this.arrowDirection == ArrowDirection.Left)
                            {
                                lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));
                            }
                            else
                            {
                                lerp = (float)Math.Sin(lerp * (Math.PI / 2.0));
                            }

                            byte alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte* pb = (byte*)bitmapData.Scan0.ToPointer() + (x * 4) + 3; // *4 because 4-bytes per pixel, +3 to get to alpha channel

                            for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                            {
                                *pb = alpha;
                                pb += bitmapData.Stride;
                            }
                        }
                    }
                    else if (this.arrowDirection == ArrowDirection.Up || this.arrowDirection == ArrowDirection.Down)
                    {
                        for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                        {
                            float lerp = (float)y / (float)(this.backBuffer.Bitmap.Height - 1);
                            lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));

                            byte alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte* pb = (byte*)bitmapData.Scan0.ToPointer() + (y * bitmapData.Stride) + 3; // *Stride for access to start of row, +3 to get to alpha channel

                            for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                            {
                                *pb = alpha;
                                pb += 4; // 4 for byte size of pixel
                            }
                        }
                    }
                }

                this.backBuffer.Bitmap.UnlockBits(bitmapData);
                bitmapData = null;

                g.DrawImage(this.backBuffer.Bitmap, new Point(0, 0));
            }

            using (SolidBrush fillBrush = new SolidBrush(backColor))
            {
                g.FillRectangle(fillBrush, ClientRectangle);
            }

            // Draw outline
            using (Pen outlinePen = new Pen(outlineColor))
            {
                g.DrawRectangle(outlinePen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));
            }

            // Draw button
            g.SmoothingMode = SmoothingMode.AntiAlias;

            const int arrowInset = 3;
            int arrowSize = Math.Min(ClientSize.Width - arrowInset * 2, ClientSize.Height - arrowInset * 2) - 1;

            PointF a;
            PointF b;
            PointF c;

            switch (this.arrowDirection)
            {
                case ArrowDirection.Left:
                    a = new PointF(arrowInset, ClientSize.Height / 2);
                    b = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Right:
                    a = new PointF(ClientSize.Width - arrowInset, ClientSize.Height / 2);
                    b = new PointF(arrowInset, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF(arrowInset, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Up:
                    a = new PointF(ClientSize.Width / 2, (ClientSize.Height - arrowSize) / 2);
                    b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                    c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                    break;

                case ArrowDirection.Down:
                    a = new PointF(ClientSize.Width / 2, (ClientSize.Height + arrowSize) / 2);
                    b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                    c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                    break;

                default:
                    throw new InvalidEnumArgumentException("this.arrowDirection");
            }

            // SPIKE in order to get this rendering correctly right away
            if (this.arrowDirection == ArrowDirection.Down)
            {
                SmoothingMode oldSM = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.None;

                float top = b.Y - 2;
                float left = b.X;
                float right = c.X;
                int squareCount = (int)((right - left) / 3);

                Brush outlineBrush = new SolidBrush(arrowOutlineColor);
                Brush interiorBrush = new SolidBrush(arrowFillColor);

                g.FillRectangle(interiorBrush, left, top, right - left + 1, 3);

                ++left;
                while (left < right)
                {
                    RectangleF rect = new RectangleF(left, top + 1, 1, 1);
                    g.FillRectangle(outlineBrush, rect);
                    left += 2;
                }

                outlineBrush.Dispose();
                outlineBrush = null;

                interiorBrush.Dispose();
                interiorBrush = null;

                a.Y += 2;
                b.Y += 2;
                c.Y += 2;

                g.SmoothingMode = oldSM;
            }

            if (this.reverseArrowColors)
            {
                Utility.Swap(ref arrowFillColor, ref arrowOutlineColor);
            }

            using (Brush buttonBrush = new SolidBrush(arrowFillColor))
            {
                g.FillPolygon(buttonBrush, new PointF[] { a, b, c });
            }

            using (Pen buttonPen = new Pen(arrowOutlineColor, this.arrowOutlineWidth))
            {
                g.DrawPolygon(buttonPen, new PointF[] { a, b, c });
            }
        }
Пример #43
0
 public void RenderUnchecked(RenderArgs args, Rectangle[] roi, int startIndex, int length)
 {
     RenderImpl(args, roi, startIndex, length);
 }
Пример #44
0
        public unsafe override void Render(
            EffectConfigToken parameters,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            System.Drawing.Rectangle[] rois,
            int startIndex,
            int length)
        {
            ThreeAmountsConfigToken token = (ThreeAmountsConfigToken)parameters;

            Surface dst = dstArgs.Surface;
            Surface src = srcArgs.Surface;
            int width = dst.Width;
            int height = dst.Height;
            float hw = width / 2.0f;
            float hh = height / 2.0f;
            float sin = (float)Math.Sin(token.Amount1 * Math.PI / 180.0);
            float cos = (float)Math.Cos(token.Amount1 * Math.PI / 180.0);
            float scale = (float)Math.PI / token.Amount2;
            float intensity = token.Amount3;

            intensity = intensity * intensity / 10 * Math.Sign(intensity);

            int aaLevel = 4;
            int aaSamples = aaLevel * aaLevel + 1;
            PointF* aaPoints = stackalloc PointF[aaSamples];

            for (int i = 0; i < aaSamples; ++i)
            {
                double x = (i * aaLevel) / (double)aaSamples;
                double y = i / (double)aaSamples;

                x -= (int)x;

                // RGSS + rotation to maximize AA quality
                aaPoints[i] = new PointF((float)(cos * x + sin * y), (float)(cos * y - sin * x));
            }

            for (int n = startIndex; n < startIndex + length; ++n)
            {
                Rectangle rect = rois[n];
                for (int y = rect.Top; y < rect.Bottom; y++)
                {
                    float j = y - hh;
                    ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = rect.Left; x < rect.Right; x++)
                    {
                        int b = 0;
                        int g = 0;
                        int r = 0;
                        int a = 0;
                        float i = x - hw;

                        for (int p = 0; p < aaSamples; ++p)
                        {
                            PointF pt = aaPoints[p];

                            float u = i + pt.X;
                            float v = j - pt.Y;

                            float s =  cos * u + sin * v;
                            float t = -sin * u + cos * v;

                            s += intensity * (float)Math.Tan(s * scale);
                            t += intensity * (float)Math.Tan(t * scale);
                            u = cos * s - sin * t;
                            v = sin * s + cos * t;

                            int xSample = (int)(hw + u);
                            int ySample = (int)(hh + v);

                            xSample = (xSample + width) % width;
                            if (xSample < 0) // This makes it a little faster
                            {
                                xSample = (xSample + width) % width;
                            }

                            ySample = (ySample + height) % height;
                            if (ySample < 0) // This makes it a little faster
                            {
                                ySample = (ySample + height) % height;
                            }

                            ColorBgra sample = *src.GetPointAddressUnchecked(xSample, ySample);

                            b += sample.B;
                            g += sample.G;
                            r += sample.R;
                            a += sample.A;
                        }

                        *(dstPtr++) = ColorBgra.FromBgra(
                            (byte)(b / aaSamples),
                            (byte)(g / aaSamples),
                            (byte)(r / aaSamples),
                            (byte)(a / aaSamples));
                    }
                }
            }
        }
Пример #45
0
        private void DrawGradient(Graphics g)
        {
            g.PixelOffsetMode = PixelOffsetMode.Half;
            Rectangle gradientRect;

            float gradientAngle;

            switch (this.orientation)
            {
            case Orientation.Horizontal:
                gradientAngle = 180.0f;
                break;

            case Orientation.Vertical:
                gradientAngle = 90.0f;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            // draw gradient
            gradientRect = ClientRectangle;

            switch (this.orientation)
            {
            case Orientation.Horizontal:
                gradientRect.Inflate(-triangleHalfLength, -triangleSize + 3);
                break;

            case Orientation.Vertical:
                gradientRect.Inflate(-triangleSize + 3, -triangleHalfLength);
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            if (this.customGradient != null && gradientRect.Width > 1 && gradientRect.Height > 1)
            {
                Surface gradientSurface = new Surface(gradientRect.Size);

                using (RenderArgs ra = new RenderArgs(gradientSurface))
                {
                    Utility.DrawColorRectangle(ra.Graphics, ra.Bounds, Color.Transparent, false);

                    if (Orientation == Orientation.Horizontal)
                    {
                        for (int x = 0; x < gradientSurface.Width; ++x)
                        {
                            // TODO: refactor, double buffer, save this computation in a bitmap somewhere
                            double index  = (double)(x * (this.customGradient.Length - 1)) / (double)(gradientSurface.Width - 1);
                            int    indexL = (int)Math.Floor(index);
                            double t      = 1.0 - (index - indexL);
                            int    indexR = (int)Math.Min(this.customGradient.Length - 1, Math.Ceiling(index));
                            Color  colorL = this.customGradient[indexL];
                            Color  colorR = this.customGradient[indexR];

                            double a1 = colorL.A / 255.0;
                            double r1 = colorL.R / 255.0;
                            double g1 = colorL.G / 255.0;
                            double b1 = colorL.B / 255.0;

                            double a2 = colorR.A / 255.0;
                            double r2 = colorR.R / 255.0;
                            double g2 = colorR.G / 255.0;
                            double b2 = colorR.B / 255.0;

                            double at = (t * a1) + ((1.0 - t) * a2);

                            double rt;
                            double gt;
                            double bt;
                            if (at == 0)
                            {
                                rt = 0;
                                gt = 0;
                                bt = 0;
                            }
                            else
                            {
                                rt = ((t * a1 * r1) + ((1.0 - t) * a2 * r2)) / at;
                                gt = ((t * a1 * g1) + ((1.0 - t) * a2 * g2)) / at;
                                bt = ((t * a1 * b1) + ((1.0 - t) * a2 * b2)) / at;
                            }

                            int ap = Utility.Clamp((int)Math.Round(at * 255.0), 0, 255);
                            int rp = Utility.Clamp((int)Math.Round(rt * 255.0), 0, 255);
                            int gp = Utility.Clamp((int)Math.Round(gt * 255.0), 0, 255);
                            int bp = Utility.Clamp((int)Math.Round(bt * 255.0), 0, 255);

                            for (int y = 0; y < gradientSurface.Height; ++y)
                            {
                                ColorBgra src = gradientSurface[x, y];

                                // we are assuming that src.A = 255

                                int rd = ((rp * ap) + (src.R * (255 - ap))) / 255;
                                int gd = ((gp * ap) + (src.G * (255 - ap))) / 255;
                                int bd = ((bp * ap) + (src.B * (255 - ap))) / 255;

                                // TODO: proper alpha blending!
                                gradientSurface[x, y] = ColorBgra.FromBgra((byte)bd, (byte)gd, (byte)rd, 255);
                            }
                        }

                        g.DrawImage(ra.Bitmap, gradientRect, ra.Bounds, GraphicsUnit.Pixel);
                    }
                    else if (Orientation == Orientation.Vertical)
                    {
                        // TODO
                    }
                    else
                    {
                        throw new InvalidEnumArgumentException();
                    }
                }

                gradientSurface.Dispose();
            }
            else
            {
                using (LinearGradientBrush lgb = new LinearGradientBrush(this.ClientRectangle,
                                                                         maxColor, minColor, gradientAngle, false))
                {
                    g.FillRectangle(lgb, gradientRect);
                }
            }

            // fill background
            using (PdnRegion nonGradientRegion = new PdnRegion())
            {
                nonGradientRegion.MakeInfinite();
                nonGradientRegion.Exclude(gradientRect);

                using (SolidBrush sb = new SolidBrush(this.BackColor))
                {
                    g.FillRegion(sb, nonGradientRegion.GetRegionReadOnly());
                }
            }

            // draw value triangles
            for (int i = 0; i < this.vals.Length; i++)
            {
                int   pos = ValueToPosition(vals[i]);
                Brush brush;
                Pen   pen;

                if (i == highlight)
                {
                    brush = Brushes.Blue;
                    pen   = (Pen)Pens.White.Clone();
                }
                else
                {
                    brush = Brushes.Black;
                    pen   = (Pen)Pens.Gray.Clone();
                }

                g.SmoothingMode = SmoothingMode.AntiAlias;

                Point a1;
                Point b1;
                Point c1;

                Point a2;
                Point b2;
                Point c2;

                switch (this.orientation)
                {
                case Orientation.Horizontal:
                    a1 = new Point(pos - triangleHalfLength, 0);
                    b1 = new Point(pos, triangleSize - 1);
                    c1 = new Point(pos + triangleHalfLength, 0);

                    a2 = new Point(a1.X, Height - 1 - a1.Y);
                    b2 = new Point(b1.X, Height - 1 - b1.Y);
                    c2 = new Point(c1.X, Height - 1 - c1.Y);
                    break;

                case Orientation.Vertical:
                    a1 = new Point(0, pos - triangleHalfLength);
                    b1 = new Point(triangleSize - 1, pos);
                    c1 = new Point(0, pos + triangleHalfLength);

                    a2 = new Point(Width - 1 - a1.X, a1.Y);
                    b2 = new Point(Width - 1 - b1.X, b1.Y);
                    c2 = new Point(Width - 1 - c1.X, c1.Y);
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                if (this.drawNearNub)
                {
                    g.FillPolygon(brush, new Point[] { a1, b1, c1, a1 });
                }

                if (this.drawFarNub)
                {
                    g.FillPolygon(brush, new Point[] { a2, b2, c2, a2 });
                }

                if (pen != null)
                {
                    if (this.drawNearNub)
                    {
                        g.DrawPolygon(pen, new Point[] { a1, b1, c1, a1 });
                    }

                    if (this.drawFarNub)
                    {
                        g.DrawPolygon(pen, new Point[] { a2, b2, c2, a2 });
                    }

                    pen.Dispose();
                }
            }
        }
Пример #46
0
        private void OnPaintButtonImpl(Graphics g, UI.ButtonState state, bool drawAsDefault, bool drawFocusCues, bool drawKeyboardCues)
        {
            Color backColor;
            Color outlineColor;
            Color arrowFillColor;
            Color arrowOutlineColor;

            switch (state)
            {
            case UI.ButtonState.Disabled:
                backColor         = Color.Transparent;
                outlineColor      = BackColor;
                arrowFillColor    = Color.Gray;
                arrowOutlineColor = Color.Black;
                break;

            case UI.ButtonState.Hot:
                backColor         = Color.FromArgb(64, SystemColors.HotTrack);
                outlineColor      = backColor;
                arrowFillColor    = Color.Blue;
                arrowOutlineColor = Color.White;
                break;

            case UI.ButtonState.Normal:
                backColor         = Color.Transparent;
                outlineColor      = Color.Transparent;
                arrowFillColor    = Color.Black;
                arrowOutlineColor = Color.White;
                break;

            case UI.ButtonState.Pressed:
                backColor         = Color.FromArgb(192, SystemColors.Highlight);
                outlineColor      = Color.FromArgb(192, SystemColors.Highlight);
                arrowFillColor    = Color.Blue;
                arrowOutlineColor = Color.White;
                break;

            default:
                throw new InvalidEnumArgumentException("buttonState");
            }

            // Draw parent background
            IPaintBackground asIpb = Parent as IPaintBackground;

            if (!this.drawWithGradient || asIpb == null)
            {
                if (asIpb != null)
                {
                    Rectangle screenRect = RectangleToScreen(ClientRectangle);
                    Rectangle parentRect = Parent.RectangleToClient(screenRect);

                    g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(g, parentRect);
                    g.TranslateTransform(+Left, +Top, MatrixOrder.Append);
                }
                else
                {
                    using (SolidBrush backBrush = new SolidBrush(BackColor))
                    {
                        g.FillRectangle(backBrush, ClientRectangle);
                    }
                }
            }
            else
            {
                if (this.backBufferSurface != null &&
                    (this.backBufferSurface.Width != ClientSize.Width || this.backBufferSurface.Height != ClientSize.Height))
                {
                    this.backBuffer.Dispose();
                    this.backBuffer = null;

                    this.backBufferSurface.Dispose();
                    this.backBufferSurface = null;
                }

                if (this.backBufferSurface == null)
                {
                    this.backBufferSurface = new Surface(ClientSize.Width, ClientSize.Height);
                    this.backBuffer        = new RenderArgs(this.backBufferSurface);
                }

                Rectangle screenRect = RectangleToScreen(ClientRectangle);
                Rectangle parentRect = Parent.RectangleToClient(screenRect);

                using (Graphics bg = Graphics.FromImage(this.backBuffer.Bitmap))
                {
                    bg.TranslateTransform(-Left, -Top, MatrixOrder.Append);
                    asIpb.PaintBackground(bg, parentRect);
                }

                BitmapData bitmapData = this.backBuffer.Bitmap.LockBits(
                    new Rectangle(0, 0, this.backBuffer.Bitmap.Width, this.backBuffer.Bitmap.Height),
                    ImageLockMode.ReadWrite,
                    PixelFormat.Format32bppArgb);

                int startAlpha;
                int finishAlpha;

                if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Up)
                {
                    startAlpha  = 255;
                    finishAlpha = 0;
                }
                else if (this.arrowDirection == ArrowDirection.Right || this.ArrowDirection == ArrowDirection.Down)
                {
                    startAlpha  = 0;
                    finishAlpha = 255;
                }
                else
                {
                    throw new InvalidEnumArgumentException("this.arrowDirection");
                }

                unsafe
                {
                    if (this.arrowDirection == ArrowDirection.Left || this.arrowDirection == ArrowDirection.Right)
                    {
                        for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                        {
                            float lerp = (float)x / (float)(this.backBuffer.Bitmap.Width - 1);

                            if (this.arrowDirection == ArrowDirection.Left)
                            {
                                lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));
                            }
                            else
                            {
                                lerp = (float)Math.Sin(lerp * (Math.PI / 2.0));
                            }

                            byte  alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte *pb    = (byte *)bitmapData.Scan0.ToPointer() + (x * 4) + 3; // *4 because 4-bytes per pixel, +3 to get to alpha channel

                            for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                            {
                                *pb = alpha;
                                pb += bitmapData.Stride;
                            }
                        }
                    }
                    else if (this.arrowDirection == ArrowDirection.Up || this.arrowDirection == ArrowDirection.Down)
                    {
                        for (int y = 0; y < this.backBuffer.Bitmap.Height; ++y)
                        {
                            float lerp = (float)y / (float)(this.backBuffer.Bitmap.Height - 1);
                            lerp = 1.0f - (float)Math.Cos(lerp * (Math.PI / 2.0));

                            byte  alpha = (byte)(startAlpha + ((int)(lerp * (finishAlpha - startAlpha))));
                            byte *pb    = (byte *)bitmapData.Scan0.ToPointer() + (y * bitmapData.Stride) + 3; // *Stride for access to start of row, +3 to get to alpha channel

                            for (int x = 0; x < this.backBuffer.Bitmap.Width; ++x)
                            {
                                *pb = alpha;
                                pb += 4; // 4 for byte size of pixel
                            }
                        }
                    }
                }

                this.backBuffer.Bitmap.UnlockBits(bitmapData);
                bitmapData = null;

                g.DrawImage(this.backBuffer.Bitmap, new Point(0, 0));
            }

            using (SolidBrush fillBrush = new SolidBrush(backColor))
            {
                g.FillRectangle(fillBrush, ClientRectangle);
            }

            // Draw outline
            using (Pen outlinePen = new Pen(outlineColor))
            {
                g.DrawRectangle(outlinePen, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));
            }

            // Draw button
            g.SmoothingMode = SmoothingMode.AntiAlias;

            const int arrowInset = 3;
            int       arrowSize  = Math.Min(ClientSize.Width - arrowInset * 2, ClientSize.Height - arrowInset * 2) - 1;

            PointF a;
            PointF b;
            PointF c;

            switch (this.arrowDirection)
            {
            case ArrowDirection.Left:
                a = new PointF(arrowInset, ClientSize.Height / 2);
                b = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height - arrowSize) / 2);
                c = new PointF(ClientSize.Width - arrowInset, (ClientSize.Height + arrowSize) / 2);
                break;

            case ArrowDirection.Right:
                a = new PointF(ClientSize.Width - arrowInset, ClientSize.Height / 2);
                b = new PointF(arrowInset, (ClientSize.Height - arrowSize) / 2);
                c = new PointF(arrowInset, (ClientSize.Height + arrowSize) / 2);
                break;

            case ArrowDirection.Up:
                a = new PointF(ClientSize.Width / 2, (ClientSize.Height - arrowSize) / 2);
                b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height + arrowSize) / 2);
                break;

            case ArrowDirection.Down:
                a = new PointF(ClientSize.Width / 2, (ClientSize.Height + arrowSize) / 2);
                b = new PointF((ClientSize.Width - arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                c = new PointF((ClientSize.Width + arrowSize) / 2, (ClientSize.Height - arrowSize) / 2);
                break;

            default:
                throw new InvalidEnumArgumentException("this.arrowDirection");
            }

            // SPIKE in order to get this rendering correctly right away
            if (this.arrowDirection == ArrowDirection.Down)
            {
                SmoothingMode oldSM = g.SmoothingMode;
                g.SmoothingMode = SmoothingMode.None;

                float top         = b.Y - 2;
                float left        = b.X;
                float right       = c.X;
                int   squareCount = (int)((right - left) / 3);

                Brush outlineBrush  = new SolidBrush(arrowOutlineColor);
                Brush interiorBrush = new SolidBrush(arrowFillColor);

                g.FillRectangle(interiorBrush, left, top, right - left + 1, 3);

                ++left;
                while (left < right)
                {
                    RectangleF rect = new RectangleF(left, top + 1, 1, 1);
                    g.FillRectangle(outlineBrush, rect);
                    left += 2;
                }

                outlineBrush.Dispose();
                outlineBrush = null;

                interiorBrush.Dispose();
                interiorBrush = null;

                a.Y += 2;
                b.Y += 2;
                c.Y += 2;

                g.SmoothingMode = oldSM;
            }

            if (this.reverseArrowColors)
            {
                Utility.Swap(ref arrowFillColor, ref arrowOutlineColor);
            }

            using (Brush buttonBrush = new SolidBrush(arrowFillColor))
            {
                g.FillPolygon(buttonBrush, new PointF[] { a, b, c });
            }

            using (Pen buttonPen = new Pen(arrowOutlineColor, this.arrowOutlineWidth))
            {
                g.DrawPolygon(buttonPen, new PointF[] { a, b, c });
            }
        }
Пример #47
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            Amount1 = newToken.GetProperty<Int32Property>(PropertyNames.Amount1).Value;
            Amount2 = newToken.GetProperty<Int32Property>(PropertyNames.Amount2).Value;
            Amount3 = (byte)((int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Amount3).Value);
            Amount4 = ColorBgra.FromOpaqueInt32(newToken.GetProperty<Int32Property>(PropertyNames.Amount4).Value);
            Amount5 = ColorBgra.FromOpaqueInt32(newToken.GetProperty<Int32Property>(PropertyNames.Amount5).Value);
            Amount6 = ColorBgra.FromOpaqueInt32(newToken.GetProperty<Int32Property>(PropertyNames.Amount6).Value);
            Amount7 = ColorBgra.FromOpaqueInt32(newToken.GetProperty<Int32Property>(PropertyNames.Amount7).Value);

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

            Bitmap tattersallBitmap = new Bitmap(selection.Width, selection.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics tattersallGraphics = Graphics.FromImage(tattersallBitmap);

            // Fill with white
            Rectangle backgroundRect = new Rectangle(0, 0, selection.Width, selection.Height);
            using (SolidBrush backColor = new SolidBrush(Amount7))
                tattersallGraphics.FillRectangle(backColor, backgroundRect);

            // Set Brush Styles
            Brush brush1, brush2, brush3;
            switch (Amount3)
            {
                case 0: // Solid 33% Opacity
                    brush1 = new SolidBrush(Color.FromArgb(85, Amount4));
                    brush2 = new SolidBrush(Color.FromArgb(85, Amount5));
                    brush3 = new SolidBrush(Color.FromArgb(85, Amount6));
                    break;
                case 1: // Solid 66% Opacity
                    brush1 = new SolidBrush(Color.FromArgb(170, Amount4));
                    brush2 = new SolidBrush(Color.FromArgb(170, Amount5));
                    brush3 = new SolidBrush(Color.FromArgb(170, Amount6));
                    break;
                case 2: // Diagonal Lines Up
                    brush1 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Amount4, Amount7);
                    brush2 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Amount5, Amount7);
                    brush3 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Amount6, Amount7);
                    break;
                case 3: // Diagonal Lines Down
                    brush1 = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Amount4, Amount7);
                    brush2 = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Amount5, Amount7);
                    brush3 = new HatchBrush(HatchStyle.DarkDownwardDiagonal, Amount6, Amount7);
                    break;
                case 4: // 50/50 Dots
                    brush1 = new HatchBrush(HatchStyle.Percent50, Amount4, Amount7);
                    brush2 = new HatchBrush(HatchStyle.Percent50, Amount5, Amount7);
                    brush3 = new HatchBrush(HatchStyle.Percent50, Amount6, Amount7);
                    break;
                default:
                    brush1 = new SolidBrush(Color.FromArgb(85, Amount4));
                    brush2 = new SolidBrush(Color.FromArgb(85, Amount5));
                    brush3 = new SolidBrush(Color.FromArgb(85, Amount6));
                    break;
            }

            // Set pen styles.
            Pen pen1 = new Pen(brush1, Amount1);
            brush1.Dispose();
            Pen pen2 = new Pen(brush2, Amount1);
            brush2.Dispose();
            Pen pen3 = new Pen(brush3, Amount1);
            brush3.Dispose();

            // Calculate the number of lines will fit in the selection
            int xLoops = (int)Math.Ceiling((double)selection.Height / ((Amount1 + Amount2) * 3));
            int yLoops = (int)Math.Ceiling((double)selection.Width / ((Amount1 + Amount2) * 3));

            // Draw Horizontal Lines
            for (int i = 0; i < xLoops; i++)
            {
                // Create points that define line.
                Point point1 = new Point(0, Amount1 / 2 + (Amount1 + Amount2) * i * 3);
                Point point2 = new Point(selection.Width, Amount1 / 2 + (Amount1 + Amount2) * i * 3);

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen1, point1, point2);

                // Create points that define line.
                Point point3 = new Point(0, Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2));
                Point point4 = new Point(selection.Width, Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2));

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen2, point3, point4);

                // Create points that define line.
                Point point5 = new Point(0, Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2) * 2);
                Point point6 = new Point(selection.Width, Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2) * 2);

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen3, point5, point6);

            }

            // Draw Vertical Lines
            for (int i = 0; i < yLoops; i++)
            {
                // Create points that define line.
                Point point1 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3, 0);
                Point point2 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3, selection.Height);

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen1, point1, point2);

                // Create points that define line.
                Point point3 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2), 0);
                Point point4 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2), selection.Height);

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen2, point3, point4);

                // Create points that define line.
                Point point5 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2) * 2, 0);
                Point point6 = new Point(Amount1 / 2 + (Amount1 + Amount2) * i * 3 + (Amount1 + Amount2) * 2, selection.Height);

                // Draw line to screen.
                tattersallGraphics.DrawLine(pen3, point5, point6);
            }

            pen1.Dispose();
            pen2.Dispose();
            pen3.Dispose();

            tattersallSurface = Surface.CopyFromBitmap(tattersallBitmap);
            tattersallBitmap.Dispose();

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
Пример #48
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.backBuffer != null)
                {
                    this.backBuffer.Dispose();
                    this.backBuffer = null;
                }

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

            base.Dispose(disposing);
        }