コード例 #1
0
        static unsafe ColorBgra GetPercentileOfColor(ColorBgra color, int area, int *hb, int *hg, int *hr, int *ha)
        {
            int rc = 0;
            int gc = 0;
            int bc = 0;

            for (int i = 0; i < color.R; ++i)
            {
                rc += hr[i];
            }

            for (int i = 0; i < color.G; ++i)
            {
                gc += hg[i];
            }

            for (int i = 0; i < color.B; ++i)
            {
                bc += hb[i];
            }

            rc = (rc * 255) / area;
            gc = (gc * 255) / area;
            bc = (bc * 255) / area;

            return(ColorBgra.FromBgr((byte)bc, (byte)gc, (byte)rc));
        }
コード例 #2
0
        public override ColorBgra Apply(ColorBgra color)
        {
            // Adjust saturation
            var intensity = color.GetIntensityByte();

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

            var hsvColor = (new RgbColor(color.R, color.G, color.B)).ToHsv();
            int hue      = hsvColor.Hue;

            hue += hue_delta;

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

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

            hsvColor.Hue = hue;

            var rgbColor = hsvColor.ToRgb();
            var newColor = ColorBgra.FromBgr((byte)rgbColor.Blue, (byte)rgbColor.Green, (byte)rgbColor.Red);

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

            return(newColor);
        }
コード例 #3
0
 public ColorBgra ToColorBgra()
 {
     return(ColorBgra.FromBgr(
                this.Red.ConvertToByte(),
                this.Green.ConvertToByte(),
                this.Blue.ConvertToByte()));
 }
コード例 #4
0
        /// <summary>
        /// Returns the color after scaling the sums. Alpha is ignored.
        /// </summary>
        /// <returns></returns>
        public static ColorBgra FromBgrSumScaled(float sumB, float sumG, float sumR, float scale)
        {
            byte red   = Utility.ClampToByte(Math.Round(sumR * scale));
            byte green = Utility.ClampToByte(Math.Round(sumG * scale));
            byte blue  = Utility.ClampToByte(Math.Round(sumB * scale));

            return(ColorBgra.FromBgr(blue, green, red));
        }
コード例 #5
0
ファイル: ColorMaskEffect.cs プロジェクト: cyberjaxx/OpenPDN
            public override ColorBgra Apply(ColorBgra color)
            {
                byte value = (byte)(HslDifference(color, FilterColor) * 255 / 240);

                if (Grayscale)
                {
                    if (!Invert)
                    {
                        value = (byte)(255 - value);
                    }
                    return(ColorBgra.FromBgr(value, value, value));
                }
                return(value < Tolerance ? TransparentColor : OpaqueColor);
            }
コード例 #6
0
ファイル: ColorMaskEffect.cs プロジェクト: cyberjaxx/OpenPDN
            public override ColorBgra Apply(ColorBgra color)
            {
                byte value = (byte)(Math.Abs(color.GetBrightness() - FilterColor.GetBrightness()) * 255);

                if (Grayscale)
                {
                    if (!Invert)
                    {
                        value = (byte)(255 - value);
                    }
                    return(ColorBgra.FromBgr(value, value, value));
                }
                return(value < Tolerance ? TransparentColor : OpaqueColor);
            }
コード例 #7
0
ファイル: ColorMaskEffect.cs プロジェクト: cyberjaxx/OpenPDN
            public override ColorBgra Apply(ColorBgra color)
            {
                byte value = color.MaxDeviance(FilterColor);

                if (Grayscale)
                {
                    if (!Invert)
                    {
                        value = (byte)(255 - value);
                    }
                    return(ColorBgra.FromBgr(value, value, value));
                }
                return(value < Tolerance ? TransparentColor : OpaqueColor);
            }
コード例 #8
0
 protected override void OnPropertyValueChanged()
 {
     this.inOnPropertyValueChanged++;
     try
     {
         int num   = base.Property.Value;
         int red   = (num >> 0x10) & 0xff;
         int green = (num >> 8) & 0xff;
         int blue  = num & 0xff;
         this.SetPropertyValueFromRgb(red, green, blue);
         this.colorRectangle.RectangleColor = ColorBgra.FromBgr((byte)blue, (byte)green, (byte)red).ToColor();
     }
     finally
     {
         this.inOnPropertyValueChanged--;
     }
 }
