Esempio n. 1
0
 public LightingValue(LightingValue lv, double i)
 {
     _hue = lv._hue;
     _saturation = lv._saturation;
     _value = lv._value;
     _intensity = i;
 }
Esempio n. 2
0
 protected override LightingValue FilterLightingValue(LightingValue lightingValue)
 {
     int white = _GetWhiteValue(lightingValue.Color);
     white = (int)(white * lightingValue.Intensity);
     lightingValue.Color = _CreateWhiteColor(white);
     return lightingValue;
 }
Esempio n. 3
0
 protected override LightingValue FilterLightingValue(LightingValue lightingValue)
 {
     int red = _GetRedValue(lightingValue.Color);
     red = (int)(red * lightingValue.Intensity);
     lightingValue.Color = _CreateRedColor(red);
     return lightingValue;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 protected override LightingValue FilterLightingValue(LightingValue lightingValue)
 {
     int yellow = _GetYellowValue(lightingValue.Color);
     yellow = (int)(yellow * lightingValue.Intensity);
     lightingValue.Color = _CreateYellowColor(yellow);
     return lightingValue;
 }
Esempio n. 6
0
 public LightingValue(LightingValue lv, double i)
 {
     _hue        = lv._hue;
     _saturation = lv._saturation;
     _value      = lv._value;
     _intensity  = i;
 }
Esempio n. 7
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);
					}
				}
			}
		}
Esempio n. 8
0
        protected override void _PreRender()
        {
            _intents = new EffectIntents();
            Channel[] channels = TargetNodes.SelectMany(x => x).ToArray();

            foreach(Channel channel in channels) {
                // Generating color intents...
                //ColorTransitionIntent intent = new ColorTransitionIntent(ColorGradient.Colors.First().Color.ToRGB(), ColorGradient.Colors.Last().Color.ToRGB(), TimeSpan);
                // Generating lighting intents...
                LightingValue startValue = new LightingValue(ColorGradient.Colors.First().Color.ToRGB(), 1);
                LightingValue endValue = new LightingValue(ColorGradient.Colors.Last().Color.ToRGB(), 1);
                LightingLinearIntent intent = new LightingLinearIntent(startValue, endValue, TimeSpan);
                _intents.AddIntentForChannel(channel.Id, intent, TimeSpan.Zero);
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
     //    }
     //}
 }
Esempio n. 11
0
 public LightingValue(LightingValue lv)
 {
     Color     = lv.Color;
     Intensity = lv.Intensity;
 }
Esempio n. 12
0
 public LightingValue(LightingValue lv, double i)
 {
     Color     = lv.Color;
     Intensity = i;
 }
Esempio n. 13
0
		public LightingValue Reduce(LightingValue value, double reductionPercent)
		{
			return new LightingValue(value.Color, Reduce(value.Intensity, reductionPercent));
		}
 protected abstract LightingValue FilterLightingValue(LightingValue lightingValue);
Esempio n. 15
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;
 }
Esempio n. 16
0
		private void addIntentsToElement(Element element, double[] allPointsTimeOrdered, Color? color = null)
		{
			if (element != null)
			{
				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;
				}
			}
		}
Esempio n. 17
0
        private void RenderElement(bool altColor, ref TimeSpan startTime, ref System.TimeSpan intervalTime,
            ref LightingValue? lightingValue, ElementNode element)
        {
            EffectIntents result;

            if ((StaticColor1 && altColor) || StaticColor2 && !altColor) {

                var level = new SetLevel.SetLevel();
                level.TargetNodes = new ElementNode[] { element };
                level.Color = altColor ? Color1 : Color2;
                level.TimeSpan = intervalTime;

                result = level.Render();

            } else {
                var pulse = new Pulse.Pulse();
                pulse.TargetNodes = new ElementNode[] { element };
                pulse.TimeSpan = intervalTime;
                pulse.ColorGradient = altColor ? ColorGradient1 : ColorGradient2;
                pulse.LevelCurve = altColor ? Curve1 : Curve2;
                result = pulse.Render();
            }

            result.OffsetAllCommandsByTime(startTime);
            _elementData.Add(result);
        }
Esempio n. 18
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;
			}
		}
Esempio n. 19
0
        // renders the given node to the internal ChannelData dictionary. If the given node is
        // not a channel, will recursively descend until we render its channels.
        private void RenderNode(ChannelNode node)
        {
            foreach(Channel channel in node) {
                // this is probably always going to be a single channel 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(channel == 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);

                    _channelData.AddIntentForChannel(channel.Id, intent, startTime);

                    lastPosition = position;
                }
            }
        }
Esempio n. 20
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);
			}
		}
Esempio n. 21
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));
                try {
                    _effectIntents.AddIntentForElement(element.Id, intent, TimeSpan.FromMilliseconds(startTime));
                }
                catch (Exception e) {
                    Console.WriteLine(e.ToString());
                    throw;
                }
                startTime += stateLength;
                currentLevel = nextLevel;
            }
        }
Esempio n. 22
0
 protected override LightingValue FilterLightingValue(LightingValue lightingValue)
 {
     return lightingValue;
 }