Exemplo n.º 1
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();
            double        newIntensity  = _curve.GetValue(lightingValue.Intensity * 100.0) / 100.0;

            _intentValue = new StaticIntentState <LightingValue>(new LightingValue(lightingValue, newIntensity));
        }
Exemplo n.º 2
0
        private void _RenderCandleOnElement(Element element)
        {
            float startTime = 0;
            float endTime   = (float)TimeSpan.TotalMilliseconds;

            float currentLevel = _GenerateStartingLevel();

            while (startTime < endTime)
            {
                // What will our new value be?
                float currentLevelChange = _GenerateLevelChange();
                float nextLevel          = currentLevel + currentLevelChange;

                // Make sure we're still within our bounds.
                nextLevel = Math.Max(nextLevel, _data.MinLevel);
                nextLevel = Math.Min(nextLevel, _data.MaxLevel);

                // How long will this state last?
                float stateLength = _GenerateStateLength();

                // Make sure we don't exceed the end of the effect.
                stateLength = Math.Min(stateLength, endTime - startTime);

                // Add the intent.
                LightingValue startValue = new LightingValue(Color.White, currentLevel);
                LightingValue endValue   = new LightingValue(Color.White, nextLevel);
                IIntent       intent     = new LightingIntent(startValue, endValue, TimeSpan.FromMilliseconds(stateLength));
                _effectIntents.AddIntentForElement(element.Id, intent, TimeSpan.FromMilliseconds(startTime));

                startTime   += stateLength;
                currentLevel = nextLevel;
            }
        }
Exemplo n.º 3
0
        // renders the given node to the internal ElementData dictionary. If the given node is
        // not a element, will recursively descend until we render its elements.
        private void RenderNode(ElementNode node)
        {
            foreach (Element element in node)
            {
                // this is probably always going to be a single element for the given node, as
                // we have iterated down to leaf nodes in RenderNode() above. May as well do
                // it this way, though, in case something changes in future.
                if (element == null)
                {
                    continue;
                }

                double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
                Debug.Assert(allPointsTimeOrdered.Length > 1);

                double lastPosition = allPointsTimeOrdered[0];
                for (int i = 1; i < allPointsTimeOrdered.Length; i++)
                {
                    double position = allPointsTimeOrdered[i];

                    LightingValue startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition), (float)LevelCurve.GetValue(lastPosition * 100) / 100);
                    LightingValue endValue   = new LightingValue(ColorGradient.GetColorAt(position), (float)LevelCurve.GetValue(position * 100) / 100);

                    TimeSpan startTime = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * lastPosition);
                    TimeSpan timeSpan  = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));

                    IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

                    _elementData.AddIntentForElement(element.Id, intent, startTime);

                    lastPosition = position;
                }
            }
        }
Exemplo n.º 4
0
        public override void Handle(IIntent <LightingValue> obj)
        {
            LightingValue startValue = obj.GetStateAt(TimeSpan.Zero);
            // This is gross, but it's because when you get a value from an intent, the time
            // is used in an exclusive manner for reasons.  So this is trying to backup
            // the end time without affecting the the resulting value too much.
            LightingValue endValue = obj.GetStateAt(obj.TimeSpan - _oneTick);

            // Why we have to do this? I have no idea, but without it, the gradient rendering gives strange artefacts.
            // (If you want to see what I mean, make a long spin (minutes) across a bunch of elements in a group with
            // a simple pulse down (or up). The ends/starts of the effect flip to the color of the other end briefly,
            // for a single pixel width. I'm guessing it's an issue in the gradient rendering for large shapes where
            // the gradient rectangle is within the same integer range as the rendering rectangle.
            float      offset            = _rect.X * 0.004F;
            RectangleF gradientRectangle = new RectangleF(
                (_rect.X) - offset,
                _rect.Y,
                (_rect.Width) + (2 * offset),
                _rect.Height
                );

            //(float)Math.Floor(_rect.X) - (_rect.X / 300),   _rect.Y,   (float)Math.Ceiling(_rect.Width) + (_rect.Right / 300) + 1.0F,  _rect.Height

            using (LinearGradientBrush brush = new LinearGradientBrush(gradientRectangle, startValue.GetAlphaChannelIntensityAffectedColor(), endValue.GetAlphaChannelIntensityAffectedColor(), LinearGradientMode.Horizontal)) {
                _graphics.FillRectangle(brush, _rect);
            }
        }
Exemplo n.º 5
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();
            double        newValue      = _curve.GetValue(lightingValue.Intensity * 100.0) / 100.0;

            _intentValue = new StaticIntentState <LightingValue>(obj, new LightingValue(lightingValue.Color, (float)newValue));
        }
