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)PixelUtils.Clamp(
                            colorOutLow[i] + (colorOutHigh[i] - colorOutLow[i]) * Math.Pow(v / (colorInHigh[i] - colorInLow[i]), gamma[i]),
                            0.0f,
                            255.0f);
                    }
                }

                return(ret);
            }
Пример #2
0
        public Pixel Map(ISourceData data)
        {
            Pixel p = data.GetPixel(0, 0);
            int   r = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.R / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0);
            int   g = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.G / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0);
            int   b = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.B / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0);
            int   a = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.A / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0);

            return(new Pixel(r, g, b, a));
        }
            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] = PixelUtils.Clamp(val, 0.1f, 10.0f);
                UpdateLookupTable();
            }
Пример #4
0
            public override float BoundLerp(float t)
            {
                if (t > 1)
                {
                    t -= 2;
                }
                else if (t < -1)
                {
                    t += 2;
                }

                return(PixelUtils.Clamp(Math.Abs(t), 0, 1));
            }
            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)PixelUtils.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.FromColor(Color.Black), ColorBgra.FromColor(Color.White)));
            }
Пример #6
0
        public Pixel Map(ISourceData data)
        {
            double factor = _amount;

            Pixel[,] pixelMatrix = PixelUtils.GetPixelMatrix(data, 1);

            if (factor > 10)
            {
                factor = 10;
            }
            if (factor <= 0)
            {
                factor = 0.1d;
            }

            bias = 2.0;
            int red   = 0;
            int green = 0;
            int blue  = 0;

            int dimLength = pixelMatrix.GetLength(0);

            for (int x = 0; x < dimLength; x++)
            {
                for (int y = 0; y < dimLength; y++)
                {
                    red   += pixelMatrix[x, y].R * filterMatrix[x, y];
                    green += pixelMatrix[x, y].G * filterMatrix[x, y];
                    blue  += pixelMatrix[x, y].B * filterMatrix[x, y];
                }
            }

            int r = PixelUtils.Clamp((int)((factor * red) + bias), 255, 0);
            int g = PixelUtils.Clamp((int)((factor * green) + bias), 255, 0);
            int b = PixelUtils.Clamp((int)((factor * blue) + bias), 255, 0);

            return(new Pixel(r, g, b, pixelMatrix[1, 1].A));
        }
Пример #7
0
 public override float BoundLerp(float t)
 {
     return(PixelUtils.Clamp(t, 0, 1));
 }
Пример #8
0
 public override float BoundLerp(float t)
 {
     return(PixelUtils.Clamp(Math.Abs(t), 0, 1));
 }