コード例 #9
0
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();

            Surface selectionSurface = new Surface(selection.Width, selection.Height);

            selectionSurface.CopySurface(srcArgs.Surface, selection);

            Surface stretchedSurface = new Surface(selection.Width * 2, selection.Height);

            stretchedSurface.FitSurface(ResamplingAlgorithm.Bicubic, selectionSurface);

            processedSurface = new Surface(srcArgs.Surface.Size);

            ColorBgra t;

            for (int y = 0; y < stretchedSurface.Height; y++)
            {
                if (IsCancelRequested)
                {
                    return;
                }
                int v = selection.Left;
                for (int x = 0; x < stretchedSurface.Width; x += 2)
                {
                    if (x % 2 == 0)
                    {
                        t.R = stretchedSurface[x, y].R;
                        t.G = stretchedSurface[x + 1, y].G;
                        if (x != stretchedSurface.Width - 2)
                        {
                            t.B = stretchedSurface[x + 2, y].B;
                        }
                        else
                        {
                            t.B = (byte)((stretchedSurface[stretchedSurface.Width - 1, y].B + stretchedSurface[stretchedSurface.Width - 2, y].B) >> 1);
                        }
                        processedSurface[v, y + selection.Top] = ColorBgra.FromBgr(t.B, t.G, t.R);
                        v++;
                    }
                }
            }


            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
コード例 #10
0
            public Bitmap Bitmap()
            {
                Bitmap returnBitmap = new Bitmap(x, y);

                for (int j = 0; j < y; j++)
                {
                    for (int i = 0; i < x; i++)
                    {
                        float r, g, b;

                        r = data[((y - j - 1) * x + i) * 3 + 2] * 255.0f;
                        g = data[((y - j - 1) * x + i) * 3 + 1] * 255.0f;
                        b = data[((y - j - 1) * x + i) * 3 + 0] * 255.0f;

                        returnBitmap.SetPixel(i, j, ColorBgra.FromBgr((byte)b, (byte)g, (byte)r));
                    }
                }

                return(returnBitmap);
            }
コード例 #11
0
        private int inOnPropertyValueChanged = 0; // this field is necessary to avoid having Effect`1.OnSetRenderInfo() called 3-4+ times at effect startup
        protected override void OnPropertyValueChanged()
        {
            ++this.inOnPropertyValueChanged;

            try
            {
                int value = Property.Value;
                int red   = (value >> 16) & 0xff;
                int green = (value >> 8) & 0xff;
                int blue  = value & 0xff;
                SetPropertyValueFromRgb(red, green, blue);

                ColorBgra color = ColorBgra.FromBgr((byte)blue, (byte)green, (byte)red);
                this.colorRectangle.RectangleColor = color.ToColor();
            }

            finally
            {
                --this.inOnPropertyValueChanged;
            }
        }
コード例 #12
0
ファイル: ColorControl.cs プロジェクト: feeleen/pdn-gridwarp
        private void SetSliderGradients()
        {
            HsvColor  h = wheel.HsvColor;
            ColorBgra c = wheel.Color;

            rslider.Gradient = new ColorBgra[] { ColorBgra.FromBgr(c.B, c.G, 0), ColorBgra.FromBgr(c.B, c.G, 255) };
            gslider.Gradient = new ColorBgra[] { ColorBgra.FromBgr(c.B, 0, c.R), ColorBgra.FromBgr(c.B, 255, c.R) };
            bslider.Gradient = new ColorBgra[] { ColorBgra.FromBgr(0, c.G, c.R), ColorBgra.FromBgr(255, c.G, c.R) };
            aslider.Gradient = new ColorBgra[] { ColorBgra.FromBgra(c.B, c.G, c.R, 0), ColorBgra.FromBgra(c.B, c.G, c.R, 255) };

            sslider.Gradient = new ColorBgra[] { new HsvColor(h.Hue, 0, h.Value).ToColorBgra(), new HsvColor(h.Hue, 100, h.Value).ToColorBgra() };
            vslider.Gradient = new ColorBgra[] { new HsvColor(h.Hue, h.Saturation, 0).ToColorBgra(), new HsvColor(h.Hue, h.Saturation, 100).ToColorBgra() };

            if (hslider.Gradient == null)
            {
                ColorBgra[] hues = new ColorBgra[361];
                for (int hue = 0; hue <= 360; ++hue)
                {
                    hues[hue] = new HsvColor(hue, 100, 100).ToColorBgra();
                }
                hslider.Gradient = hues;
            }
        }
