コード例 #1
0
            public override ColorBgra Apply(ColorBgra color)
            {
                //adjust saturation
                byte intensity = color.GetIntensityByte();

                color.R = PixelUtils.ClampToByte((intensity * 1024 + (color.R - intensity) * satFactor) >> 10);
                color.G = PixelUtils.ClampToByte((intensity * 1024 + (color.G - intensity) * satFactor) >> 10);
                color.B = PixelUtils.ClampToByte((intensity * 1024 + (color.B - intensity) * satFactor) >> 10);

                HsvColor hsvColor = HsvColor.FromColor(color.ToColor());
                int      hue      = hsvColor.Hue;

                hue += hueDelta;

                while (hue < 0)
                {
                    hue += 360;
                }

                while (hue > 360)
                {
                    hue -= 360;
                }

                hsvColor.Hue = hue;

                ColorBgra newColor = ColorBgra.FromColor(hsvColor.ToColor());

                newColor   = blendOp.Apply(newColor);
                newColor.A = color.A;

                return(newColor);
            }
コード例 #2
0
 /// <summary>
 /// Creates a new ColorBgra instance with the given color and alpha values.
 /// </summary>
 public static ColorBgra FromBgraClamped(float b, float g, float r, float a)
 {
     return(FromBgra(
                PixelUtils.ClampToByte(b),
                PixelUtils.ClampToByte(g),
                PixelUtils.ClampToByte(r),
                PixelUtils.ClampToByte(a)));
 }
コード例 #3
0
 /// <summary>
 /// Creates a new ColorBgra instance with the given color and alpha values.
 /// </summary>
 public static ColorBgra FromBgraClamped(int b, int g, int r, int a)
 {
     return(FromBgra(
                PixelUtils.ClampToByte(b),
                PixelUtils.ClampToByte(g),
                PixelUtils.ClampToByte(r),
                PixelUtils.ClampToByte(a)));
 }
コード例 #4
0
        /// <summary>
        /// Linearly interpolates between two color values.
        /// </summary>
        /// <param name="from">The color value that represents 0 on the lerp number line.</param>
        /// <param name="to">The color value that represents 1 on the lerp number line.</param>
        /// <param name="frac">A value in the range [0, 1].</param>
        /// <remarks>
        /// This method does a simple lerp on each color value and on the alpha channel. It does
        /// not properly take into account the alpha channel's effect on color blending.
        /// </remarks>
        public static ColorBgra Lerp(ColorBgra from, ColorBgra to, double frac)
        {
            ColorBgra ret = new ColorBgra();

            ret.B = (byte)PixelUtils.ClampToByte(PixelUtils.Lerp(from.B, to.B, frac));
            ret.G = (byte)PixelUtils.ClampToByte(PixelUtils.Lerp(from.G, to.G, frac));
            ret.R = (byte)PixelUtils.ClampToByte(PixelUtils.Lerp(from.R, to.R, frac));
            ret.A = (byte)PixelUtils.ClampToByte(PixelUtils.Lerp(from.A, to.A, frac));

            return(ret);
        }
コード例 #5
0
        public override void Render(Surface src, Surface dest, Rectangle[] rois, int startIndex, int length)
        {
            unsafe
            {
                int    w          = dest.Width;
                int    h          = dest.Height;
                double invH       = 1.0 / h;
                double invZoom    = 1.0 / _zoom;
                double invQuality = 1.0 / _quality;
                double aspect     = (double)h / (double)w;
                int    count      = _quality * _quality + 1;
                double invCount   = 1.0 / (double)count;

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

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

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

                            for (double i = 0; i < count; i++)
                            {
                                double u = (2.0 * x - w + (i * invCount)) * invH;
                                double v = (2.0 * y - h + ((i * invQuality) % 1)) * invH;

                                double radius  = Math.Sqrt((u * u) + (v * v));
                                double radiusP = radius;
                                double theta   = Math.Atan2(v, u);
                                double thetaP  = theta + _angleTheta;

                                double uP = radiusP * Math.Cos(thetaP);
                                double vP = radiusP * Math.Sin(thetaP);

                                double jX = (uP - vP * aspect) * invZoom;
                                double jY = (vP + uP * aspect) * invZoom;

                                double j = Julia(jX, jY, JR, JI);

                                double c = _factor * j;


                                b += PixelUtils.ClampToByte(c - 768);
                                g += PixelUtils.ClampToByte(c - 512);
                                r += PixelUtils.ClampToByte(c - 256);
                                a += PixelUtils.ClampToByte(c - 0);
                            }

                            *dstPtr = ColorBgra.FromBgra(
                                PixelUtils.ClampToByte(b / count),
                                PixelUtils.ClampToByte(g / count),
                                PixelUtils.ClampToByte(r / count),
                                PixelUtils.ClampToByte(a / count));

                            ++dstPtr;
                        }
                    }
                }
            }
        }