Exemplo n.º 6
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            if (_mixColors)
            {
                _intentValue = new StaticIntentState <LightingValue>(obj,
                                                                     new LightingValue(_breakdownItem.Color,
                                                                                       lightingValue.Intensity *
                                                                                       _getMaxProportion(lightingValue.HueSaturationOnlyColor)));
            }
            else
            {
                // if we're not mixing colors, we need to compare the input color against the filter color -- but only the
                // hue and saturation components; ignore the intensity.
                if (Math.Abs(lightingValue.Hue - _breakdownColorAsHSV.H) < Tolerance && Math.Abs(lightingValue.Saturation - _breakdownColorAsHSV.S) < Tolerance)
                {
                    _intentValue = new StaticIntentState <LightingValue>(obj, lightingValue);
                }
                else
                {
                    // TODO: return 'null', or some sort of empty intent state here instead. (null isn't handled well, and we don't have an 'empty' state class.)
                    _intentValue = new StaticIntentState <LightingValue>(obj, new LightingValue(_breakdownItem.Color, 0));
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Given one or more intent states, this will calculate a Color that is the combination of them all, in a 'max
        /// RGB component' fashion (ie. max of R, max of G, max of B).
        /// </summary>
        public static Color GetOpaqueRGBMaxColorForIntents(IIntentStates states)
        {
            byte R = 0;
            byte G = 0;
            byte B = 0;

            foreach (IIntentState intentState in states)
            {
                object value = intentState.GetValue();

                if (value is LightingValue)
                {
                    LightingValue lv = (LightingValue)value;
                    if (lv.Intensity > 0)
                    {
                        Color intentColor = lv.FullColor;
                        R = Math.Max(R, intentColor.R);
                        G = Math.Max(G, intentColor.G);
                        B = Math.Max(B, intentColor.B);
                    }
                }
                else if (value is RGBValue)
                {
                    RGBValue rv = (RGBValue)value;
                    R = Math.Max(R, rv.R);
                    G = Math.Max(G, rv.G);
                    B = Math.Max(B, rv.B);
                }
            }

            return(Color.FromArgb(R, G, B));
        }
Exemplo n.º 8
0
        public static IIntent CreateIntent(Color color, double intensity, TimeSpan duration)
        {
            LightingValue lightingValue = new LightingValue(color, intensity);
            IIntent       intent        = new LightingIntent(lightingValue, lightingValue, duration);

            return(intent);
        }
Exemplo n.º 9
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();
            int           alphaValue    = (int)(lightingValue.Intensity * byte.MaxValue);

            EvaluatorValue = new ColorCommand(Color.FromArgb(alphaValue, lightingValue.Color));
        }
Exemplo n.º 10
0
        protected override void _PreRender()
        {
            _effectIntents = new EffectIntents();

            Image image;

            try {
                image = Image.FromFile(_data.FilePath);
            }
            catch {
                return;
            }

            foreach (ElementNode targetNode in TargetNodes)
            {
                // Each element represents a single pixel in the grid display.
                // Therefore, the intent for the element will represent the state of that
                // pixel over the lifetime of the effect.

                // Get the grid dimensions from the node.
                VixenModules.Property.Grid.Module gridProperty =
                    (VixenModules.Property.Grid.Module)targetNode.Properties.Get(((Descriptor)Descriptor)._gridPropertyId);
                VixenModules.Property.Grid.Data gridData = (VixenModules.Property.Grid.Data)gridProperty.ModuleData;

                // For now, just scale it to the dimensions of the grid.
                Element[] elements    = targetNode.ToArray();
                byte[]    pixelBuffer = new byte[] { 0, 0, 0, byte.MaxValue };
                using (Bitmap bitmap = new Bitmap(gridData.Width, gridData.Height, image.PixelFormat)) {
                    using (Graphics g = Graphics.FromImage(bitmap)) {
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        g.DrawImage(image, 0, 0, bitmap.Width, bitmap.Height);

                        BitmapData bitmapData = bitmap.LockBits(Rectangle.FromLTRB(0, 0, bitmap.Width, bitmap.Height),
                                                                ImageLockMode.ReadOnly, image.PixelFormat);

                        byte[] rgbValues = new byte[Math.Abs(bitmapData.Stride) * bitmap.Height];
                        System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, rgbValues, 0, rgbValues.Length);

                        int bytesPerPixel = bitmapData.Stride / bitmapData.Width;
                        for (int y = 0, pixelIndex = 0; y < bitmapData.Height; y++)
                        {
                            int sourceDataIndex = y * bitmapData.Stride;
                            for (int x = 0; x < bitmapData.Width; x++, pixelIndex++, sourceDataIndex += bytesPerPixel)
                            {
                                Array.Copy(rgbValues, sourceDataIndex, pixelBuffer, 0, bytesPerPixel);
                                int           argbValue  = BitConverter.ToInt32(pixelBuffer, 0);
                                Color         pixelColor = Color.FromArgb(argbValue);
                                LightingValue startValue = new LightingValue(pixelColor, 1);
                                LightingValue endValue   = new LightingValue(pixelColor, 1);
                                IIntent       intent     = new LightingIntent(startValue, endValue, TimeSpan);
                                _effectIntents.AddIntentForElement(elements[pixelIndex].Id, intent, TimeSpan.Zero);
                            }
                        }

                        bitmap.UnlockBits(bitmapData);
                    }
                }
            }
        }