コード例 #13
0
        public static Func <double, ColorBgra> GetGetColorFunc(this ValueSources valueSource)
        {
            if (valueSource == ValueSources.Red)
            {
                return((red) => { return ColorBgra.FromBgr(0, 0, (byte)Math.Round(255 * red)); });
            }

            if (valueSource == ValueSources.Green)
            {
                return((green) => { return ColorBgra.FromBgr(0, (byte)Math.Round(255 * green), 0); });
            }

            if (valueSource == ValueSources.Blue)
            {
                return((blue) => { return ColorBgra.FromBgr((byte)Math.Round(255 * blue), 0, 0); });
            }

            //if (valueSource == ValueSources.Intensity)
            return((intensity) =>
            {
                byte i = (byte)Math.Round(255 * intensity);
                return ColorBgra.FromBgr(i, i, i);
            });
        }
コード例 #14
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;
                        }
                    }
                }
            }
        }
コード例 #15
0
ファイル: InkSketchEffect.cs プロジェクト: p07r0457/Pinta
        public unsafe override void Render(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
        {
            // Glow backgound
            glowEffect.Data.Radius     = 6;
            glowEffect.Data.Brightness = -(Data.Coloring - 50) * 2;
            glowEffect.Data.Contrast   = -(Data.Coloring - 50) * 2;

            this.glowEffect.Render(src, dest, rois);

            // Create black outlines by finding the edges of objects
            foreach (Gdk.Rectangle roi in rois)
            {
                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 > dest.Height)
                    {
                        bottom = dest.Height;
                    }

                    ColorBgra *srcPtr = src.GetPointAddress(roi.X, y);
                    ColorBgra *dstPtr = dest.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 > dest.Width)
                        {
                            right = dest.Width;
                        }

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

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

                        for (int v = top; v < bottom; v++)
                        {
                            ColorBgra *pRow = src.GetRowAddressUnchecked(src_dataptr, src_width, 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(
                            Utility.ClampToByte(b),
                            Utility.ClampToByte(g),
                            Utility.ClampToByte(r));

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

                        // Adjust Brightness and Contrast
                        if (topLayer.R > (Data.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;
                    }
                }
            }
        }
コード例 #16
0
        public static ColorBgra ToColorBgra(this HsvColor color)
        {
            // HsvColor contains values scaled as in the color wheel:

            double h;
            double s;
            double v;

            double r = 0;
            double g = 0;
            double b = 0;

            // Scale Hue to be between 0 and 360. Saturation
            // and value scale to be between 0 and 1.
            h = (double)color.Hue % 360;
            s = (double)color.Saturation / 100;
            v = (double)color.Value / 100;

            if (s == 0)
            {
                // If s is 0, all colors are the same.
                // This is some flavor of gray.
                r = v;
                g = v;
                b = v;
            }
            else
            {
                double p;
                double q;
                double t;

                double fractionalSector;
                int    sectorNumber;
                double sectorPos;

                // The color wheel consists of 6 sectors.
                // Figure out which sector you're in.
                sectorPos    = h / 60;
                sectorNumber = (int)(Math.Floor(sectorPos));

                // get the fractional part of the sector.
                // That is, how many degrees into the sector
                // are you?
                fractionalSector = sectorPos - sectorNumber;

                // Calculate values for the three axes
                // of the color.
                p = v * (1 - s);
                q = v * (1 - (s * fractionalSector));
                t = v * (1 - (s * (1 - fractionalSector)));

                // Assign the fractional colors to r, g, and b
                // based on the sector the angle is in.
                switch (sectorNumber)
                {
                case 0:
                    r = v;
                    g = t;
                    b = p;
                    break;

                case 1:
                    r = q;
                    g = v;
                    b = p;
                    break;

                case 2:
                    r = p;
                    g = v;
                    b = t;
                    break;

                case 3:
                    r = p;
                    g = q;
                    b = v;
                    break;

                case 4:
                    r = t;
                    g = p;
                    b = v;
                    break;

                case 5:
                    r = v;
                    g = p;
                    b = q;
                    break;
                }
            }

            // return an RgbColor structure, with values scaled
            // to be between 0 and 255.
            return(ColorBgra.FromBgr((byte)(b * 255), (byte)(g * 255), (byte)(r * 255)));
        }
コード例 #17
0
        protected unsafe override void RenderLine(ISurface src, ISurface dest, Rectangle roi)
        {
            // Glow backgound
            glow_effect.Render(src, dest, roi);

            // Create black outlines by finding the edges of objects
            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 > dest.Height)
                {
                    bottom = dest.Height;
                }

                ColorBgra *srcPtr = src.GetPointAddress(roi.X, y);
                ColorBgra *dstPtr = dest.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 > dest.Width)
                    {
                        right = dest.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(
                        Utility.ClampToByte(b),
                        Utility.ClampToByte(g),
                        Utility.ClampToByte(r));

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

                    // Adjust Brightness and Contrast
                    if (topLayer.R > (ink_outline * 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.darken_op.Apply(topLayer, *dstPtr);
                    *         dstPtr  = myPixel;

                    ++srcPtr;
                    ++dstPtr;
                }
            }
        }