コード例 #6
0
        public void SetParameters(int brightness, int contrast)
        {
            this.brightness = brightness;
            this.contrast   = contrast;
            if (this.contrast < 0)
            {
                this.multiply = this.contrast + 100;
                this.divide   = 100;
            }
            else if (this.contrast > 0)
            {
                this.multiply = 100;
                this.divide   = 100 - this.contrast;
            }
            else
            {
                this.multiply = 1;
                this.divide   = 1;
            }

            if (this.rgbTable == null)
            {
                this.rgbTable = new byte[65536];
            }

            if (this.divide == 0)
            {
                for (int intensity = 0; intensity < 256; ++intensity)
                {
                    if (intensity + this.brightness < 128)
                    {
                        this.rgbTable[intensity] = 0;
                    }
                    else
                    {
                        this.rgbTable[intensity] = 255;
                    }
                }
            }
            else if (this.divide == 100)
            {
                for (int intensity = 0; intensity < 256; ++intensity)
                {
                    int shift = (intensity - 127) * this.multiply / this.divide + 127 - intensity + this.brightness;

                    for (int col = 0; col < 256; ++col)
                    {
                        int index = (intensity * 256) + col;
                        this.rgbTable[index] = PixelUtils.ClampToByte(col + shift);
                    }
                }
            }
            else
            {
                for (int intensity = 0; intensity < 256; ++intensity)
                {
                    int shift = (intensity - 127 + this.brightness) * this.multiply / this.divide + 127 - intensity;

                    for (int col = 0; col < 256; ++col)
                    {
                        int index = (intensity * 256) + col;
                        this.rgbTable[index] = PixelUtils.ClampToByte(col + shift);
                    }
                }
            }
        }
コード例 #7
0
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int startIndex, int length)
        {
            unsafe
            {
                // Glow backgound
                glowRenderer.Render(src, dst, rois, startIndex, length);

                // Create black outlines by finding the edges of objects

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

                    for (int y = roi.Top; y < roi.Bottom; ++y)
                    {
                        int top    = y - radius;
                        int bottom = y + radius + 1;

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

                        if (bottom > dst.Height)
                        {
                            bottom = dst.Height;
                        }

                        ColorBgra *srcPtr = src.GetPointAddress(roi.X, y);
                        ColorBgra *dstPtr = src.GetPointAddress(roi.X, y);

                        for (int x = roi.Left; x < roi.Right; ++x)
                        {
                            int left  = x - radius;
                            int right = x + radius + 1;

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

                            if (right > dst.Width)
                            {
                                right = dst.Width;
                            }

                            int r = 0;
                            int g = 0;
                            int b = 0;

                            for (int v = top; v < bottom; v++)
                            {
                                ColorBgra *pRow = src.GetRowAddress(v);
                                int        j    = v - y + radius;

                                for (int u = left; u < right; u++)
                                {
                                    int i1 = u - x + radius;
                                    int w  = conv[j][i1];

                                    ColorBgra *pRef = pRow + u;

                                    r += pRef->R * w;
                                    g += pRef->G * w;
                                    b += pRef->B * w;
                                }
                            }

                            ColorBgra topLayer = ColorBgra.FromBgr(
                                PixelUtils.ClampToByte(b),
                                PixelUtils.ClampToByte(g),
                                PixelUtils.ClampToByte(r));

                            // Desaturate
                            topLayer = this.desaturateOp.Apply(topLayer);

                            // Adjust Brightness and Contrast
                            if (topLayer.R > (this.inkOutline * 255 / 100))
                            {
                                topLayer = ColorBgra.FromBgra(255, 255, 255, topLayer.A);
                            }
                            else
                            {
                                topLayer = ColorBgra.FromBgra(0, 0, 0, topLayer.A);
                            }

                            // Change Blend Mode to Darken
                            ColorBgra myPixel = this.darkenOp.Apply(topLayer, *dstPtr);
                            *         dstPtr  = myPixel;

                            ++srcPtr;
                            ++dstPtr;
                        }
                    }
                }
            }
        }
