Clamp() public static method

public static Clamp ( double x, double min, double max ) : double
x double
min double
max double
return double
Ejemplo n.º 1
0
        public void ScrollCanvas(int dx, int dy)
        {
            Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;

            view.Hadjustment.Value = Utility.Clamp(dx + view.Hadjustment.Value, view.Hadjustment.Lower, view.Hadjustment.Upper - view.Hadjustment.PageSize);
            view.Vadjustment.Value = Utility.Clamp(dy + view.Vadjustment.Value, view.Vadjustment.Lower, view.Vadjustment.Upper - view.Vadjustment.PageSize);
        }
Ejemplo n.º 2
0
            public ColorBgra Apply(float r, float g, float b)
            {
                ColorBgra ret = new ColorBgra();

                float[] input = new float[] { b, g, r };

                for (int i = 0; i < 3; i++)
                {
                    float v = (input[i] - colorInLow[i]);

                    if (v < 0)
                    {
                        ret[i] = colorOutLow[i];
                    }
                    else if (v + colorInLow[i] >= colorInHigh[i])
                    {
                        ret[i] = colorOutHigh[i];
                    }
                    else
                    {
                        ret[i] = (byte)Utility.Clamp(
                            colorOutLow[i] + (colorOutHigh[i] - colorOutLow[i]) * Math.Pow(v / (colorInHigh[i] - colorInLow[i]), gamma[i]),
                            0.0f,
                            255.0f);
                    }
                }

                return(ret);
            }
Ejemplo n.º 3
0
        public void RecenterView(double x, double y)
        {
            Gtk.Viewport view = (Gtk.Viewport)PintaCore.Chrome.Canvas.Parent;

            view.Hadjustment.Value = Utility.Clamp(x * Scale - view.Hadjustment.PageSize / 2, view.Hadjustment.Lower, view.Hadjustment.Upper);
            view.Vadjustment.Value = Utility.Clamp(y * Scale - view.Vadjustment.PageSize / 2, view.Vadjustment.Lower, view.Vadjustment.Upper);
        }
Ejemplo n.º 4
0
        public Gdk.Rectangle ClampToImageSize(Gdk.Rectangle r)
        {
            int x      = Utility.Clamp(r.X, 0, ImageSize.Width);
            int y      = Utility.Clamp(r.Y, 0, ImageSize.Height);
            int width  = Math.Min(r.Width, ImageSize.Width - x);
            int height = Math.Min(r.Height, ImageSize.Height - y);

            return(new Gdk.Rectangle(x, y, width, height));
        }
Ejemplo n.º 5
0
            public void SetGamma(int index, float val)
            {
                if (index < 0 || index >= 3)
                {
                    throw new ArgumentOutOfRangeException("index", index, "Index must be between 0 and 2");
                }

                gamma[index] = Utility.Clamp(val, 0.1f, 10.0f);
                UpdateLookupTable();
            }
Ejemplo n.º 6
0
            public double BoundLerp(double t)
            {
                if (t > 1)
                {
                    t -= 2;
                }
                else if (t < -1)
                {
                    t += 2;
                }

                return(Utility.Clamp(Math.Abs(t), 0, 1));
            }
Ejemplo n.º 7
0
            public static Level AutoFromLoMdHi(ColorBgra lo, ColorBgra md, ColorBgra hi)
            {
                float[] gamma = new float[3];

                for (int i = 0; i < 3; i++)
                {
                    if (lo[i] < md[i] && md[i] < hi[i])
                    {
                        gamma[i] = (float)Utility.Clamp(Math.Log(0.5, (float)(md[i] - lo[i]) / (float)(hi[i] - lo[i])), 0.1, 10.0);
                    }
                    else
                    {
                        gamma[i] = 1.0f;
                    }
                }

                return(new Level(lo, hi, gamma, ColorBgra.Black, ColorBgra.White));
            }
Ejemplo n.º 8
0
 private static byte BoundLerp(double t)
 {
     return((byte)(Utility.Clamp(Math.Abs(t), 0, 1) * 255f));
 }
Ejemplo n.º 9
0
 private byte BoundLerp(double t)
 {
     return((byte)(Utility.Clamp(t, 0, 1) * 255f));
 }