コード例 #18
0
ファイル: CanvasPanel.cs プロジェクト: feeleen/pdn-smudge
        private void ShowContextMenu(Control sender, Point location, bool colorsOnly)
        {
            contextMenu.Items.Clear();
            using (Surface sfc = new Surface(16, 16))
            {
                contextMenu.Items.Add(new ToolStripLabel("Background"));
                contextMenu.Items.Add(new ToolStripSeparator());

                sfc.ClearWithCheckerboardPattern();
                if (!colorsOnly)
                {
                    contextMenu.Items.Add("Transparent", new Bitmap(sfc.CreateAliasedBitmap()), (s, e) =>
                    {
                        sender.BackgroundImage = null;
                        sender.BackColor       = Color.Transparent;
                    });
                }

                sfc.Clear(ColorBgra.Black);
                contextMenu.Items.Add("Black", new Bitmap(sfc.CreateAliasedBitmap()), (s, e) =>
                {
                    sender.BackgroundImage = null;
                    sender.BackColor       = Color.Black;
                });

                sfc.Clear(ColorBgra.White);
                contextMenu.Items.Add("White", new Bitmap(sfc.CreateAliasedBitmap()), (s, e) =>
                {
                    sender.BackgroundImage = null;
                    sender.BackColor       = Color.White;
                });

                sfc.Clear(ColorBgra.FromBgr(127, 127, 127));
                contextMenu.Items.Add("Gray", new Bitmap(sfc.CreateAliasedBitmap()), (s, e) =>
                {
                    sender.BackgroundImage = null;
                    sender.BackColor       = Color.Gray;
                });

                contextMenu.Items.Add("Other color...", new Bitmap(typeof(Smudge), "images.colorwheel.png"), (s, e) =>
                {
                    ColorBgra c;
                    if (DialogResult.OK == ShowColorPicker(sender, location, !colorsOnly, out c))
                    {
                        sender.BackColor       = c.ToColor();
                        sender.BackgroundImage = null;
                    }
                });

                if (!colorsOnly)
                {
                    contextMenu.Items.Add("From clipboard", null, (s, e) =>
                    {
                        try
                        {
                            sender.BackgroundImage = Clipboard.GetImage();
                            sender.BackColor       = Color.Transparent;
                        }
                        catch { }
                    });
                    if (Clipboard.ContainsImage())
                    {
                        using (Surface fromcb = Surface.CopyFromBitmap((Bitmap)Clipboard.GetImage()))
                        {
                            sfc.FitSurface(ResamplingAlgorithm.SuperSampling, fromcb);
                            contextMenu.Items[7].Image = new Bitmap(sfc.CreateAliasedBitmap());
                        }
                    }
                    else
                    {
                        contextMenu.Items[7].Enabled = false;
                    }
                }
            }
            contextMenu.Show(sender, location);
        }
コード例 #19
0
 /// <summary>
 /// Returns a Point3D object where X = R, Y = G, & Z = B. Alpha is ignored.
 /// </summary>
 /// <returns></returns>
 public static ColorBgra FromPoint3D(Point3D point)
 {
     return(ColorBgra.FromBgr(Utility.ClampToByte(point.Z),
                              Utility.ClampToByte(point.Y), Utility.ClampToByte(point.X)));
 }
コード例 #20
0
 public override ColorBgra GetPercentileColor(float fraction)
 {
     int[] perc = GetPercentile(fraction);
     return(ColorBgra.FromBgr((byte)(perc[0]), (byte)(perc[0]), (byte)(perc[0])));
 }
コード例 #21
0
 public override ColorBgra GetMeanColor()
 {
     float[] mean = GetMean();
     return(ColorBgra.FromBgr((byte)(mean[0] + 0.5f), (byte)(mean[0] + 0.5f), (byte)(mean[0] + 0.5f)));
 }