public void saveSettings(string path)
        {
            File.WriteAllText(@path + @"\HueArtwork_Settings.xml", "");
            if (HueLights == null)
            {
                HueLights.Add("");
            }
            HueLights = HueLights.Distinct().ToList();
            XmlTextWriter xWriter = new XmlTextWriter(@path + @"\HueArtwork_Settings.xml", Encoding.UTF8);

            xWriter.Formatting = Formatting.Indented;
            xWriter.WriteStartElement("HueArtwork");
            xWriter.WriteStartElement("appConfig");
            xWriter.WriteElementString("APIKey", APIKey);
            xWriter.WriteStartElement("HueLights");
            foreach (string light in HueLights)
            {
                if (light != null)
                {
                    xWriter.WriteElementString("HueLights", light);
                }
            }
            xWriter.WriteEndElement();
            xWriter.WriteElementString("AverageColor", AverageColor.ToString());
            xWriter.WriteElementString("ColorPalette", ColorPalette.ToString());
            xWriter.WriteElementString("QualitySettings", QualitySetting);
            xWriter.WriteElementString("Brightness", Brightness);
            xWriter.WriteEndElement();
            xWriter.Close();
            MessageBox.Show("File saved @ " + @path + "HueArtwork_Settings.xml");
        }
Beispiel #2
0
        public AverageColor DoSumit(string path)
        {
            Bitmap bmp  = new Bitmap(1, 1);
            Bitmap orig = (Bitmap)Bitmap.FromFile(path);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                // updated: the Interpolation mode needs to be set to
                // HighQualityBilinear or HighQualityBicubic or this method
                // doesn't work at all.  With either setting, the results are
                // slightly different from the averaging method.
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.DrawImage(orig, new Rectangle(0, 0, 1, 1));
            }
            Color pixel = bmp.GetPixel(0, 0);
            // pixel will contain average values for entire orig Bitmap

            AverageColor rgb = new AverageColor()
            {
                R = pixel.R, G = pixel.G, B = pixel.B
            };

            byte avgR = pixel.R; // etc.

            Color myColor = Color.FromArgb(pixel.R, pixel.G, pixel.B);

            rgb.Hex = myColor.R.ToString("X2") + myColor.G.ToString("X2") + myColor.B.ToString("X2");

            return(rgb);
        }
Beispiel #3
0
        public Bitmap Render()
        {
            Bitmap result = (Bitmap)_bitmap.Clone();

            AverageColor[,] pixels = new AverageColor[_region.Height / _pixelSize.Height, _region.Width / _pixelSize.Width];

            for (int y = _region.Y; y < _region.Bottom; y++)
            {
                for (int x = _region.X; x < _region.Right; x++)
                {
                    int pixelX = (x - _region.X) / _pixelSize.Width;
                    int pixelY = (y - _region.Y) / _pixelSize.Height;

                    if (pixels[pixelY, pixelX] == null)
                    {
                        pixels[pixelY, pixelX] = new AverageColor();
                    }

                    pixels[pixelY, pixelX].Add(_bitmap.GetPixel(x, y));
                }
            }

            for (int y = _region.Y; y < _region.Bottom; y++)
            {
                for (int x = _region.X; x < _region.Right; x++)
                {
                    int pixelX = (x - _region.X) / _pixelSize.Width;
                    int pixelY = (y - _region.Y) / _pixelSize.Height;

                    result.SetPixel(x, y, pixels[pixelY, pixelX].Color);
                }
            }

            return(result);
        }
Beispiel #4
0
        public List <Files> GetFiles(string directory)
        {
            var dir = new DirectoryInfo(directory);

            FileInfo[] allFiles = dir.GetFiles();

            List <Files> allFilesList = new List <Files>();


            foreach (var item in allFiles)
            {
                if (item.FullName.Contains("jpeg") || item.FullName.Contains("png"))
                {
                    var file = new Files();
                    file.DateCreated = item.CreationTime;
                    file.Filename    = item.Name;


                    Image img = Image.FromFile(item.FullName);
                    file.Height = img.Height;
                    file.Width  = img.Width;
                    file.Size   = img.Height * img.Width;

                    //Image<Bgr, Byte> img1 = new Image<Bgr, Byte>(item.FullName);

                    //var pI = PixelateImage(img1);

                    //img.Dispose();

                    //pI.Save(item.FullName);

                    AverageColor rgb = DoSumit(item.FullName);

                    file.AverageColor = rgb;

                    allFilesList.Add(file);
                }
            }


            List <Files> SortedList = allFilesList.OrderBy(o => o.DateCreated).ToList();



            return(SortedList);
        }
