Exemplo n.º 1
0
        public void PushFrame(EffectFrame frame)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            lock (bitmap_lock)
            {
                EffectLayer background = new EffectLayer("Global Background", Color.FromArgb(0, 0, 0));

                EffectLayer[] over_layers_array = frame.GetOverlayLayers().ToArray();
                EffectLayer[] layers_array      = frame.GetLayers().ToArray();

                foreach (EffectLayer layer in layers_array)
                {
                    background += layer;
                }

                foreach (EffectLayer layer in over_layers_array)
                {
                    background += layer;
                }

                //Apply Brightness
                Dictionary <DeviceKeys, Color> peripehralColors = new Dictionary <DeviceKeys, Color>();

                foreach (Devices.DeviceKeys key in possible_peripheral_keys)
                {
                    if (!peripehralColors.ContainsKey(key))
                    {
                        peripehralColors.Add(key, background.Get(key));
                    }
                }

                foreach (Devices.DeviceKeys key in possible_peripheral_keys)
                {
                    background.Set(key, Utils.ColorUtils.BlendColors(peripehralColors[key], Color.Black, (1.0f - Global.Configuration.PeripheralBrightness)));
                }

                background.Fill(Color.FromArgb((int)(255.0f * (1.0f - Global.Configuration.KeyboardBrightness)), Color.Black));

                if (Global.Configuration.use_volume_as_brightness)
                {
                    background *= Global.Configuration.GlobalBrightness;
                }

                if (_forcedFrame != null)
                {
                    using (Graphics g = background.GetGraphics())
                    {
                        g.Clear(Color.Black);

                        g.DrawImage(_forcedFrame, 0, 0, canvas_width, canvas_height);
                    }
                }

                Dictionary <DeviceKeys, Color> keyColors = new Dictionary <DeviceKeys, Color>();
                Devices.DeviceKeys[]           allKeys   = bitmap_map.Keys.ToArray();

                foreach (Devices.DeviceKeys key in allKeys)
                {
                    keyColors[key] = background.Get(key);
                }

                Effects.keyColors = new Dictionary <DeviceKeys, Color>(keyColors);

                pushedframes++;

                DeviceColorComposition dcc = new DeviceColorComposition()
                {
                    keyColors = new Dictionary <DeviceKeys, Color>(keyColors),
                    keyBitmap = background.GetBitmap()
                };

                Global.dev_manager.UpdateDevices(dcc);

                var hander = NewLayerRender;
                if (hander != null)
                {
                    hander.Invoke(background.GetBitmap());
                }

                if (isrecording)
                {
                    EffectLayer pizelated_render = new EffectLayer();
                    foreach (Devices.DeviceKeys key in allKeys)
                    {
                        pizelated_render.Set(key, background.Get(key));
                    }

                    using (Bitmap map = pizelated_render.GetBitmap())
                    {
                        previousframe = new Bitmap(map);
                    }
                }


                frame.Dispose();
            }

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
        }
Exemplo n.º 2
0
        public void PushFrame(EffectFrame frame)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            lock (bitmap_lock)
            {
                EffectLayer background = new EffectLayer("Global Background", Color.FromArgb(0, 0, 0));

                EffectLayer[] over_layers_array = frame.GetOverlayLayers().ToArray();
                EffectLayer[] layers_array      = frame.GetLayers().ToArray();

                foreach (EffectLayer layer in layers_array)
                {
                    background += layer;
                }

                foreach (EffectLayer layer in over_layers_array)
                {
                    background += layer;
                }

                //Apply Brightness
                Color peri_col = background.Get(DeviceKeys.Peripheral);

                background.Set(DeviceKeys.Peripheral, Utils.ColorUtils.BlendColors(peri_col, Color.Black, (1.0f - Global.Configuration.peripheral_brightness_modifier)));
                background.Fill(Color.FromArgb((int)(255.0f * (1.0f - Global.Configuration.keyboard_brightness_modifier)), Color.Black));

                if (Global.Configuration.use_volume_as_brightness)
                {
                    background *= Global.Configuration.global_brightness;
                }

                Dictionary <DeviceKeys, Color> keyColors = new Dictionary <DeviceKeys, Color>();
                Devices.DeviceKeys[]           allKeys   = bitmap_map.Keys.ToArray();

                foreach (Devices.DeviceKeys key in allKeys)
                {
                    keyColors[key] = background.Get(key);
                }

                Effects.keyColors = new Dictionary <DeviceKeys, Color>(keyColors);

                pushedframes++;
                Global.dev_manager.UpdateDevices(keyColors);

                var hander = NewLayerRender;

                if (hander != null)
                {
                    hander.Invoke(background.GetBitmap());
                }

                if (isrecording)
                {
                    EffectLayer pizelated_render = new EffectLayer();
                    foreach (Devices.DeviceKeys key in allKeys)
                    {
                        pizelated_render.Set(key, background.Get(key));
                    }

                    using (Bitmap map = pizelated_render.GetBitmap())
                    {
                        previousframe = new Bitmap(map);
                    }
                }


                frame.Dispose();
            }

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
        }