コード例 #1
0
        public virtual void BeforeRender()
        {
            if (!this.lerpCacheIsValid)
            {
                byte startAlpha;
                byte endAlpha;

                if (this.AlphaOnly)
                {
                    ComputeAlphaOnlyValuesFromColors(this.startColor, this.endColor, out startAlpha, out endAlpha);
                }
                else
                {
                    startAlpha = this.startColor.A;
                    endAlpha   = this.endColor.A;
                }

                this.lerpAlphas = new byte[256];
                this.lerpColors = new ColorBgra[256];

                for (int i = 0; i < 256; ++i)
                {
                    byte a = (byte)i;
                    this.lerpColors[a] = ColorBgra.Blend(this.startColor, this.endColor, a);
                    this.lerpAlphas[a] = (byte)(startAlpha + ((endAlpha - startAlpha) * a) / 255);
                }

                this.lerpCacheIsValid = true;
            }
        }
コード例 #2
0
        private unsafe Color GetColorFromPoint(PointD point)
        {
            var pixels = GetPixelsFromPoint(point);

            fixed(ColorBgra *ptr = pixels)
            return(ColorBgra.Blend(ptr, pixels.Length).ToCairoColor());
        }
コード例 #3
0
        protected override unsafe void OnRender(Rectangle[] rois, int startIndex, int length)
        {
            double radiusDelta          = this.maxRadius - this.minRadius;
            double effectiveRadiusDelta = radiusDelta;

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

            ColorBgra *samples = stackalloc ColorBgra[sampleCount];

            Random localRand = threadRand;

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

                for (int y = roi.Top; y < roi.Bottom; ++y)
                {
                    ColorBgra *dstPtr = DstArgs.Surface.GetPointAddressUnchecked(roi.Left, y);

                    for (int x = roi.Left; x < roi.Right; ++x)
                    {
                        for (int sampleIndex = 0; sampleIndex < sampleCount; ++sampleIndex)
                        {
                            double srcX;
                            double srcY;

                            while (true)
                            {
                                double angle         = localRand.NextDouble() * Math.PI * 2.0;
                                double distanceDelta = localRand.NextDouble() * effectiveRadiusDelta;
                                double distance      = distanceDelta + this.minRadius;

                                srcX = x + (Math.Cos(angle) * distance);
                                srcY = y + (Math.Sin(angle) * distance);

                                if (srcX >= 0 && srcX <= SrcArgs.Width && srcY >= 0 && srcY <= SrcArgs.Height)
                                {
                                    break;
                                }
                            }

                            samples[sampleIndex] = SrcArgs.Surface.GetBilinearSample((float)srcX, (float)srcY);
                        }

                        ColorBgra result = ColorBgra.Blend(samples, sampleCount);

                        dstPtr->Bgra = result.Bgra;
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #4
0
        public unsafe override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
        {
            Gdk.Point[] pointOffsets = RecalcPointOffsets(Data.Fragments, Data.Rotation, Data.Distance);

            int poLength = pointOffsets.Length;

            Gdk.Point *pointOffsetsPtr = stackalloc Gdk.Point[poLength];

            for (int i = 0; i < poLength; ++i)
            {
                pointOffsetsPtr[i] = pointOffsets[i];
            }

            ColorBgra *samples = stackalloc ColorBgra[poLength];

            // Cache these for a massive performance boost
            int        src_width    = src.Width;
            int        src_height   = src.Height;
            ColorBgra *src_data_ptr = (ColorBgra *)src.DataPtr;

            foreach (Gdk.Rectangle rect in rois)
            {
                for (int y = rect.Top; y <= rect.GetBottom(); y++)
                {
                    ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = rect.Left; x <= rect.GetRight(); x++)
                    {
                        int sampleCount = 0;

                        for (int i = 0; i < poLength; ++i)
                        {
                            int u = x - pointOffsetsPtr[i].X;
                            int v = y - pointOffsetsPtr[i].Y;

                            if (u >= 0 && u < src_width && v >= 0 && v < src_height)
                            {
                                samples[sampleCount] = src.GetPointUnchecked(src_data_ptr, src_width, u, v);
                                ++sampleCount;
                            }
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #5
0
        protected override unsafe void OnRender(Rectangle[] renderRects, int startIndex, int length)
        {
            Surface dst = DstArgs.Surface;
            Surface src = SrcArgs.Surface;

            int    poLength     = this.pointOffsets.Length;
            Point *pointOffsets = stackalloc Point[poLength];

            for (int i = 0; i < poLength; ++i)
            {
                pointOffsets[i] = this.pointOffsets[i];
            }

            ColorBgra *samples = stackalloc ColorBgra[poLength];

            for (int n = startIndex; n < startIndex + length; ++n)
            {
                Rectangle rect = renderRects[n];

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

                    for (int x = rect.Left; x < rect.Right; x++)
                    {
                        int sampleCount = 0;

                        for (int i = 0; i < poLength; ++i)
                        {
                            int u = x - pointOffsets[i].X;
                            int v = y - pointOffsets[i].Y;

                            if (u >= 0 && u < src.Bounds.Width && v >= 0 && v < src.Bounds.Height)
                            {
                                samples[sampleCount] = src.GetPointUnchecked(u, v);
                                ++sampleCount;
                            }
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #6
0
ファイル: ColorPickerTool.cs プロジェクト: ykafia/Paint.Net4
        private static unsafe ColorBgra SampleArea(Surface surface, RectInt32 sampleArea)
        {
            List <ColorBgra> items = new List <ColorBgra>();

            for (int i = sampleArea.Top; i < sampleArea.Bottom; i++)
            {
                ColorBgra *pointAddressUnchecked = surface.GetPointAddressUnchecked(sampleArea.Left, i);
                for (int j = sampleArea.Left; j < sampleArea.Right; j++)
                {
                    items.Add(pointAddressUnchecked[0]);
                    pointAddressUnchecked++;
                }
            }
            if (items.Count == 0)
            {
                return(ColorBgra.TransparentBlack);
            }
            return(ColorBgra.Blend(items.ToArrayEx <ColorBgra>()));
        }
コード例 #7
0
        protected unsafe override void RenderLine(ISurface src, ISurface dst, Rectangle rect)
        {
            var pointOffsets = RecalcPointOffsets(fragments, rotation, distance);

            int    poLength        = pointOffsets.Length;
            Point *pointOffsetsPtr = stackalloc Point[poLength];

            for (int i = 0; i < poLength; ++i)
            {
                pointOffsetsPtr[i] = pointOffsets[i];
            }

            ColorBgra *samples = stackalloc ColorBgra[poLength];

            int src_width  = src.Width;
            int src_height = src.Height;

            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++)
                {
                    int sampleCount = 0;

                    for (int i = 0; i < poLength; ++i)
                    {
                        int u = x - pointOffsetsPtr[i].X;
                        int v = y - pointOffsetsPtr[i].Y;

                        if (u >= 0 && u < src_width && v >= 0 && v < src_height)
                        {
                            samples[sampleCount] = src.GetPoint(u, v);
                            ++sampleCount;
                        }
                    }

                    *dstPtr = ColorBgra.Blend(samples, sampleCount);
                    ++dstPtr;
                }
            }
        }
コード例 #8
0
        protected override unsafe void OnRender(Rectangle[] rois, int startIndex, int length)
        {
            Surface dst = DstArgs.Surface;
            Surface src = SrcArgs.Surface;

            ColorBgra *samples = stackalloc ColorBgra[this.points.Length];

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

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

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        int sampleCount = 0;

                        PointF a = new PointF((float)x + points[0].X, (float)y + points[0].Y);
                        PointF b = new PointF((float)x + points[points.Length - 1].X, (float)y + points[points.Length - 1].Y);

                        for (int j = 0; j < this.points.Length; ++j)
                        {
                            PointF pt = new PointF(this.points[j].X + (float)x, this.points[j].Y + (float)y);

                            if (pt.X >= 0 && pt.Y >= 0 && pt.X <= (src.Width - 1) && pt.Y <= (src.Height - 1))
                            {
                                samples[sampleCount] = src.GetBilinearSample(pt.X, pt.Y);
                                ++sampleCount;
                            }
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #9
0
        public unsafe override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
        {
            PointD start = new PointD(0, 0);
            double theta = ((double)(Data.Angle + 180) * 2 * Math.PI) / 360.0;
            double alpha = (double)Data.Distance;
            PointD end   = new PointD((float)alpha * Math.Cos(theta), (float)(-alpha * Math.Sin(theta)));

            if (Data.Centered)
            {
                start.X = -end.X / 2.0f;
                start.Y = -end.Y / 2.0f;

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

            PointD[] points = new PointD[((1 + Data.Distance) * 3) / 2];

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

            ColorBgra *samples = stackalloc ColorBgra[points.Length];

            ColorBgra *src_dataptr = (ColorBgra *)src.DataPtr;
            int        src_width   = src.Width;
            int        src_height  = src.Height;

            foreach (Gdk.Rectangle rect in rois)
            {
                for (int y = rect.Top; y <= rect.GetBottom(); ++y)
                {
                    ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = rect.Left; x <= rect.GetRight(); ++x)
                    {
                        int sampleCount = 0;

                        for (int j = 0; j < points.Length; ++j)
                        {
                            PointD pt = new PointD(points[j].X + (float)x, points[j].Y + (float)y);

                            if (pt.X >= 0 && pt.Y >= 0 && pt.X <= (src_width - 1) && pt.Y <= (src_height - 1))
                            {
                                samples[sampleCount] = src.GetBilinearSample(src_dataptr, src_width, src_height, (float)pt.X, (float)pt.Y);
                                ++sampleCount;
                            }
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Replaces a portion of the destination bitmap with the surface bitmap using a brush as an alpha mask.
        /// </summary>
        /// <param name="surface">The surface contains the source bitmap. It will be drawn to dest.</param>
        /// <param name="dest">The bitmap to edit.</param>
        /// <param name="alphaMask">The brush used to draw.</param>
        /// <param name="location">The location to draw the brush at.</param>
        public static unsafe void OverwriteMasked(Surface surface, Bitmap dest, Bitmap alphaMask, Point location)
        {
            // Calculates the brush regions outside the bounding area of the surface.
            int negativeX = location.X < 0 ? -location.X : 0;
            int negativeY = location.Y < 0 ? -location.Y : 0;
            int extraX    = Math.Max(location.X + alphaMask.Width - surface.Width, 0);
            int extraY    = Math.Max(location.Y + alphaMask.Height - surface.Height, 0);

            int adjWidth  = alphaMask.Width - negativeX - extraX;
            int adjHeight = alphaMask.Height - negativeY - extraY;

            if (adjWidth < 1 || adjHeight < 1 ||
                surface.Width != dest.Width || surface.Height != dest.Height)
            {
                return;
            }

            Rectangle adjBounds = new Rectangle(
                location.X < 0 ? 0 : location.X,
                location.Y < 0 ? 0 : location.Y,
                adjWidth,
                adjHeight);

            BitmapData destData = dest.LockBits(
                adjBounds,
                ImageLockMode.ReadWrite,
                dest.PixelFormat);

            BitmapData alphaMaskData = alphaMask.LockBits(
                new Rectangle(0, 0,
                              alphaMask.Width,
                              alphaMask.Height),
                ImageLockMode.ReadOnly,
                alphaMask.PixelFormat);

            byte *destRow      = (byte *)destData.Scan0;
            byte *alphaMaskRow = (byte *)alphaMaskData.Scan0;
            byte *srcRow       = (byte *)surface.Scan0.Pointer;
            float alphaFactor;

            for (int y = 0; y < adjHeight; y++)
            {
                ColorBgra *alphaMaskPtr = (ColorBgra *)(alphaMaskRow + negativeX * 4 + ((negativeY + y) * alphaMaskData.Stride));
                ColorBgra *srcPtr       = (ColorBgra *)(srcRow + adjBounds.X * 4 + ((adjBounds.Y + y) * surface.Stride));
                ColorBgra *destPtr      = (ColorBgra *)(destRow + (y * destData.Stride));

                for (int x = 0; x < adjWidth; x++)
                {
                    ColorBgra newColor = ColorBgra.Blend(
                        destPtr->ConvertFromPremultipliedAlpha(),
                        *srcPtr,
                        alphaMaskPtr->A);

                    alphaFactor = newColor.A / 255f;
                    destPtr->B  = (byte)Math.Ceiling(newColor.B * alphaFactor);
                    destPtr->G  = (byte)Math.Ceiling(newColor.G * alphaFactor);
                    destPtr->R  = (byte)Math.Ceiling(newColor.R * alphaFactor);
                    destPtr->A  = newColor.A;

                    alphaMaskPtr++;
                    destPtr++;
                    srcPtr++;
                }
            }

            dest.UnlockBits(destData);
            alphaMask.UnlockBits(alphaMaskData);
        }
コード例 #11
0
        public unsafe override void Render(ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
        {
            ColorBgra colPrimary     = PintaCore.Palette.PrimaryColor.ToColorBgra();
            ColorBgra colSecondary   = PintaCore.Palette.SecondaryColor.ToColorBgra();
            ColorBgra colTransparent = ColorBgra.Transparent;

            int aaSampleCount = Data.Quality * Data.Quality;

            Cairo.PointD *aaPoints = stackalloc Cairo.PointD[aaSampleCount];
            Utility.GetRgssOffsets(aaPoints, aaSampleCount, Data.Quality);
            ColorBgra *samples = stackalloc ColorBgra[aaSampleCount];

            TransformData td;

            foreach (Gdk.Rectangle rect in rois)
            {
                for (int y = rect.Top; y <= rect.GetBottom(); y++)
                {
                    ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);

                    double relativeY = y - Data.CenterOffset.Y;

                    for (int x = rect.Left; x <= rect.GetRight(); x++)
                    {
                        double relativeX = x - Data.CenterOffset.X;

                        int sampleCount = 0;

                        for (int p = 0; p < aaSampleCount; ++p)
                        {
                            td.X = relativeX + aaPoints[p].X;
                            td.Y = relativeY - aaPoints[p].Y;

                            InverseTransform(ref td);

                            float sampleX = (float)(td.X + Data.CenterOffset.X);
                            float sampleY = (float)(td.Y + Data.CenterOffset.Y);

                            ColorBgra sample = colPrimary;

                            if (IsOnSurface(src, sampleX, sampleY))
                            {
                                sample = src.GetBilinearSample(sampleX, sampleY);
                            }
                            else
                            {
                                switch (Data.EdgeBehavior)
                                {
                                case WarpEdgeBehavior.Clamp:
                                    sample = src.GetBilinearSampleClamped(sampleX, sampleY);
                                    break;

                                case WarpEdgeBehavior.Wrap:
                                    sample = src.GetBilinearSampleWrapped(sampleX, sampleY);
                                    break;

                                case WarpEdgeBehavior.Reflect:
                                    sample = src.GetBilinearSampleClamped(ReflectCoord(sampleX, src.Width), ReflectCoord(sampleY, src.Height));

                                    break;

                                case WarpEdgeBehavior.Primary:
                                    sample = colPrimary;
                                    break;

                                case WarpEdgeBehavior.Secondary:
                                    sample = colSecondary;
                                    break;

                                case WarpEdgeBehavior.Transparent:
                                    sample = colTransparent;
                                    break;

                                case WarpEdgeBehavior.Original:
                                    sample = src.GetColorBgra(x, y);
                                    break;

                                default:

                                    break;
                                }
                            }

                            samples[sampleCount] = sample;
                            ++sampleCount;
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);
                        ++dstPtr;
                    }
                }
            }
        }
コード例 #12
0
        protected unsafe override void RenderLine(ISurface src, ISurface dst, Rectangle rect)
        {
            ColorBgra colTransparent = ColorBgra.Transparent;

            int     aaSampleCount = quality * quality;
            PointD *aaPoints      = stackalloc PointD[aaSampleCount];

            Utility.GetRgssOffsets(aaPoints, aaSampleCount, quality);
            ColorBgra *samples = stackalloc ColorBgra[aaSampleCount];

            TransformData td;

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

                double relativeY = y - center_offset.Y;

                for (int x = rect.Left; x <= rect.Right; x++)
                {
                    double relativeX = x - center_offset.X;

                    int sampleCount = 0;

                    for (int p = 0; p < aaSampleCount; ++p)
                    {
                        td.X = relativeX + aaPoints[p].X;
                        td.Y = relativeY - aaPoints[p].Y;

                        InverseTransform(ref td);

                        float sampleX = (float)(td.X + center_offset.X);
                        float sampleY = (float)(td.Y + center_offset.Y);

                        ColorBgra sample = primary_color;

                        if (IsOnSurface(src, sampleX, sampleY))
                        {
                            sample = Utility.GetBilinearSampleClamped(src, sampleX, sampleY);
                        }
                        else
                        {
                            switch (edge_behavior)
                            {
                            case WarpEdgeBehavior.Clamp:
                                sample = Utility.GetBilinearSampleClamped(src, sampleX, sampleY);
                                break;

                            case WarpEdgeBehavior.Wrap:
                                sample = Utility.GetBilinearSampleWrapped(src, sampleX, sampleY);
                                break;

                            case WarpEdgeBehavior.Reflect:
                                sample = Utility.GetBilinearSampleClamped(src, ReflectCoord(sampleX, src.Width), ReflectCoord(sampleY, src.Height));

                                break;

                            case WarpEdgeBehavior.Primary:
                                sample = primary_color;
                                break;

                            case WarpEdgeBehavior.Secondary:
                                sample = secondary_color;
                                break;

                            case WarpEdgeBehavior.Transparent:
                                sample = colTransparent;
                                break;

                            case WarpEdgeBehavior.Original:
                                sample = src.GetPoint(x, y);
                                break;

                            default:

                                break;
                            }
                        }

                        samples[sampleCount] = sample;
                        ++sampleCount;
                    }

                    *dstPtr = ColorBgra.Blend(samples, sampleCount);
                    ++dstPtr;
                }
            }
        }
コード例 #13
0
ファイル: HistogramWidget.cs プロジェクト: mfcallahan/Pinta
        private void DrawChannel(Context g, ColorBgra color, int channel, long max, float mean)
        {
            var rect = new Rectangle(0, 0, AllocatedWidth, AllocatedHeight);

            var l = (int)rect.X;
            var t = (int)rect.Y;
            var r = (int)(rect.X + rect.Width);
            var b = (int)(rect.Y + rect.Height);

            var entries = Histogram.Entries;
            var hist    = Histogram.HistogramValues[channel];

            ++max;

            if (FlipHorizontal)
            {
                Utility.Swap(ref l, ref r);
            }

            if (!FlipVertical)
            {
                Utility.Swap(ref t, ref b);
            }

            var points = new PointD[entries + 2];

            points[entries]     = new PointD(Utility.Lerp(l, r, -1), Utility.Lerp(t, b, 20));
            points[entries + 1] = new PointD(Utility.Lerp(l, r, -1), Utility.Lerp(b, t, 20));

            for (var i = 0; i < entries; i += entries - 1)
            {
                points[i] = new PointD(
                    Utility.Lerp(l, r, (float)hist[i] / (float)max),
                    Utility.Lerp(t, b, (float)i / (float)entries));

                CheckPoint(rect, points[i]);
            }

            var sum3 = hist[0] + hist[1];

            for (var i = 1; i < entries - 1; ++i)
            {
                sum3 += hist[i + 1];

                points[i] = new PointD(
                    Utility.Lerp(l, r, (float)(sum3) / (float)(max * 3.1f)),
                    Utility.Lerp(t, b, (float)i / (float)entries));

                CheckPoint(rect, points[i]);
                sum3 -= hist[i - 1];
            }

            var intensity   = selected[channel] ? (byte)96 : (byte)32;
            var pen_color   = ColorBgra.Blend(ColorBgra.Black, color, intensity);
            var brush_color = color;

            brush_color.A = intensity;

            g.LineWidth = 1;

            g.Rectangle(rect);
            g.Clip();
            g.DrawPolygonal(points, pen_color.ToCairoColor());
            g.FillPolygonal(points, brush_color.ToCairoColor());
        }
コード例 #14
0
ファイル: TwistEffect.cs プロジェクト: cyberjaxx/OpenPDN
        protected unsafe override void OnRender(Rectangle[] rois, int startIndex, int length)
        {
            double twist = this.amount * this.amount * Math.Sign(this.amount);

            Surface dst = DstArgs.Surface;
            Surface src = SrcArgs.Surface;

            float hw = dst.Width / 2.0f;

            hw += (float)(hw * this.offset.First);
            float hh = dst.Height / 2.0f;

            hh += (float)(hh * this.offset.Second);

            //*double maxrad = Math.Min(dst.Width / 2.0, dst.Height / 2.0);
            double invmaxrad = 1.0 / Math.Min(dst.Width / 2.0, dst.Height / 2.0);

            int     aaLevel   = this.quality;
            int     aaSamples = aaLevel * aaLevel;
            PointF *aaPoints  = stackalloc PointF[aaSamples];

            Utility.GetRgssOffsets(aaPoints, aaSamples, aaLevel);

            ColorBgra *samples = stackalloc ColorBgra[aaSamples];

            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);
                    ColorBgra *srcPtr = src.GetPointAddressUnchecked(rect.Left, y);

                    for (int x = rect.Left; x < rect.Right; x++)
                    {
                        float i = x - hw;

                        int sampleCount = 0;

                        for (int p = 0; p < aaSamples; ++p)
                        {
                            float u = i + aaPoints[p].X;
                            float v = j + aaPoints[p].Y;

                            double rad   = Math.Sqrt(u * u + v * v);
                            double theta = Math.Atan2(v, u);

                            double t = 1 - ((rad * this.size) * invmaxrad);

                            t = (t < 0) ? 0 : (t * t * t);

                            theta += (t * twist) * inv100;

                            float sampleX = (hw + (float)(rad * Math.Cos(theta)));
                            float sampleY = (hh + (float)(rad * Math.Sin(theta)));

                            samples[sampleCount] = src.GetBilinearSampleClamped(sampleX, sampleY);
                            ++sampleCount;
                        }

                        *dstPtr = ColorBgra.Blend(samples, sampleCount);


                        ++dstPtr;
                        ++srcPtr;
                    }
                }
            }
        }
コード例 #15
0
ファイル: RollControl.cs プロジェクト: ykafia/Paint.Net4
        private void DrawToDrawingContext(IDrawingContext dc)
        {
            RectInt32 rect = base.ClientRectangle.ToRectInt32();

            dc.Clear(new ColorRgba128Float?(this.BackColor));
            using (dc.UseTranslateTransform(0.5f, 0.5f, MatrixMultiplyOrder.Append))
            {
                using (dc.UseAntialiasMode(AntialiasMode.PerPrimitive))
                {
                    RectInt32  num2      = RectInt32.Inflate(rect, -2, -2);
                    int        num3      = Math.Min(num2.Width, num2.Height);
                    PointInt32 center    = new PointInt32(num2.X + (num3 / 2), num2.Y + (num3 / 2));
                    double     radius    = ((double)num3) / 2.0;
                    double     scale     = ((double)num3) / 3.0;
                    double     num7      = ((double)num3) / 2.0;
                    double     d         = -MathUtil.DegreesToRadians(this.angle);
                    double     num9      = Math.Cos(d);
                    double     num10     = Math.Sin(d);
                    double     rx        = (this.rollAmount * Math.Cos(MathUtil.DegreesToRadians(this.rollDirection))) / 90.0;
                    double     num12     = (this.rollAmount * Math.Sin(MathUtil.DegreesToRadians(this.rollDirection))) / 90.0;
                    double     num13     = rx / (((num12 * num12) < 0.99) ? Math.Sqrt(1.0 - (num12 * num12)) : 1.0);
                    double     num14     = num12 / (((rx * rx) < 0.99) ? Math.Sqrt(1.0 - (rx * rx)) : 1.0);
                    double     thickness = (this.mouseEntered && !this.onSphere) ? 2.0 : 1.0;
                    if (this.ringOuterEllipseGeometry == null)
                    {
                        this.ringOuterEllipseGeometry = new EllipseGeometry();
                    }
                    if (this.ringInnerEllipseGeometry == null)
                    {
                        this.ringInnerEllipseGeometry = new EllipseGeometry();
                    }
                    if (this.ringFillGeometry == null)
                    {
                        this.ringFillGeometry = new CombinedGeometry(GeometryCombineMode.Exclude, this.ringOuterEllipseGeometry, this.ringInnerEllipseGeometry);
                    }
                    this.ringOuterEllipseGeometry.Center  = center;
                    this.ringOuterEllipseGeometry.RadiusX = radius - 0.5;
                    this.ringOuterEllipseGeometry.RadiusY = radius - 0.5;
                    this.ringInnerEllipseGeometry.Center  = center;
                    this.ringInnerEllipseGeometry.RadiusX = radius;
                    this.ringInnerEllipseGeometry.RadiusY = radius;
                    dc.FillGeometry(this.ringFillGeometry, ringFillBrush, null);
                    if (this.ringOutlinePen == null)
                    {
                        this.ringOutlinePen = new PaintDotNet.UI.Media.Pen();
                    }
                    this.ringOutlinePen.Brush     = ringOutlineBrush;
                    this.ringOutlinePen.Thickness = thickness;
                    dc.DrawCircle(center, radius, this.ringOutlinePen);
                    double num16 = (this.mouseEntered && !this.onSphere) ? ((double)2) : ((double)1);
                    dc.DrawLine(center.X + (scale * num9), center.Y + (scale * num10), center.X + (num7 * num9), center.Y + (num7 * num10), thetaLineBrush, num16);
                    using (dc.UseTranslateTransform((float)center.X, (float)center.Y, MatrixMultiplyOrder.Prepend))
                    {
                        double num17 = (this.angle * 3.1415926535897931) / 180.0;
                        float  num18 = (this.mouseEntered && this.onSphere) ? 1.5f : 1f;
                        int    num19 = 0x18;
                        for (int i = 0; i >= (-num19 / 2); i--)
                        {
                            double num22 = (i * 3.1415926535897931) / ((double)num19);
                            double num23 = -num17 - 3.1415926535897931;
                            double xs    = Math.Cos(num23) * Math.Cos(num22);
                            double ys    = Math.Sin(num23) * Math.Cos(num22);
                            double zs    = Math.Sin(num22);
                            double num30 = ((double)(i + (num19 / 2))) / ((double)(num19 / 2));
                            byte   index = Int32Util.ClampToByte((int)(num30 * 255.0));
                            if (this.latBrushCache[index] == null)
                            {
                                ColorBgra bgra = ColorBgra.Blend(latGradStart, latGradEnd, index);
                                this.latBrushCache[index] = SolidColorBrushCache.Get((ColorRgba128Float)bgra);
                            }
                            SolidColorBrush brush = this.latBrushCache[index];
                            for (int k = -num19 * 6; k <= (num19 * 6); k++)
                            {
                                num23 = -num17 + ((k * 3.1415926535897931) / ((double)(num19 * 6)));
                                double num33 = Math.Cos(num22);
                                double num34 = Math.Sin(num22);
                                double xe    = Math.Cos(num23) * Math.Cos(num22);
                                double ye    = Math.Sin(num23) * Math.Cos(num22);
                                double ze    = Math.Sin(num22);
                                double num35 = (this.mouseEntered && this.onSphere) ? 1.5 : 1.0;
                                this.Draw3DLine(dc, rx, -num12, scale, xs, ys, zs, xe, ye, ze, brush, num35);
                                xs = xe;
                                ys = ye;
                                zs = ze;
                            }
                        }
                        int num20 = 4;
                        for (int j = -num20; j < num20; j++)
                        {
                            double num37 = -num17 + ((j * 3.1415926535897931) / ((double)num20));
                            double num38 = -1.5707963267948966;
                            double num39 = Math.Cos(num37) * Math.Cos(num38);
                            double num40 = Math.Sin(num37) * Math.Cos(num38);
                            double num41 = Math.Sin(num38);
                            for (int m = -num20 * 4; m <= 0; m++)
                            {
                                num38 = (m * 3.1415926535897931) / ((double)(num20 * 8));
                                double num42 = Math.Cos(num37) * Math.Cos(num38);
                                double num43 = Math.Sin(num37) * Math.Cos(num38);
                                double num44 = Math.Sin(num38);
                                double num46 = (this.mouseEntered && this.onSphere) ? 2.0 : 1.0;
                                this.Draw3DLine(dc, rx, -num12, scale, num39, num40, num41, num42, num43, num44, lightBrush, num46);
                                num39 = num42;
                                num40 = num43;
                                num41 = num44;
                            }
                        }
                    }
                    dc.DrawCircle(center, scale, ringInlineBrush, thickness);
                }
            }
        }
コード例 #16
0
ファイル: TwistRenderer.cs プロジェクト: brezza92/PixelFarm
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int start, int len)
        {
            unsafe
            {
                double twist = _amount * _amount * Math.Sign(_amount);

                float hw = dst.Width / 2.0f;
                hw += (float)(hw * _offsetX);
                float hh = dst.Height / 2.0f;
                hh += (float)(hh * _offsetY);

                //*double maxrad = Math.Min(dst.Width / 2.0, dst.Height / 2.0);
                double invmaxrad = 1.0 / Math.Min(dst.Width / 2.0, dst.Height / 2.0);

                int     aaLevel   = _quality;
                int     aaSamples = aaLevel * aaLevel;
                PointF *aaPoints  = stackalloc PointF[aaSamples];
                PixelUtils.GetRgssOffsets(aaPoints, aaSamples, aaLevel);

                ColorBgra *samples = stackalloc ColorBgra[aaSamples];

                //TODO: review here
                for (int n = start; n < start + len; ++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);
                        ColorBgra *srcPtr = src.GetPointAddressUnchecked(rect.Left, y);

                        for (int x = rect.Left; x < rect.Right; x++)
                        {
                            float i = x - hw;

                            int sampleCount = 0;

                            for (int p = 0; p < aaSamples; ++p)
                            {
                                float u = i + aaPoints[p].X;
                                float v = j + aaPoints[p].Y;

                                double rad   = Math.Sqrt(u * u + v * v);
                                double theta = Math.Atan2(v, u);

                                double t = 1 - ((rad * _size) * invmaxrad);

                                t = (t < 0) ? 0 : (t * t * t);

                                theta += (t * twist) * INV100;

                                float sampleX = (hw + (float)(rad * Math.Cos(theta)));
                                float sampleY = (hh + (float)(rad * Math.Sin(theta)));

                                samples[sampleCount] = src.GetBilinearSampleClamped(sampleX, sampleY);
                                ++sampleCount;
                            }

                            *dstPtr = ColorBgra.Blend(samples, sampleCount);


                            ++dstPtr;
                            ++srcPtr;
                        }
                    }
                }
            }
        }
コード例 #17
0
        protected unsafe override void RenderLine(ISurface src, ISurface dst, Rectangle rect)
        {
            PointD start = new PointD(0, 0);
            double theta = ((double)(angle + 180) * 2 * Math.PI) / 360.0;
            double alpha = (double)distance;
            PointD end   = new PointD((float)alpha * Math.Cos(theta), (float)(-alpha * Math.Sin(theta)));

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

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

            PointD[] points = new PointD[((1 + distance) * 3) / 2];

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

            ColorBgra *samples = stackalloc ColorBgra[points.Length];

            int src_width  = src.Width;
            int src_height = src.Height;


            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)
                {
                    int sampleCount = 0;

                    for (int j = 0; j < points.Length; ++j)
                    {
                        PointD pt = new PointD(points[j].X + (float)x, points[j].Y + (float)y);

                        if (pt.X >= 0 && pt.Y >= 0 && pt.X <= (src_width - 1) && pt.Y <= (src_height - 1))
                        {
                            samples[sampleCount] = Utility.GetBilinearSampleClamped(src, (float)pt.X, (float)pt.Y);
                            ++sampleCount;
                        }
                    }

                    *dstPtr = ColorBgra.Blend(samples, sampleCount);
                    ++dstPtr;
                }
            }
        }
コード例 #18
0
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int start, int len)
        {
            unsafe
            {
                int   width  = dst.Width;
                int   height = dst.Height;
                float hw     = width / 2.0f;
                float hh     = height / 2.0f;

                int     aaSampleCount = this.quality * this.quality;
                PointF *aaPointsArray = stackalloc PointF[aaSampleCount];
                PixelUtils.GetRgssOffsets(aaPointsArray, aaSampleCount, this.quality);
                ColorBgra *samples = stackalloc ColorBgra[aaSampleCount];

                for (int n = start; n < start + len; ++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++)
                        {
                            float i = x - hw;

                            for (int p = 0; p < aaSampleCount; ++p)
                            {
                                PointF pt = aaPointsArray[p];

                                float u1 = i + pt.X;
                                float v1 = j - pt.Y;

                                float s1 = cos * u1 + sin * v1;
                                float t1 = -sin * u1 + cos * v1;

                                float s2 = s1 + this.intensity * (float)Math.Tan(s1 * this.scale);
                                float t2 = t1 + this.intensity * (float)Math.Tan(t1 * this.scale);

                                float u2 = cos * s2 - sin * t2;
                                float v2 = sin * s2 + cos * t2;

                                float xSample = hw + u2;
                                float ySample = hh + v2;

                                samples[p] = src.GetBilinearSampleWrapped(xSample, ySample);

                                /*
                                 * int xiSample = (int)xSample;
                                 * int yiSample = (int)ySample;
                                 *
                                 * xiSample = (xiSample + width) % width;
                                 * if (xiSample < 0) // This makes it a little faster
                                 * {
                                 *  xiSample = (xiSample + width) % width;
                                 * }
                                 *
                                 * yiSample = (yiSample + height) % height;
                                 * if (yiSample < 0) // This makes it a little faster
                                 * {
                                 *  yiSample = (yiSample + height) % height;
                                 * }
                                 *
                                 * samples[p] = *src.GetPointAddressUnchecked(xiSample, yiSample);
                                 */
                            }

                            *dstPtr = ColorBgra.Blend(samples, aaSampleCount);
                            ++dstPtr;
                        }
                    }
                }
            }
        }
コード例 #19
0
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int startIndex, int length)
        {
            ColorBgra colTransparent = ColorBgra.Transparent;

            unsafe
            {
                int     aaSampleCount = quality * quality;
                PointF *aaPoints      = stackalloc PointF[aaSampleCount];
                PixelUtils.GetRgssOffsets(aaPoints, aaSampleCount, quality);
                ColorBgra *samples = stackalloc ColorBgra[aaSampleCount];

                TransformData td;

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

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

                        double relativeY = y - this.yCenterOffset;

                        for (int x = rect.Left; x < rect.Right; x++)
                        {
                            double relativeX = x - this.xCenterOffset;

                            int sampleCount = 0;

                            for (int p = 0; p < aaSampleCount; ++p)
                            {
                                td.X = relativeX + aaPoints[p].X;
                                td.Y = relativeY - aaPoints[p].Y;

                                InverseTransform(ref td);

                                float sampleX = (float)(td.X + this.xCenterOffset);
                                float sampleY = (float)(td.Y + this.yCenterOffset);

                                ColorBgra sample = colPrimary;

                                if (IsOnSurface(src, sampleX, sampleY))
                                {
                                    sample = src.GetBilinearSample(sampleX, sampleY);
                                }
                                else
                                {
                                    switch (this.edgeBehavior)
                                    {
                                    case WarpEdgeBehavior.Clamp:
                                        sample = src.GetBilinearSampleClamped(sampleX, sampleY);
                                        break;

                                    case WarpEdgeBehavior.Wrap:
                                        sample = src.GetBilinearSampleWrapped(sampleX, sampleY);
                                        break;

                                    case WarpEdgeBehavior.Reflect:
                                        sample = src.GetBilinearSampleClamped(
                                            ReflectCoord(sampleX, src.Width),
                                            ReflectCoord(sampleY, src.Height));

                                        break;

                                    case WarpEdgeBehavior.Primary:
                                        sample = colPrimary;
                                        break;

                                    case WarpEdgeBehavior.Secondary:
                                        sample = colSecondary;
                                        break;

                                    case WarpEdgeBehavior.Transparent:
                                        sample = colTransparent;
                                        break;

                                    case WarpEdgeBehavior.Original:
                                        sample = src[x, y];
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                samples[sampleCount] = sample;
                                ++sampleCount;
                            }

                            *dstPtr = ColorBgra.Blend(samples, sampleCount);
                            ++dstPtr;
                        }
                    }
                }
            }
        }
コード例 #20
0
ファイル: ConfigDialog.cs プロジェクト: feeleen/pdn-smudge
        void brushcombobox_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            if (e.State == DrawItemState.Selected)
            {
                e.DrawFocusRectangle();
            }

            if (e.Index == brushcombobox.Items.Count - 1)
            {
                e.Graphics.DrawString(brushcombobox.Items[e.Index].ToString(), e.Font, new SolidBrush(ColorBgra.Blend(new ColorBgra[] { ColorBgra.FromColor(e.ForeColor), ColorBgra.FromColor(e.BackColor) }).ToColor()), e.Bounds.X, e.Bounds.Y + 8);
            }
            else
            {
                if (e.Index >= 0)
                {
                    if (droppingdown)
                    {
                        var image = brushcollection[e.Index].ThumbnailAlphaOnly.CreateAliasedBitmap();
                        e.Graphics.DrawImage(image, e.Bounds.X + (32 - image.Width) / 2, e.Bounds.Y + (32 - image.Height) / 2);
                        e.Graphics.DrawString(brushcollection[e.Index].Name, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X + 32, e.Bounds.Y);

                        e.Graphics.DrawString(brushcollection[e.Index].NativeSizePrettyString, e.Font, new SolidBrush(ColorBgra.Blend(new ColorBgra[] { ColorBgra.FromColor(e.ForeColor), ColorBgra.FromColor(e.BackColor) }).ToColor()), e.Bounds.X + 64, e.Bounds.Y + 16);
                    }
                    else
                    {
                        var image = brushcollection[e.Index].ThumbnailAlphaOnly.CreateAliasedBitmap();
                        e.Graphics.DrawImage(image, e.Bounds.X + (32 - image.Width) / 4, e.Bounds.Y + (32 - image.Height) / 4, image.Width / 2, image.Height / 2);
                        e.Graphics.DrawString(brushcollection[e.Index].Name, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X + 16, e.Bounds.Y);
                    }
                }
            }
        }