コード例 #8
0
        public override void Render(Surface src, Surface dst, Rectangle[] rois, int startIndex, int length)
        {
            long w   = dst.Width;
            long h   = dst.Height;
            long fox = (long)(dst.Width * offsetX * 32768.0);
            long foy = (long)(dst.Height * offsetY * 32768.0);
            long fcx = fox + (w << 15);
            long fcy = foy + (h << 15);
            long fz  = this.amount;


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

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

                        for (int x = rect.Left; x < rect.Right; ++x)
                        {
                            long fx = (x << 16) - fcx;
                            long fy = (y << 16) - fcy;

                            int sr = 0;
                            int sg = 0;
                            int sb = 0;
                            int sa = 0;
                            int sc = 0;

                            sr += srcPtr->R * srcPtr->A;
                            sg += srcPtr->G * srcPtr->A;
                            sb += srcPtr->B * srcPtr->A;
                            sa += srcPtr->A;
                            ++sc;

                            for (int i = 0; i < n; ++i)
                            {
                                fx -= ((fx >> 4) * fz) >> 10;
                                fy -= ((fy >> 4) * fz) >> 10;

                                int u = (int)(fx + fcx + 32768 >> 16);
                                int v = (int)(fy + fcy + 32768 >> 16);

                                if (src.IsVisible(u, v))
                                {
                                    ColorBgra *srcPtr2 = src.GetPointAddressUnchecked(u, v);

                                    sr += srcPtr2->R * srcPtr2->A;
                                    sg += srcPtr2->G * srcPtr2->A;
                                    sb += srcPtr2->B * srcPtr2->A;
                                    sa += srcPtr2->A;
                                    ++sc;
                                }
                            }

                            if (sa != 0)
                            {
                                *dstPtr = ColorBgra.FromBgra(
                                    PixelUtils.ClampToByte(sb / sa),
                                    PixelUtils.ClampToByte(sg / sa),
                                    PixelUtils.ClampToByte(sr / sa),
                                    PixelUtils.ClampToByte(sa / sc));
                            }
                            else
                            {
                                dstPtr->Bgra = 0;
                            }

                            ++srcPtr;
                            ++dstPtr;
                        }
                    }
                }
            }
        }
        void SetParameters(int brightness, int contrast)
        {
            //---------------------------------------
            int multiply;
            int divide;

            this.brightness = brightness;
            this.contrast   = contrast;
            if (this.contrast < 0)
            {
                multiply = this.contrast + 100;
                divide   = 100;
            }
            else if (this.contrast > 0)
            {
                multiply = 100;
                divide   = 100 - this.contrast;
            }
            else
            {
                multiply = 1;
                divide   = 1;
            }

            if (this.rgbTable == null)
            {
                this.rgbTable = new byte[65536];//256*256
            }
            //-------------------------------------------------------
            //built table
            if (divide == 0)
            {
                unsafe
                {
                    fixed(byte *table_ptr = &this.rgbTable[0])
                    {
                        for (int intensity = 0; intensity < 256; ++intensity)
                        {
                            if (intensity + brightness < 128)
                            {
                                table_ptr[intensity] = 0;
                            }
                            else
                            {
                                table_ptr[intensity] = 255;
                            }
                        }
                    }
                }
            }
            else if (divide == 100)
            {
                unsafe
                {
                    fixed(byte *table_ptr = &this.rgbTable[0])
                    {
                        for (int intensity = 0; intensity < 256; ++intensity)
                        {
                            int shift = (intensity - 127) * multiply / divide + 127 - intensity + brightness;

                            for (int col = 0; col < 256; ++col)
                            {
                                int index = (intensity * 256) + col;
                                table_ptr[index] = PixelUtils.ClampToByte(col + shift);
                            }
                        }
                    }
                }
            }
            else
            {
                unsafe
                {
                    fixed(byte *table_ptr = &this.rgbTable[0])
                    {
                        for (int intensity = 0; intensity < 256; ++intensity)
                        {
                            int shift = (intensity - 127 + brightness) * multiply / divide + 127 - intensity;

                            for (int col = 0; col < 256; ++col)
                            {
                                int index = (intensity * 256) + col;
                                table_ptr[index] = PixelUtils.ClampToByte(col + shift);
                            }
                        }
                    }
                }
            }
            //-------------------------------------------------------
        }