public LightingValue(LightingValue lv, double i) { _hue = lv._hue; _saturation = lv._saturation; _value = lv._value; _intensity = i; }
protected override LightingValue FilterLightingValue(LightingValue lightingValue) { int white = _GetWhiteValue(lightingValue.Color); white = (int)(white * lightingValue.Intensity); lightingValue.Color = _CreateWhiteColor(white); return lightingValue; }
protected override LightingValue FilterLightingValue(LightingValue lightingValue) { int red = _GetRedValue(lightingValue.Color); red = (int)(red * lightingValue.Intensity); lightingValue.Color = _CreateRedColor(red); return lightingValue; }
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; }
protected override LightingValue FilterLightingValue(LightingValue lightingValue) { int yellow = _GetYellowValue(lightingValue.Color); yellow = (int)(yellow * lightingValue.Intensity); lightingValue.Color = _CreateYellowColor(yellow); return lightingValue; }
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); } } } }
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); } }
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); }
// 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); // } //} }
public LightingValue(LightingValue lv) { Color = lv.Color; Intensity = lv.Intensity; }
public LightingValue(LightingValue lv, double i) { Color = lv.Color; Intensity = i; }
public LightingValue Reduce(LightingValue value, double reductionPercent) { return new LightingValue(value.Color, Reduce(value.Intensity, reductionPercent)); }
protected abstract LightingValue FilterLightingValue(LightingValue lightingValue);
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; }
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; } } }
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); }
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; } }
// 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; } } }
// 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); } }
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; } }
protected override LightingValue FilterLightingValue(LightingValue lightingValue) { return lightingValue; }