Exemplo n.º 11
0
        public static IIntent CreateIntent(Color startColor, Color endColor, double startIntensity, double endIntensity, TimeSpan duration)
        {
            var     startValue = new LightingValue(startColor, startIntensity);
            var     endValue   = new LightingValue(endColor, endIntensity);
            IIntent intent     = new LightingIntent(startValue, endValue, duration);

            return(intent);
        }
Exemplo n.º 12
0
 // renders the given node to the internal ElementData dictionary. If the given node is
 // not a element, will recursively descend until we render its elements.
 private void RenderNode(ElementNode node)
 {
     foreach (ElementNode elementNode in node.GetLeafEnumerator())
     {
         LightingValue lightingValue = new LightingValue(Color, (float)IntensityLevel);
         IIntent       intent        = new LightingIntent(lightingValue, lightingValue, TimeSpan);
         _elementData.AddIntentForElement(elementNode.Element.Id, intent, TimeSpan.Zero);
     }
 }
Exemplo n.º 13
0
        private void _RenderCandleOnElements(List <Element> elements)
        {
            TimeSpan startTime    = TimeSpan.Zero;
            double   currentLevel = _GenerateStartingLevel();

            while (startTime < TimeSpan)
            {
                // What will our new value be?
                double currentLevelChange = _GenerateLevelChange();
                double nextLevel          = currentLevel + currentLevelChange;

                // Make sure we're still within our bounds.
                nextLevel = Math.Max(nextLevel, _data.MinLevel);
                nextLevel = Math.Min(nextLevel, _data.MaxLevel);

                // How long will this state last?
                double stateLength = _GenerateStateLength();

                // Make sure we don't exceed the end of the effect.
                stateLength = Math.Min(stateLength, (TimeSpan - startTime).TotalMilliseconds);
                var length = TimeSpan.FromMilliseconds(stateLength);
                if (length == TimeSpan.Zero)
                {
                    length = TimeSpan.FromMilliseconds(1);
                }
                else
                {
                    // Add the intent.
                    LightingValue startValue = new LightingValue(Color, currentLevel);
                    LightingValue endValue   = new LightingValue(Color, nextLevel);

                    IIntent intent = new LightingIntent(startValue, endValue, length);
                    try
                    {
                        foreach (var element in elements)
                        {
                            if (element != null)
                            {
                                _effectIntents.AddIntentForElement(element.Id, intent, startTime);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logging.Error("Error generating Candle intents", e);
                        throw;
                    }
                }

                startTime   += length;
                currentLevel = nextLevel;
            }
        }
Exemplo n.º 14
0
        private void addIntentsToElement(Element element, Color?color = null)
        {
            if (element != null)
            {
                double[] allPointsTimeOrdered = _GetAllSignificantDataPoints().ToArray();
                Debug.Assert(allPointsTimeOrdered.Length > 1);

                double   lastPosition = allPointsTimeOrdered[0];
                TimeSpan lastEnd      = TimeSpan.Zero;
                for (var i = 1; i < allPointsTimeOrdered.Length; i++)
                {
                    double position = allPointsTimeOrdered[i];

                    LightingValue startValue;
                    LightingValue endValue;
                    if (color == null)
                    {
                        startValue = new LightingValue(ColorGradient.GetColorAt(lastPosition),
                                                       LevelCurve.GetValue(lastPosition * 100) / 100);
                        endValue = new LightingValue(ColorGradient.GetColorAt(position), LevelCurve.GetValue(position * 100) / 100);
                    }
                    else
                    {
                        startValue = new LightingValue((Color)color,
                                                       (ColorGradient.GetProportionOfColorAt(lastPosition, (Color)color) *
                                                        LevelCurve.GetValue(lastPosition * 100) / 100));
                        endValue = new LightingValue((Color)color,
                                                     (ColorGradient.GetProportionOfColorAt(position, (Color)color) *
                                                      LevelCurve.GetValue(position * 100) / 100));
                    }

                    TimeSpan startTime = lastEnd;
                    TimeSpan timeSpan  = TimeSpan.FromMilliseconds(TimeSpan.TotalMilliseconds * (position - lastPosition));
                    if (startValue.Intensity.Equals(0f) && endValue.Intensity.Equals(0f))
                    {
                        lastPosition = position;
                        lastEnd      = startTime + timeSpan;
                        continue;
                    }

                    IIntent intent = new LightingIntent(startValue, endValue, timeSpan);

                    _elementData.AddIntentForElement(element.Id, intent, startTime);

                    lastPosition = position;
                    lastEnd      = startTime + timeSpan;
                }
            }
        }
Exemplo n.º 15
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            if (lightingValue.Intensity > 0)
            {
                double newIntensity = _curve.GetValue(lightingValue.Intensity * 100.0) / 100.0;
                _lvState.SetValue(new LightingValue(lightingValue, newIntensity));
                _intentValue = _lvState;
            }
            else
            {
                _intentValue = null;
            }
        }
Exemplo n.º 16
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            // if we're not mixing colors, we need to compare the input color against the filter color -- but only the
            // hue and saturation components; ignore the intensity.
            if (Math.Abs(lightingValue.Color.R - _breakdownItem.Color.R) < Tolerance &&
                Math.Abs(lightingValue.Color.G - _breakdownItem.Color.G) < Tolerance &&
                Math.Abs(lightingValue.Color.B - _breakdownItem.Color.B) < Tolerance)
            {
                _intensityValue = lightingValue.Intensity;
            }
            else
            {
                _intensityValue = 0;
            }
        }