Beispiel #5
0
        public void SaveSettings(string path)
        {
            if (path == "")
            {
                path = StoragePath;
            }
            File.WriteAllText(@path + @"\HueSettings.xml", "");
            if (HueLights == null)
            {
                HueLights.Add("");
            }
            HueLights = HueLights.Distinct().ToList();
            XmlTextWriter xWriter = new XmlTextWriter(@path + @"\HueSettings.xml", Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            };

            xWriter.WriteStartElement("HueSettings");
            xWriter.WriteStartElement("appConfig");
            xWriter.WriteElementString("APIKey", Username);
            xWriter.WriteStartElement("HueLights");
            foreach (string light in HueLights)
            {
                if (light != null)
                {
                    xWriter.WriteElementString("HueLights", light);
                }
            }
            xWriter.WriteEndElement();
            xWriter.WriteElementString("AverageColor", AverageColor.ToString());
            xWriter.WriteElementString("ColorPalette", ColorPalette.ToString());
            xWriter.WriteElementString("Brightness", Brightness.ToString());
            xWriter.WriteElementString("Enabled", IsEnabled.ToString());
            xWriter.WriteEndElement();
            xWriter.Close();
        }
Beispiel #6
0
        public void CreateConfigurationFile(string path)
        {
            XmlTextWriter xWriter = new XmlTextWriter(@path + @"\HueSettings.xml", Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            };

            AverageColor = true;
            ColorPalette = false;
            Brightness   = 10;
            IsEnabled    = true;
            xWriter.WriteStartElement("HueSettings");
            xWriter.WriteStartElement("appConfig");
            xWriter.WriteElementString("APIKey", "");
            xWriter.WriteStartElement("HueLights");
            xWriter.WriteElementString("HueLights", "");
            xWriter.WriteEndElement();
            xWriter.WriteElementString("AverageColor", AverageColor.ToString());
            xWriter.WriteElementString("ColorPalette", ColorPalette.ToString());
            xWriter.WriteElementString("Brightness", Brightness.ToString());
            xWriter.WriteElementString("Enabled", IsEnabled.ToString());
            xWriter.WriteEndElement();
            xWriter.Close();
        }
