Beispiel #1
0
        public ColorF Transform(ColorTransformerContext context, ColorF color)
        {
            var r = (float)Math.Pow(color.R, _gammaR);
            var g = (float)Math.Pow(color.G, _gammaG);
            var b = (float)Math.Pow(color.B, _gammaB);

            return(ColorF.FromRgb(r, g, b));
        }
Beispiel #2
0
        public ColorF Transform(ColorTransformerContext context, ColorF color)
        {
            float brightness = color.GetBrightness();

            if (brightness > (1f - _threshold))
            {
                return(ColorF.FromRgb(1f, 1f, 1f));
            }

            if (brightness < _threshold)
            {
                return(ColorF.FromRgb(0f, 0f, 0f));
            }

            return(color);
        }
Beispiel #3
0
        public ColorF Transform(ColorTransformerContext context, ColorF color)
        {
            ColorF lastColor = context.PreviousOutputColor;

            float diffR = color.R - lastColor.R;
            float r     = lastColor.R;

            if (diffR > _hysteresis)
            {
                r += diffR - _hysteresis;
            }

            if (diffR < -_hysteresis)
            {
                r += diffR + _hysteresis;
            }


            float diffG = color.G - lastColor.G;
            float g     = lastColor.G;

            if (diffG > _hysteresis)
            {
                g += diffG - _hysteresis;
            }

            if (diffG < -_hysteresis)
            {
                g += diffG + _hysteresis;
            }


            float diffB = color.B - lastColor.B;
            float b     = lastColor.B;

            if (diffB > _hysteresis)
            {
                b += diffB - _hysteresis;
            }

            if (diffB < -_hysteresis)
            {
                b += diffB + _hysteresis;
            }

            return(ColorF.FromRgb(r, g, b));
        }
        private IColorTransformer GetTransformer(ColorTransformerContext context)
        {
            IColorTransformer toReturn;

            lock (_transformers)
            {
                if (!_transformers.TryGetValue(context, out toReturn))
                {
                    ConstructorInfo ctor = context.Type.GetConstructor(new[] { typeof(IDictionary <string, object>) });

                    if (ctor == null)
                    {
                        throw new InvalidOperationException(string.Format("Color Transformer {0} is missing constructor with config", context.Type.Name));
                    }

                    _transformers[context] = toReturn = (IColorTransformer)ctor.Invoke(new object[] { context.TransformerConfig });
                }
            }
            return(toReturn);
        }
Beispiel #5
0
 public ColorF Transform(ColorTransformerContext context, ColorF color)
 {
     return(ColorF.FromRgb(color.R * _factorR, color.G * _factorG, color.B * _factorB));
 }