Exemplo n.º 17
0
        public static StaticArrayIntent <RGBValue> CreateStaticArrayIntent(LightingValue startValue, LightingValue endValue, TimeSpan duration)
        {
            var interval  = VixenSystem.DefaultUpdateTimeSpan;
            var intervals = (int)(duration.TotalMilliseconds / interval.TotalMilliseconds);

            RGBValue[] values       = new RGBValue[intervals + 1];
            var        interpolator = Interpolator.Interpolator.Create <LightingValue>();

            for (int i = 0; i < intervals + 1; i++)
            {
                LightingValue sample;
                double        percent = interval.TotalMilliseconds * i / duration.TotalMilliseconds;
                interpolator.Interpolate(percent, startValue, endValue, out sample);
                values[i] = new RGBValue(sample.FullColor);
            }

            return(new StaticArrayIntent <RGBValue>(interval, values, duration));
        }
Exemplo n.º 18
0
 // renders the given node to the internal ElementData dictionary. If the given node is
 // not a element, will recursively descend until we render its elements.
 private void RenderNode(ElementNode node)
 {
     foreach (Element element in node)
     {
         LightingValue lightingValue = new LightingValue(Color, (float)IntensityLevel);
         IIntent       intent        = new LightingIntent(lightingValue, lightingValue, TimeSpan);
         _elementData.AddIntentForElement(element.Id, intent, TimeSpan.Zero);
     }
     //// if this node is an RGB node, then it will know what to do with it (might render directly,
     //// might be broken down into sub-elements, etc.) So just pass it off to that instead.
     //if (node.Properties.Contains(SetLevelDescriptor._RGBPropertyId)) {
     //    RenderRGB(node);
     //} else {
     //    if (node.IsLeaf) {
     //        RenderMonochrome(node);
     //    } else {
     //        foreach (ElementNode child in node.Children)
     //            RenderNode(child);
     //    }
     //}
 }
Exemplo n.º 19
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            if (_mixColors)
            {
                _intensityValue = lightingValue.Intensity * _getMaxProportion(lightingValue.Color);
            }
            else
            {
                // if we're not mixing colors, we need to compare the input color against the filter color -- but only the
                // hue and saturation components; ignore the intensity.
                if (Math.Abs(lightingValue.Hue - _breakdownColorAsHSV.H) < Tolerance && Math.Abs(lightingValue.Saturation - _breakdownColorAsHSV.S) < Tolerance)
                {
                    _intensityValue = lightingValue.Intensity;
                }
                else
                {
                    _intensityValue = 0;
                }
            }
        }
Exemplo n.º 20
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            EvaluatorValue = new ColorCommand(lightingValue.FullColor);
        }
Exemplo n.º 21
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            _intensityValue = lightingValue.Intensity * GetMaxProportionFunc(lightingValue.Color);
        }
Exemplo n.º 22
0
 public LightingValue Reduce(LightingValue value, double reductionPercent)
 {
     return(new LightingValue(value.Color, Reduce(value.Intensity, reductionPercent)));
 }
Exemplo n.º 23
0
        public override void Handle(IIntentState <LightingValue> obj)
        {
            LightingValue lightingValue = obj.GetValue();

            _intentValue = new StaticIntentState <LightingValue>(obj, new LightingValue(_breakdownItem.Color, lightingValue.Intensity * _getMaxProportion(lightingValue.Color)));
        }