Beispiel #7
0
        private ColorRange[] Render()
        {
            this.edges.Sort();

            var writer            = new BitmapWriter(BackgroundColor, width, height);
            var superSampleBuffer = new SuperSampleBuffer(width);

            var layers            = new LayerManager[SuperSampling.SamplesPerPixelY];
            var superSampleRanges = new SuperSampleRangeList();

            // Keeps track of how many of the subpixellayers that are used for
            // the currently rendered scanline. Until a range requiring supersampling
            // is encountered only a single layer is needed.
            var usedLayers = 0;

            var color         = default(Color);
            var intersections = new IntersectionList();

            // Create a layer manager for every subpixel scanline
            for (var i = 0; i < layers.Length; i++)
            {
                layers[i] = new LayerManager();
            }

            for (var ey = 0; ey < height; ey++)
            {
                var ranges = this.edges[ey];
                if (ranges.Count == 0)
                {
                    writer.Skip(width);
                    continue;
                }

                for (var i = 0; i < usedLayers; i++)
                {
                    layers[i].Clear();
                }
                usedLayers = 1;

                superSampleRanges.Populate(ranges);

                writer.Skip(superSampleRanges[0].FromX);

                for (var rangeIndex = 0; rangeIndex < superSampleRanges.Count; rangeIndex++)
                {
                    ref var superSampleRange = ref superSampleRanges[rangeIndex];

                    // If there is exactly one edge in the supersample range, and it is crossing
                    // the entire scanline, we can perform the antialiasing by integrating the
                    // edge function.
                    if (superSampleRange.Count == 1 && (
                            superSampleRange[0].From.Y <= ey && superSampleRange[0].To.Y >= ey + 1 ||
                            superSampleRange[0].From.Y >= ey + 1 && superSampleRange[0].To.Y <= ey
                            ))
                    {
                        var edge = superSampleRange[0];

                        // Determine the lower and upper x value where the edge
                        // intersects the scanline.
                        var xey   = edge.Intersection(ey);
                        var xey1  = edge.Intersection(ey + 1);
                        var x0    = Math.Min(xey, xey1);
                        var x1    = Math.Max(xey, xey1);
                        var width = x1 - x0;

                        // Compute the average color of all subpixel layers before
                        // and after the edge intersection.
                        var fromColorAverage = new AverageColor();
                        var toColorAverage   = new AverageColor();

                        for (var sy = 0; sy < usedLayers; sy++)
                        {
                            var subScanlineLayers = layers[sy];
                            fromColorAverage.Add(subScanlineLayers.CurrentColor);
                            toColorAverage.Add(subScanlineLayers.Add(edge));
                        }

                        var fromColor = fromColorAverage.Color;
                        color = toColorAverage.Color;

                        // Render pixels
                        for (var x = superSampleRange.FromX; x < superSampleRange.ToXExcl; x++)
                        {
                            if (x0 >= x + 1)
                            {
                                // Pixel not covered
                                writer.Write(fromColor);
                                continue;
                            }

                            if (x1 <= x)
                            {
                                // Pixel fully covered
                                writer.Write(color);
                                continue;
                            }

                            // toColor coverage in the range [0.0, 1.0]
                            // Initialize to the fully covered range of the pixel.
                            var coverage = x1 < x + 1 ? x + 1 - x1 : 0;

                            // Compute integral for non-vertical edges
                            if (width > 0.001f)
                            {
                                // Range to integrate
                                var integralFrom = Math.Max(x0, x);
                                var integralTo   = Math.Min(x1, x + 1);

                                coverage +=
                                    (
                                        (integralTo * integralTo - integralFrom * integralFrom) / 2 +
                                        x0 * (integralFrom - integralTo)
                                    ) / width;
                            }

                            writer.Write(Color.Mix(fromColor, color, coverage));
                        }
                    } // /simplified antialiasing
                    else
                    {
                        // There are more than a single intersecting edge in this range.
                        // Use super sampling to render the pixels.
                        intersections.Initialize(ranges.Count);

                        var y = ey + SuperSampling.SampleHeight / 2;

                        // Ensure all subpixel layers are initialized
                        while (usedLayers < SuperSampling.SamplesPerPixelY)
                        {
                            layers[0].CopyTo(layers[usedLayers]);
                            usedLayers++;
                        }

                        // Average color of the pixels following the current supersample range.
                        var forwardColorAverage = new AverageColor();

                        for (var sy = 0; sy < SuperSampling.SamplesPerPixelY; sy++, y += SuperSampling.SampleHeight)
                        {
                            var subScanlineLayers = layers[sy];
                            color = subScanlineLayers.CurrentColor;

                            superSampleRange.GetIntersections(ref intersections, y);

                            for (var i = 0; i < intersections.Count; i++)
                            {
                                ref var intersection = ref intersections[i];
                                superSampleBuffer.Add(color, intersection.X - superSampleRange.FromX);
                                color = subScanlineLayers.Add(intersection.Edge);
                            }

                            // Write an extra pixel that will contain the color that
                            // will be forwarded until the next supersample range.
                            superSampleBuffer.Add(color, superSampleRange.Width);
                            superSampleBuffer.Rewind();

                            forwardColorAverage.Add(color);
                        } // /subpixel

                        // Get color to be forwarded
                        color = forwardColorAverage.Color;

                        // Blend subpixels
                        superSampleBuffer.WriteTo(ref writer, superSampleRange.Width);
                        superSampleBuffer.Clear();
                    } // /supersampling

                    // Forward last color
                    if (rangeIndex + 1 < superSampleRanges.Count)
                    {
                        var nextRangeX = superSampleRanges[rangeIndex + 1].FromX;
                        writer.Write(color, nextRangeX - superSampleRange.ToXExcl);
                    }
                    else
                    {
                        writer.Write(color, width - superSampleRange.ToXExcl);
                    }
                } // /range